CatDogEngine
CatDogEngine copied to clipboard
[Lightmap] Bake Tool
- Overview
- The first step is to bake Direct/Indirect Lighting Diffuse. Direct Lighting Diffuse should be same with engine realtime rendering by using same render pipeline. Indirect Lighting Diffuse is the key part to improve lighting visual result.
- Consider material's AlbedoMap + NormalMap.
- CPU baker at first. Then consider GPU baker.
- See Dghelneshi's answer in high_level_overview_of_a_lightmapping_generation which has more professional details.
- Lightmap
- Simple Lambertian diffuse BRDF without view dependencies
- Consider NormalMap to avoid flat ambient issue
- Learn about different BakingMode
- Reference
Lightmap meets with NormalMap to get better surface details in indirect light. Use half life 2's 3 basis's solution to blend irradiance values at runtime.
Indirect + Direct Lighting Diffuse:
Direct Lighting Diffuse:
Indirect Lighting Diffuse:
@Hinageshi01 You can play with MJP's BakingLab. I got some basic knowledges about baking lightmap implementation.
- Generate LightmapUV for multiple scene objects to share one lightmap texture
- XAtlas Implementation
- For model's every mesh, do below task in parallel
- Then it will build mesh faces to different groups in
MeshFaceGroups::compute()- Loop every face
- Loop face's all adjacent faces if valid. Create a queue container. Init it with current face.
- Loop every non-unboundary edge belong to the container's first face(pop up)
- Query current edge's opposite face. If opposite face's material is not same with face, don't put in same group.
- Skip if opposite face already put in a group.
- Record face loop order.
- Add valid opposite faces to previous created queue container.
- Loop every face
- After split faces into different groups considered connections + same materials, we define group number as UV Charts group count
- Record invalid faces' information such as indexes.
- Sort all UV Charts group by every Charts group's face number. RadixSort is used here which is widely-used parallel sort algorithm.
- For every Charts group, do below task in parallel.
ChartGroup::computeCharts- For every Chart, parameterize it in
PiecewiseParam::computeChart.
- For every Chart, parameterize it in
- Then it will build mesh faces to different groups in
- For model's every mesh, do below task in parallel
- XAtlas Implementation
- Generate UV for all meshes
- Baking
- Generate light map
- UV space rasterization
OUT.Position = float4(IN.LightmapUV * 2 - 1, 0, 1);
- Padding
- for every empty background pixel, it simply looks at 8 neighbours around it and copies the first non-empty value value it finds.
- Conservative rasterization, post-padding is not enough for small triangle
- Repurposing MSAA samples
- Rendering geometry multiple times with sub-pixel offset √
- Rendering lines over triangles
- Optimize shadow leaks
- push sample points out of shadowed areas where leaks can occur
- Optimize shadow terminator
- Adding constant bias to ray start
- Making shadow rays ignore adjacent faces that are almost coplanar
- Tessellating/smoothing geometry before ray-tracing
- Blurring the result
- Tamy Boubekeur and Marc Alexa. 2008. Phong Tessellation. √
- Determines if the smooth position intersects another surface
- If any fragment on a triangle intersects another surface, all fragments on the entire triangle should use the flat position
- Beware of weird triangles with 2 normals pointing out, and one in
- Fixing UV seams
- Not quite sure how this works
- UV space rasterization
- Trace rays
- OptiX, RadeonRays, DXR
- UV GBuffer
- rasterize surface attributes like above
- Ray bias, to prevent noisy self-overlapping due to floating-point inaccuracy
position += sign(normal) * abs(position * 0.0000002)
- Generate light map
- Some little optimization
- Denoising
- Optix AI denoiser
- Must before UV seam fixing
- Maybe something like reversible tonemapping is needed to ensure that the input to the denoiser is non-HDR
- Optix AI denoiser
- Bicubic interpolation
- Not quite sure how this works
- lightmap mip map?
- Denoising
In game renderer and Radiosity: http://the-witness.net/news/2010/09/hemicube-rendering-and-integration/ https://web.archive.org/web/20160311085440/http://freespace.virgin.net/hugo.elias/radiosity/radiosity.htm
Solution from Precomputed Global Illumination in Frostbite
Store L1 SH for every texel.