Search Unity

Billboard-like shader + ShadowCaster

Discussion in 'Shaders' started by soulburner, Sep 20, 2020.

  1. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    I'm implementing a billboard-style shader (which maps a texture always facing to the camera on any 3D object).

    Imagine a sprite of a bush mapped to a sphere like this:


    (I need that for lighting, and I know I can use normal maps, but this is not the case. I'm going to use this shader for quite complex objects).

    Texture mapping works great, but I got troubles with shadows.

    I've made my own shadowcaster pass, but the trouble is that I use unity_WorldToCamera for coords calculation and obviously that works wrong for the light lines perpendicular to the line of sight. My bush-ball looks something like this for the light perpendicular to the camera:


    And I get these weird shadows.

    As I see, the correct way is to use something like "unity_WorldToLight" in the shadowcaster pass, but it is not accessable during this pass. I'm even not sure if a shadowcaster pass called each time for each light source. I couldn't find any information on that.

    PS: I'm using a built-in render pipeline, if that matters.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You want
    UNITY_MATRIX_V
    , which is the world to view space transform for the currently rendering view.
     
    soulburner likes this.