Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can I use world normals in a post processing shader?

Discussion in 'Shaders' started by dccoo, Sep 8, 2022.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    In a nutshell, I want to do a post processing effect using the world normals of the scene.

    I'm using Unity 2020.3.26 and URP 10.8.1 and I tried hard to use
    _CameraDepthNormalsTexture
    in my unlit shader but it doesn't work no matter what I do (although
    _CameraDepthTexture
    works fine). I obviously set
    cam.depthTextureMode = DepthTextureMode.DepthNormals
    .

    What can I do to access the world normal texture in a post processing shader?
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Include this hlsl and just use SampleSceneNormals
    upload_2022-9-8_12-8-31.png

    But be sure you've configured your ScriptableRenderPass properly in your PPS ScriptableRendererFeature, it will guarantee that DepthNormalOnlyPass will be always executed before your renderer feature (if it's not been executed yet) and _CameraNormalsTexture will be filled.
    upload_2022-9-8_12-10-22.png
     
    dccoo likes this.