Search Unity

Screen Space texture projection with ortho camera

Discussion in 'Shaders' started by pixpusher2, Oct 19, 2019.

  1. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Hello,

    I recently bought a Cloud Shadow shader from the Asset Store which basically projects a fake cloud shadow texture onto all objects on screen. It works fine with Perspective camera, but not with the Orthographic one. The author isn't answering my emails so now I'm trying to fix the shader myself.

    I'm a shader newbie and two things have gotten me stumped so far:
    1) How do I ensure the cloud texture is projected from top-down instead of camera view?
    topdown.jpg

    2) How do I have the cloud texture stay in place when the camera is rotated?
    This is perspective camera. Projected texture sticks nicely on the surfaces
    rotateok.gif

    This is orthographic camera. Projected texture "slides" around when camera rotates
    rotatebug.gif

    Thank you!
     
    Last edited: Oct 26, 2019
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
  3. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Thanks bgolus!
    I've just checked out Keijiro's project but I'm having trouble getting it to project a texture instead of the default grid.

    I've tried adding this line in InverseProjector.cs's OnRenderImage() method so I could pass in a texture to the shader, but strangely nothing happens after I assigned one? The shader itself seems to have built-in support for a texture.

    _material.SetTexture ("_MainTex", texture);


    Any idea what I'm doing wrong?
    Cheers
     
    Last edited: Oct 20, 2019
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Well, you’ll probably want to make a whole new shader that’s an amalgam of both, or at least modify the existing cloud shader implementing the orthographic method used in Keijiro’s shader. Mainly don’t use the “Visualize” function in Keijiro’s shader, just use the position it calculates transformed into world space.
     
  5. pixpusher2

    pixpusher2

    Joined:
    Oct 30, 2013
    Posts:
    121
    Yeah that's what I'm trying to do, but I have to figure out how the projected texture UVs work in Keijiro's before I can combine them properly. I'll dig more into it tonight, thanks