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

Resolved From orthographic depth to perspective position?

Discussion in 'Shaders' started by yonir2, Sep 8, 2020.

  1. yonir2

    yonir2

    Joined:
    Aug 29, 2020
    Posts:
    2
    So I created a shader for dynamic snow/rain coverage.

    shader.png

    The final shader is applied in screen space, but in between I do the following:

    - Create a grid of the map
    - Render each grid cell from top with an orthographic camera, it looks like this

    upload_2020-9-8_4-17-52.png

    - Now get all visible grid cells in view and render them using the main camera using an unlit shader (to capture depth and the coverage amount):

    shader2.png


    Now I can use this information when applying the final fullscreen shader.

    The problem is: It obviously works only for the same height, meaning the grid-ground has to be even. I could create another grid + cells for each height layer and use transparency-hacks so they can properly overlap etc... But I wonder, is there maybe a way to capture the height or rather depth from the orthographic camera and then use that depth to displace the pixels to their actual "height" when I render all the grid cells in perspective mode?
     
  2. yonir2

    yonir2

    Joined:
    Aug 29, 2020
    Posts:
    2
    I solved it by rendering each cell on top of the underlying geometry using a decal shader.

    shader.png shader1.png shader2.png