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

Bake one shadow map texture per light source in unity

Discussion in 'Global Illumination' started by rf4dev5, Nov 27, 2019.

  1. rf4dev5

    rf4dev5

    Joined:
    Aug 20, 2019
    Posts:
    1
    Hello. Is there any way to save ONLY shadow maps (not light maps and other GI stuff) in Unity? All baked lighting options that I saw is not suited for me, because they work in "per object" mode, but not "per light".

    What I want to achive. I have a scene with a lot of objects (really big number). And there are 10-20 STATIC light sources in this scene. All I want is to bake 10-20 shadow maps for this light sources. Only static scene objects should be draw in this shadow maps.
    All dynamic scene objects should be rendered in real time in another 10-20 shadow maps. Then, on the final desicion on "is pixel in shadow" we check both: baked and real time shadow maps. If at least one test is "in shadow" then the pixel in shadow, otherwise not.

    Why I need exactly THIS approach?
    Because I don't want to bake a lot of GI textures, and shadow mask textures for my scene. It is about 100+ textures and about 1 hour of time to bake this (with progressive GPU lightmapper).

    So, as a short resume about what I want.
    Bake shadow maps for every static light in a scene. Draw only static objects in this shadow maps.
    In real time draw shadow maps for every non static objects in scene, and for every non static light.
    Use both baked and real time shadow maps to deside is pixel in shadow.
    It there any way to achive this in unity? (preferrably from the box).
     
  2. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    Unfortunately there's no static shadowmap caching as of yet. You could do this at runtime, but you'd need to assign static/dynamic objects to different light layers so you can distinguish them at runtime. Calculate the static one, keep it around and merge it with the dynamic one. This shadowmap could then be fed into the shaders. If you want to double fetch and evaluate in the shader, you'd have to custom code the material lighting as well.
     
  3. cnheider

    cnheider

    Joined:
    Apr 5, 2017
    Posts:
    13
    You could save the shadow maps of the static objects using light sources on a StaticObject layer in a commandbuffer at LightEvent.AfterShadowMap, then disable these light and draw them onto the screen yourself in a commandbuffer at CameraEvent.AfterLighting. For the non-statics have some other light sources for a DynamicObject layer on top of the disabled ones.