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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Shadow casting for raymarched volumes?

Discussion in 'Shaders' started by TopiTirkkonen, Jun 23, 2018.

  1. TopiTirkkonen

    TopiTirkkonen

    Joined:
    Dec 8, 2017
    Posts:
    5
    I have a shader which raymarches at a constant step into a 3D-texture based volume inside the mesh that the shader is applied to. I implemented the shadowing technique here (at the end of the page), but obviously it just creates shadows for the mesh and not the rendered volume.

    So ultimately I'd like to make the volume cast shadows on other objects.
    How should I approach this?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,243
    The same way you're doing your raymarching for the main pass. Presumably your raymarching is outputting a depth from the fragment shader. For directional lights and spot lights the depth is the only thing the shadow map depth pass cares about.
     
  3. TopiTirkkonen

    TopiTirkkonen

    Joined:
    Dec 8, 2017
    Posts:
    5
    Thanks for the quick answer. But how do I output the depth from main pass to shadow pass and how do I use it as an input in the shadow pass. Should I go with render textures?

    Also is there something I should know about these:

    V2F_SHADOW_CASTER
    TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    SHADOW_CASTER_FRAGMENT(i)
     
  4. TopiTirkkonen

    TopiTirkkonen

    Joined:
    Dec 8, 2017
    Posts:
    5
    I got it working with this answer from you. So thank you.
     
  5. ccoddes

    ccoddes

    Joined:
    Mar 6, 2017
    Posts:
    3
    I'm currently trying to do exactly what you wanted to (shadow cast from a raymarched volume), but after reading up on shadowcasting, etc, everything is still going over my head relating to how to get the depth values into the shadow caster. I wonder if you could provide a code sample or demonstration of what you managed to get working? It would greatly help with my understanding :(
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,243