|
Untitled
|
#include "core/camera.h"#include "core/engine_types.h"#include "core/mesh.h"#include "render/render.h"#include "stb/stb_image.h"#include "stb/stb_image_write.h"#include "load/load.h"#include "utilities/mathf.h"#include "utilities/engine_utilities.h"#include "utilities/types.h"#include "core/acceleration.h"#include "load/init.h"#include "audio/audio.h"#include "utilities/utilities.h"#include <limits.h>#include <math.h>#include <stdlib.h>#include <omp.h>#include <assert.h>#include <winscard.h>#include <unistd.h>Go to the source code of this file.
Data Structures | |
| struct | UVAssignmentPair |
| struct | LMDebug |
| struct | LightGPUData |
| struct | DistancePair |
Macros | |
| #define | SLEEP(x) |
| #define | MAX_DIRECTIONAL_LIGHTS_LM 4 |
| #define | MAX_POINT_LIGHTS_LM 2048 |
| #define | MAX_EMISSIVE_TRIS_LM 100000 |
| #define | LMDEBUG_SIZE 4096 |
Functions | |
| void | walk_coplanar_adjacency (Mesh *mesh, UVIsland *island, UVMapping *uv_map, int island_idx, int current_face_index, bool *tri_list, TriangleAdjacency *tri_adj, vec3 normal, vec3 ref_point, float eps) |
| LightmapAtlas | init_lightmap_atlas (int width, int height, int block_size) |
| void | free_lightmap_atlas (LightmapAtlas *atlas) |
| void | init_lightmap_data (LightmapData *ld) |
| Frees current LightmapAtlas and UVIsland data and re-initializes the LightmapAtlas array and initializes the UVIsland Vector. | |
| void | find_least_parallel_axis (vec3 normal, vec3 *u_dir, vec3 *v_dir) |
| LightmapRect | allocate_lightmap_rect (LightmapAtlas *atlas, int w_px, int h_px) |
| void | deallocate_lightmap_rect (LightmapData *ld, LightmapRect *rect) |
| void | assign_uvs (UVIsland *uvi, LightmapAtlas *atlas) |
| void | add_uv_island_to_lightmap (LightmapData *ld, UVIsland *uvi) |
| void | init_uv_islands (LightmapData *ld) |
| Adds all current UVIslands to the lightmap by allocating LightmapRects. | |
| void | build_uv_islands (MeshNode *mn) |
| Builds UVIslands over a MeshNode by stepping through TriangleAdjacency and stopping when normals become too different. | |
| void | LM_regenerate_texels () |
| Regenerates lightmap texels: re-inits LightmapData, then builds UVIslands, then calls add_all_meshes_to_draw_buffer. | |
| void | LM_allocate_empty_mns () |
| Allocates texels for MeshNodes that don't have UVIslands generated yet. | |
| void | save_lightmap_to_binary (LightmapData *ld, const char *name) |
| Saves a UV lightmap and relevant UVIsland and MeshNode data to binary. | |
| void | load_lightmap_from_binary (LightmapData *ld, const char *name) |
| Loads a UV lightmap and relevant UVIsland and MeshNode data fro, binary. | |
| void | bake_reflection_probes () |
| Bakes ReflectionProbes for the entire scene onto cubemaps on RPROBE_CUBE_MAP_ARRAY. | |
| void | upload_bake_lights_gpu (GLuint *lights_ssbo) |
| void | bake_lightmap (LightmapData *ld) |
| Bakes a UV Lightmap based on which UVIslands have UVIsland.currently_rasterizing set. | |
| void | remove_lighting_pv (LPV *lpv, bool *lpb) |
| void | reset_lighting_pvs () |
| Resets current LPVs from their slots in SceneData.LOADED_LIGHTING_PV. | |
| void | load_lighting_pv (LPV *lpv, ProbeVolume *pv, int replacing_id) |
| int | compare_distances (const void *a, const void *b) |
| int | compare_current_distances (const void *a, const void *b) |
| void | check_lighting_pv () |
| Determines which LPVs we may need to replace due to distance to new ones. | |
| void | bake_lighting_probe_volume (ProbeVolume *pv) |
| Loads a UV lightmap and relevant UVIsland and MeshNode data fro, binary. | |
| struct UVAssignmentPair |
Definition at line 219 of file lightmap.c.
| Data Fields | ||
|---|---|---|
| float | pu | |
| float | pv | |
| size_t | idx | |
| vec3 | p | |
| struct LMDebug |
Definition at line 915 of file lightmap.c.
| Data Fields | ||
|---|---|---|
| vec3 | pos | |
| uint32_t | pad0 | |
| vec3 | dir | |
| uint32_t | pad1 | |
| vec3 | origin | |
| uint32_t | pad2 | |
| struct LightGPUData |
Definition at line 925 of file lightmap.c.
| Data Fields | ||
|---|---|---|
| int | dir_count | |
| int | point_count | |
| int | tri_count | |
| uint32_t | sample_count | |
| float | dir_w | |
| float | point_w | |
| float | tri_w | |
| float | total_power | |
| LightGPU | directional_lights[4] | |
| LightGPU | point_lights[2048] | |
| LMDebug | LMDEBUG[4096] | |
| struct DistancePair |
Definition at line 1364 of file lightmap.c.
| Data Fields | ||
|---|---|---|
| float | d | |
| int | id | |
| #define SLEEP | ( | x | ) |
Definition at line 34 of file lightmap.c.
| #define MAX_DIRECTIONAL_LIGHTS_LM 4 |
Definition at line 911 of file lightmap.c.
| #define MAX_POINT_LIGHTS_LM 2048 |
Definition at line 912 of file lightmap.c.
| #define MAX_EMISSIVE_TRIS_LM 100000 |
Definition at line 913 of file lightmap.c.
| #define LMDEBUG_SIZE 4096 |
Definition at line 924 of file lightmap.c.
| void walk_coplanar_adjacency | ( | Mesh * | mesh, |
| UVIsland * | island, | ||
| UVMapping * | uv_map, | ||
| int | island_idx, | ||
| int | current_face_index, | ||
| bool * | tri_list, | ||
| TriangleAdjacency * | tri_adj, | ||
| vec3 | normal, | ||
| vec3 | ref_point, | ||
| float | eps ) |
Definition at line 37 of file lightmap.c.
References A, TriangleAdjacency::adjacent_indices, B, C, CAST_VEC, Vector::count, MeshFace::indices, MeshFace::normal, Point::pos, triangle_area(), Mesh::tris, UVIsland::tris, UVMapping::uv_island, vec3_dot(), vector_expand(), Mesh::vertices, and walk_coplanar_adjacency().
Referenced by build_uv_islands(), and walk_coplanar_adjacency().
| LightmapAtlas init_lightmap_atlas | ( | int | width, |
| int | height, | ||
| int | block_size ) |
Definition at line 77 of file lightmap.c.
References LightmapAtlas::block_size, LightmapAtlas::height, init_lightmap_atlas(), LightmapAtlas::occupied, and LightmapAtlas::width.
Referenced by init_lightmap_atlas(), and init_lightmap_data().
| void free_lightmap_atlas | ( | LightmapAtlas * | atlas | ) |
Definition at line 87 of file lightmap.c.
References LightmapAtlas::block_size, free_lightmap_atlas(), LightmapAtlas::height, LightmapAtlas::occupied, and LightmapAtlas::width.
Referenced by free_lightmap_atlas(), and init_lightmap_data().
| void init_lightmap_data | ( | LightmapData * | ld | ) |
Frees current LightmapAtlas and UVIsland data and re-initializes the LightmapAtlas array and initializes the UVIsland Vector.
| The | LightmapData for the lightmap. |
Definition at line 93 of file lightmap.c.
References LightmapData::atlas, Vector::buffer, CAST_VEC, Vector::count, free_lightmap_atlas(), init_lightmap_atlas(), init_lightmap_data(), init_vector(), LightmapData::islands, LIGHTMAP_HEIGHT, LIGHTMAP_WIDTH, and LightmapData::sample_cubemap.
Referenced by execute_globals_undo(), init_lightmap_data(), LM_regenerate_texels(), and render_main_menu().
Definition at line 124 of file lightmap.c.
References find_least_parallel_axis(), n, vec3_cross(), vec3_dot(), and vec3_normalize().
Referenced by assign_uvs(), and find_least_parallel_axis().
| LightmapRect allocate_lightmap_rect | ( | LightmapAtlas * | atlas, |
| int | w_px, | ||
| int | h_px ) |
Definition at line 147 of file lightmap.c.
References allocate_lightmap_rect(), LightmapAtlas::block_size, LightmapAtlas::height, LightmapAtlas::occupied, and LightmapAtlas::width.
Referenced by allocate_lightmap_rect(), and assign_uvs().
| void deallocate_lightmap_rect | ( | LightmapData * | ld, |
| LightmapRect * | rect ) |
Definition at line 195 of file lightmap.c.
References LightmapData::atlas, LightmapAtlas::block_size, deallocate_lightmap_rect(), LightmapRect::h, LightmapAtlas::height, LightmapAtlas::occupied, LightmapRect::padding, LightmapRect::u, LightmapRect::v, LightmapRect::w, and LightmapAtlas::width.
Referenced by deallocate_lightmap_rect(), and load_lightmap_from_binary().
| void assign_uvs | ( | UVIsland * | uvi, |
| LightmapAtlas * | atlas ) |
Definition at line 230 of file lightmap.c.
References allocate_lightmap_rect(), assign_uvs(), CAST_VEC, UVIsland::centroid, Vector::count, EDITOR_SETTINGS, find_least_parallel_axis(), GLOBALS, LightmapRect::h, LightmapAtlas::height, MeshFace::indices, MAX, MeshNode::mesh, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, EditorSettings::mfactor, EditorSettings::mfactor_enabled, UVIsland::normal, LightmapRect::padding, Point::pos, UVAssignmentPair::pu, UVAssignmentPair::pv, UVIsland::rect, LightmapRect::success, EditorSettings::texels_per_uv_unit, triangle_area(), Mesh::tris, UVIsland::tris, LightmapRect::u, UVMapping::uv_idx, MeshNode::uv_map, UVIsland::uvs, LightmapRect::v, vec3_dot(), vec3_sub(), Mesh::vertices, LightmapRect::w, and LightmapAtlas::width.
Referenced by add_uv_island_to_lightmap(), and assign_uvs().
| void add_uv_island_to_lightmap | ( | LightmapData * | ld, |
| UVIsland * | uvi ) |
Definition at line 353 of file lightmap.c.
References add_uv_island_to_lightmap(), assign_uvs(), LightmapData::atlas, CAST_VEC, Vector::count, UVIsland::currently_rasterizing, GLOBALS, MeshNode::mesh, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, Mesh::tris, UVIsland::tris, UVIsland::uvs, and Mesh::vertices.
Referenced by add_uv_island_to_lightmap(), build_uv_islands(), and init_uv_islands().
| void init_uv_islands | ( | LightmapData * | ld | ) |
Adds all current UVIslands to the lightmap by allocating LightmapRects.
| The | LightmapData for the lightmap. |
Definition at line 384 of file lightmap.c.
References add_uv_island_to_lightmap(), CAST_VEC, Vector::count, init_uv_islands(), and LightmapData::islands.
Referenced by init_uv_islands().
| void build_uv_islands | ( | MeshNode * | mn | ) |
Builds UVIslands over a MeshNode by stepping through TriangleAdjacency and stopping when normals become too different.
| The | MeshNode to traverse. |
Definition at line 400 of file lightmap.c.
References A, add_uv_island_to_lightmap(), TriangleAdjacency::adjacent_indices, B, build_uv_islands(), C, CAST_VEC, UVIsland::centroid, Vector::count, GLOBALS, MeshNode::id, MeshFace::indices, init_vector(), LightmapData::islands, SceneData::lightmap_data, MeshNode::mesh, UVIsland::mesh_node, Globals::meshes, MeshFace::normal, UVIsland::normal, Point::pos, Globals::scene_data, Mesh::tri_adjacency, triangle_area(), triangle_centroid(), Mesh::tris, UVIsland::tris, UVMapping::uv_island, MeshNode::uv_map, UVIsland::uvs, vec3_add(), vec3_normalize(), vec3_scale(), vector_expand(), Mesh::vertices, and walk_coplanar_adjacency().
Referenced by build_uv_islands(), execute_globals_undo(), LM_allocate_empty_mns(), LM_regenerate_texels(), and render_main_menu().
| void LM_regenerate_texels | ( | ) |
Regenerates lightmap texels: re-inits LightmapData, then builds UVIslands, then calls add_all_meshes_to_draw_buffer.
Definition at line 486 of file lightmap.c.
References add_all_meshes_to_buffer(), build_uv_islands(), CAST_VEC, Vector::count, GLOBALS, init_lightmap_data(), SceneData::lightmap_data, LM_regenerate_texels(), Globals::mesh_nodes, Globals::meshes, Globals::scene_data, and Globals::vertex_layouts.
Referenced by LM_regenerate_texels(), and render_light_menu().
| void LM_allocate_empty_mns | ( | ) |
Allocates texels for MeshNodes that don't have UVIslands generated yet.
Used when loading a binary that does not include certain MeshNodes.
Definition at line 502 of file lightmap.c.
References add_all_meshes_to_buffer(), build_uv_islands(), CAST_VEC, Vector::count, GLOBALS, LM_allocate_empty_mns(), Globals::mesh_nodes, Globals::meshes, and Globals::vertex_layouts.
Referenced by LM_allocate_empty_mns(), and render_light_menu().
| void save_lightmap_to_binary | ( | LightmapData * | ld, |
| const char * | name ) |
Saves a UV lightmap and relevant UVIsland and MeshNode data to binary.
| The | LightmapData for the lightmap. |
| The | path to and name of the file. |
Definition at line 525 of file lightmap.c.
References Globals::assets, LightmapData::atlas, LightmapAtlas::block_size, Vector::buffer, CAST_VEC, Vector::count, DIRECTIONAL_MAP_TEXTURE, EDITOR_SETTINGS, GLOBALS, LightmapAtlas::height, LightmapData::islands, MeshNode::mesh, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, MeshNode::name, UVIsland::normal, LightmapAtlas::occupied, UVIsland::rect, LightmapData::sample_cubemap, save_lightmap_to_binary(), EditorSettings::texels_per_uv_unit, LightmapData::texture_id, Mesh::tris, UVIsland::tris, MeshNode::uv_map, UVIsland::uvs, and LightmapAtlas::width.
Referenced by render_light_menu(), save_lightmap_to_binary(), and scene_save().
| void load_lightmap_from_binary | ( | LightmapData * | ld, |
| const char * | name ) |
Loads a UV lightmap and relevant UVIsland and MeshNode data fro, binary.
| The | LightmapData for the lightmap. |
| The | path to and name of the file. |
Definition at line 610 of file lightmap.c.
References add_all_meshes_to_buffer(), LightmapData::atlas, LightmapAtlas::block_size, Vector::buffer, Vector::capacity, CAST_VEC, Vector::count, deallocate_lightmap_rect(), DIRECTIONAL_MAP_TEXTURE, EDITOR_SETTINGS, find_mn_by_name(), GLOBALS, LightmapAtlas::height, init_vector(), LightmapData::islands, load_lightmap_from_binary(), MeshNode::mesh, UVIsland::mesh_node, Globals::mesh_nodes, Globals::meshes, UVIsland::normal, LightmapAtlas::occupied, UVIsland::rect, LightmapData::sample_cubemap, EditorSettings::texels_per_uv_unit, LightmapData::texture_id, Mesh::tris, UVIsland::tris, MeshNode::uv_map, UVIsland::uvs, Globals::vertex_layouts, and LightmapAtlas::width.
Referenced by load_lightmap_from_binary(), render_light_menu(), and scene_load().
| void bake_reflection_probes | ( | ) |
Bakes ReflectionProbes for the entire scene onto cubemaps on RPROBE_CUBE_MAP_ARRAY.
Definition at line 786 of file lightmap.c.
References ReflectionProbe::aabb, bake_reflection_probes(), BUFFER_FRAMES, Camera::cam_data, CamData::cam_pos, ReflectionProbe::capture_pos, CAST_VEC, AABB::center, RProbe::center, compute_camera_basis(), Vector::count, current_frame, EDITOR_SETTINGS, Camera::forward, GLOBALS, CamData::inv_proj, CamData::inv_view, m4_inverse(), M_PI, make_look_at(), make_projection(), RProbe::max, AABB::max_x, AABB::max_y, AABB::max_z, RProbe::min, AABB::min_x, AABB::min_y, AABB::min_z, EditorSettings::MSAA, Camera::pitch, CamData::proj, SceneData::reflection_probes, render_to_cubemap_face(), RPROBE_CUBE_MAP_ARRAY, RPROBE_FBO, RPROBE_HEIGHT, RPROBE_SSBO, RPROBE_WIDTH, Globals::scene_data, CamData::unjittered_inv_proj, CamData::unjittered_proj, vec3_add(), vec3_to_vec4(), CamData::view, view, and Camera::yaw.
Referenced by bake_reflection_probes(), and render_light_menu().
| void upload_bake_lights_gpu | ( | GLuint * | lights_ssbo | ) |
Definition at line 943 of file lightmap.c.
References BVHNode::aabb, LightGPU::bvh_index, CAST_VEC, AABB::center, copy_light_to_gpu_light(), BVHNode::count, Vector::count, current_frame, BVHNode::emissive_flux, AABB::extents, BVHNode::first_index, BVHNode::flux, GLOBALS, LightBVH::indices, LightBVH::indices_count, BVHNode::left, SceneData::light_bvh, LIGHT_SSBO, light_ssbo_ptr, light_ssbo_size, LightBVH::lights, AABB::max_x, AABB::max_y, AABB::max_z, Globals::mesh_nodes, Globals::meshes, AABB::min_x, AABB::min_y, AABB::min_z, n, BVHNode::next, LightBVH::nodes, BVHNode::parent, BVHNode::right, Globals::scene_data, and upload_bake_lights_gpu().
Referenced by bake_lighting_probe_volume(), bake_lightmap(), and upload_bake_lights_gpu().
| void bake_lightmap | ( | LightmapData * | ld | ) |
Bakes a UV Lightmap based on which UVIslands have UVIsland.currently_rasterizing set.
| The | LightmapData for the lightmap. |
Definition at line 1009 of file lightmap.c.
References EditorSettings::ao_iterations, EditorSettings::ao_threshold, LightmapData::atlas, bake_lightmap(), bind_baking_ssbos(), Vector::buffer, Mesh::bvh_indices, SceneData::bvh_indices, SceneData::bvh_indices_count, CAST_VEC, Vector::count, UVIsland::currently_rasterizing, DIRECTIONAL_MAP_NORMALIZE_SHADER, DIRECTIONAL_MAP_TEXTURE, EDITOR_SETTINGS, end_timer(), MeshNode::free, GLOBALS, LightmapAtlas::height, MeshFace::indices, LightmapData::islands, SceneData::light_bvh, LIGHTMAP_BOUNCE_SHADER, LIGHTMAP_DENOISE_SHADER, LIGHTMAP_DILATE_SHADER, LIGHTMAP_FBO, LIGHTMAP_HEIGHT, LIGHTMAP_ID_TEXTURE, LIGHTMAP_NORM_TEXTURE, LIGHTMAP_POS_TEXTURE, LIGHTMAP_SHADER, LIGHTMAP_VAO, LIGHTMAP_VBO, LIGHTMAP_WIDTH, Globals::lights, EditorSettings::lm_iterations, LightmapVertex::lm_uv, LightmapVertex::material_id, MeshFace::material_id, MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, MIN, LightBVH::nodes, LightmapVertex::normal, Point::normal, LightmapVertex::pos, Point::pos, ShaderProgram::program, Globals::scene_data, SKYBOX, start_timer(), temp, LightmapData::texture_id, LightmapVertex::tri_id, Mesh::tris, unbind_baking_ssbos(), upload_bake_lights_gpu(), LightmapVertex::uv, Point::uv, UVMapping::uv_idx, UVMapping::uv_island, MeshNode::uv_map, UVIsland::uvs, Mesh::vertices, and LightmapAtlas::width.
Referenced by bake_lightmap(), and render_light_menu().
| void remove_lighting_pv | ( | LPV * | lpv, |
| bool * | lpb ) |
Definition at line 1319 of file lightmap.c.
References LPV::lprobes, LPV::pv_id, and remove_lighting_pv().
Referenced by check_lighting_pv(), and remove_lighting_pv().
| void reset_lighting_pvs | ( | ) |
Resets current LPVs from their slots in SceneData.LOADED_LIGHTING_PV.
Definition at line 1330 of file lightmap.c.
References GLOBALS, SceneData::LOADED_LIGHTING_PV, SceneData::LOADED_LIGHTING_PV_FLAG, LPV::lprobes, LPV_SLOTS, reset_lighting_pvs(), and Globals::scene_data.
Referenced by execute_lprobe_undo(), load_lprobes(), render_lprobe_menu(), and reset_lighting_pvs().
| void load_lighting_pv | ( | LPV * | lpv, |
| ProbeVolume * | pv, | ||
| int | replacing_id ) |
Definition at line 1344 of file lightmap.c.
References ProbeVolume::byte_offset, GLOBALS, load_lighting_pv(), LPV::lprobes, SceneData::LPV_FILE, LPV_PADDED_COUNT, LPV_TEXTURE, PROBE_VOLUME_DEPTH_PADDED, PROBE_VOLUME_HEIGHT, PROBE_VOLUME_WIDTH, Globals::scene_data, and SH_MAX.
Referenced by check_lighting_pv(), and load_lighting_pv().
| int compare_distances | ( | const void * | a, |
| const void * | b ) |
Definition at line 1370 of file lightmap.c.
References compare_distances(), and DistancePair::d.
Referenced by check_lighting_pv(), and compare_distances().
| int compare_current_distances | ( | const void * | a, |
| const void * | b ) |
Definition at line 1379 of file lightmap.c.
References compare_current_distances(), and DistancePair::d.
Referenced by check_lighting_pv(), and compare_current_distances().
| void check_lighting_pv | ( | ) |
Determines which LPVs we may need to replace due to distance to new ones.
Definition at line 1391 of file lightmap.c.
References CAST_VEC, OBB::center, check_lighting_pv(), compare_current_distances(), compare_distances(), Vector::count, DistancePair::d, GLOBALS, hit, DistancePair::id, SceneData::lighting_probe_volumes, load_lighting_pv(), SceneData::LOADED_LIGHTING_PV, SceneData::LOADED_LIGHTING_PV_FLAG, SceneData::LPV_FILE, LPV_SLOTS, Skeleton::neck, ProbeVolume::obb, player, Spring::pos, LPV::pv_id, ray_intersects_obb_with_point(), remove_lighting_pv(), Globals::scene_data, Player::skeleton, vec3_dist(), vec3_normalize(), and vec3_sub().
Referenced by check_lighting_pv(), and main().
| void bake_lighting_probe_volume | ( | ProbeVolume * | pv | ) |
Loads a UV lightmap and relevant UVIsland and MeshNode data fro, binary.
| The | LightmapData for the lightmap. |
| The | path to and name of the file. |
Definition at line 1509 of file lightmap.c.
References bake_lighting_probe_volume(), bind_baking_ssbos(), Vector::buffer, ProbeVolume::byte_offset, CAST_VEC, Vector::count, EDITOR_SETTINGS, GLOBALS, SceneData::light_bvh, Globals::lights, SceneData::LPV_FILE, LPV_PADDED_COUNT, Globals::mesh_nodes, Globals::meshes, LightBVH::nodes, ProbeVolume::obb, OBB_min_corner(), SHDataGPU::pos, PROBE_BAKE_SHADER, EditorSettings::probe_iterations, Globals::probe_spacing, PROBE_SSBO, PROBE_UNPACK_SHADER, PROBE_VOLUME_DEPTH, PROBE_VOLUME_DEPTH_PADDED, PROBE_VOLUME_HEIGHT, PROBE_VOLUME_WIDTH, PV_step_size(), Globals::scene_data, SH_MAX, ProbeVolume::size, SKYBOX, unbind_baking_ssbos(), upload_bake_lights_gpu(), vec3::x, vec3::y, and vec3::z.
Referenced by bake_lighting_probe_volume(), and render_lprobe_menu().