Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GPU light baker

Discussion in 'Works In Progress - Archive' started by Snorkel, Mar 29, 2016.

  1. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    Hi,

    I'm currently experimenting with a custom lightbaker. With the idea that it could be used to bake lights in a procedural generated level or level made in an ingame editor.

    * left unity deferred rendering, legacy diffuse material
    * right lightmapped version using generated lightmap UVs from Unity
    ss+(2016-03-28+at+06.03.26).jpg

    Light baking is super cheap (milliseconds) and can easy been run every frame in the editor
    (directional light with custom shadow filtering)
    ss+(2016-03-30+at+12.17.15).jpg

    I'm also testing some ideas for ambient occlusion.
    (here showing a post effect I just added on the generated map - fixes UV edges)
    aoPost.png

    Next tests will be directional shadows with penumbra.
    AO still needs more work, including some noise reduction and more predictable results.
     

    Attached Files:

    mgear, Whiteleaf, colin299 and 4 others like this.
  2. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    Not much new, I changed all the code so that is uses command buffers instead of camera.render().
    With camera.render I had random glitches and had to double buffer shadow targets.
    It also works without pressing play now.

    ss+(2016-04-17+at+12.46.27).png

    Baking 300 shadow maps to simulate a skylight is still instant ! (using nvidia gtx 970).
    ss+(2016-04-17+at+12.39.55).png

    The next step will be using it in an actual project to see if this is useful and/or usable.
     
  3. Ronald_McScotland

    Ronald_McScotland

    Joined:
    Jul 30, 2014
    Posts:
    174
    This sounds like a great idea. I hope this pans out, as I'd like to add a level editor to my current game which uses lightmapping.
     
  4. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    Anyway you could get bounce lighting?
     
  5. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    I'm thinking of rendering a view for every triangle and baking the result.
    I could do both AO & bounce this way. The current AO system doesn't work for interiors as it doesn't support AO falloff.
    Not sure what quality and speed this wil have. I'll have to experiment a bit more.
     
  6. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    Not much changed, I did fix the strange AO artifacts by adding diffuse light for each sample:
    ss (2016-05-09 at 02.13.12).jpg
     
    colin299 likes this.
  7. MattFS

    MattFS

    Joined:
    Jul 14, 2009
    Posts:
    219
    heya Snorkel - sounds really cool what you're working on... where is this data stored, do you plan to integrate it into the current shading pipeline? In that this is more a replacement in how lightmap data is generated rather than redefining what lightmap data is?

    A few years back I tried something like this that used every vertex position and normal to render into a tiny rendertexture.. I found as small as 16x16 was enough to get good diffuse 'radiosity'... as you say, you get both AO and GI in one hit here and is - IMO - a very natural approach... the final lighting on a point is the radiance that reached that point.

    Look forward to seeing how you go with this!





     
  8. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    @urgrund
    I store it as regular lightmaps. The difference is backing speed & that it can be run at runtime/in a build.

    Haven't really thought about how to handle dynamic object. (they might just use realtime light & shadows similar to how mixed lighting used to work in unity 4).

    Your result looks promising. I really want to try radiosity. Hopefully I have some spare time soon :)
     
  9. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    232
    I had made a runtime lightmapper for a project at work, was able to do a 1024 map in ~5 seconds, would be very interested to see how you did this!
     
  10. Whiteleaf

    Whiteleaf

    Joined:
    Jul 1, 2014
    Posts:
    728
    Dang this looks significantly better than the Unity lightmapping right now.I'm really interested in this.
     
  11. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    176
    I tried something similar for a mobile project which generate the scene at runtime.
    The final result allow dynamic object to sample lightmap by a single tex2D().
    but this solution will only works on flat ground
     
    Whiteleaf and Snorkel like this.
  12. Snorkel

    Snorkel

    Joined:
    Dec 3, 2012
    Posts:
    37
    First attempt at GI,

    So just to clarify how much more expensive this is going to be.
    For each direct light I render the mesh it needs to bake too just once (in a single drawcall).
    For a directional light with shadows there is an additional time I need to render the mesh (to fill the shadow buffer)

    But for the GI I do the following:

    for each triangle
    {
    It renders a 16x16 view at the center of the triangle, facing the average normal direction.
    Then it plots this triangle into the lightmap while using the lowest mip of the 16x16 result.
    }

    I did cheat a bit for now by making a tessellated mesh
    ss (2016-07-21 at 05.13.05).png

    Render with a white sky at 120 fov
    ss (2016-07-21 at 05.12.38).jpg

    Render with a direct shadow casting light + GI (black sky)
    ss (2016-07-21 at 05.14.43).png

    Render with direct shadow casting light + GI (blue sky)
    ss (2016-07-21 at 05.18.47).png