Search Unity

Fragment Shader Normals in DepthNormalsTexture

Discussion in 'Shaders' started by Chimera3D, Sep 30, 2014.

  1. Chimera3D

    Chimera3D

    Joined:
    Jan 27, 2012
    Posts:
    73
    I'm wondering how I can go about storing the normals from a fragment shader so that they are accessible when rendering a DepthNormals Texture. The normals from the fragment shader are derived from a normal map. The surface shaders in Unity handle this wonderfully which can be demonstrated by placing a simple mesh with a material with the diffuse normal map shader, in front of a camera and rendering the depthnormals texture. The normals from the normal map are accounted for when rendering the depthnormals texture and accessing the normals component. All I want to do is have the same functionality of accounting for the normals of a normal map, but for a custom fragment shader that also uses normal maps. Has anyone done this before or does anyone know how Unity does this internally?
     
  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    That's a good question. I thought it was handled by shader replacement using Camera-DepthNormalTexture.shader, which you can find in the built-in shaders package. Ostensibly, this file should have all the sub shaders used to render view space normals for each RenderType. However, there is no mention of normal maps in that file, so I'm not sure how normal maps are accounted for.
     
  3. Chimera3D

    Chimera3D

    Joined:
    Jan 27, 2012
    Posts:
    73
    If there's not a way to get the normals from a custom fragment shader into a DepthNormalsTexture then can someone let me know if I just need to move on? There surely has to be an alternative though, right?
     
  4. Chimera3D

    Chimera3D

    Joined:
    Jan 27, 2012
    Posts:
    73
    Bump. I tried checking compiled surface shaders and the compiled depthtexturenormals replacement shader and found nothing that seemed to be internally storing the normals in the surf shader for the depthtexutre shader.