Untitled
Loading...
Searching...
No Matches
lightmap.c File Reference
#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.

Data Structure Documentation

◆ UVAssignmentPair

struct UVAssignmentPair

Definition at line 219 of file lightmap.c.

Data Fields
float pu
float pv
size_t idx
vec3 p

◆ LMDebug

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

◆ LightGPUData

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]

◆ DistancePair

struct DistancePair

Definition at line 1364 of file lightmap.c.

Data Fields
float d
int id

Macro Definition Documentation

◆ SLEEP

#define SLEEP ( x)
Value:
sleep(x / 1000)

Definition at line 34 of file lightmap.c.

◆ MAX_DIRECTIONAL_LIGHTS_LM

#define MAX_DIRECTIONAL_LIGHTS_LM   4

Definition at line 911 of file lightmap.c.

◆ MAX_POINT_LIGHTS_LM

#define MAX_POINT_LIGHTS_LM   2048

Definition at line 912 of file lightmap.c.

◆ MAX_EMISSIVE_TRIS_LM

#define MAX_EMISSIVE_TRIS_LM   100000

Definition at line 913 of file lightmap.c.

◆ LMDEBUG_SIZE

#define LMDEBUG_SIZE   4096

Definition at line 924 of file lightmap.c.

Function Documentation

◆ walk_coplanar_adjacency()

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 )

◆ init_lightmap_atlas()

LightmapAtlas init_lightmap_atlas ( int width,
int height,
int block_size )

◆ free_lightmap_atlas()

◆ init_lightmap_data()

◆ find_least_parallel_axis()

void find_least_parallel_axis ( vec3 normal,
vec3 * u_dir,
vec3 * v_dir )

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().

◆ allocate_lightmap_rect()

LightmapRect allocate_lightmap_rect ( LightmapAtlas * atlas,
int w_px,
int h_px )

◆ deallocate_lightmap_rect()

◆ assign_uvs()

◆ add_uv_island_to_lightmap()

◆ init_uv_islands()

void init_uv_islands ( LightmapData * ld)

Adds all current UVIslands to the lightmap by allocating LightmapRects.

Parameters
TheLightmapData 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().

◆ build_uv_islands()

◆ LM_regenerate_texels()

void LM_regenerate_texels ( )

◆ LM_allocate_empty_mns()

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().

◆ save_lightmap_to_binary()

◆ load_lightmap_from_binary()

◆ bake_reflection_probes()

◆ upload_bake_lights_gpu()

◆ bake_lightmap()

void bake_lightmap ( LightmapData * ld)

Bakes a UV Lightmap based on which UVIslands have UVIsland.currently_rasterizing set.

Parameters
TheLightmapData 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().

◆ remove_lighting_pv()

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().

◆ reset_lighting_pvs()

◆ load_lighting_pv()

◆ compare_distances()

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().

◆ compare_current_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().

◆ check_lighting_pv()

◆ bake_lighting_probe_volume()