meta4d-me / CatDogEngine

A cross-platform game engine/editor written in modern C++ (WIP)
GNU General Public License v2.0
158 stars 17 forks source link

[Lightmap] Bake Tool #457

Open T-rvw opened 8 months ago

T-rvw commented 8 months ago
T-rvw commented 8 months ago

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.

image

T-rvw commented 8 months ago

Indirect + Direct Lighting Diffuse: image

Direct Lighting Diffuse: image

Indirect Lighting Diffuse: image

T-rvw commented 8 months ago

@Hinageshi01 You can play with MJP's BakingLab. I got some basic knowledges about baking lightmap implementation.

T-rvw commented 8 months ago
roeas commented 7 months ago
  1. Generate UV for all meshes
  2. 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
    • 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)
  3. 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
    • Bicubic interpolation
      • Not quite sure how this works
    • lightmap mip map?
roeas commented 7 months ago

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

roeas commented 7 months ago

Solution from Precomputed Global Illumination in Frostbite Store L1 SH for every texel. image