CatDogEngine icon indicating copy to clipboard operation
CatDogEngine copied to clipboard

[Lightmap] Bake Tool

Open T-rvw opened this issue 1 year ago • 7 comments
trafficstars

T-rvw avatar Jan 31 '24 04:01 T-rvw

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 avatar Jan 31 '24 08:01 T-rvw

Indirect + Direct Lighting Diffuse: image

Direct Lighting Diffuse: image

Indirect Lighting Diffuse: image

T-rvw avatar Jan 31 '24 09:01 T-rvw

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

T-rvw avatar Jan 31 '24 09:01 T-rvw

  • 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.
        • 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.

T-rvw avatar Feb 01 '24 09:02 T-rvw

  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 avatar Feb 20 '24 08:02 roeas

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 avatar Feb 23 '24 09:02 roeas

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

roeas avatar Mar 09 '24 10:03 roeas