#Unable to use normal texture in shader

1 messages · Page 1 of 1 (latest)

median quail
#

Hello, I am relatively new to Unity, and I am trying to implement an outline scriptable render feature.

The way it would work is essentially to pass the depth and normal textures into a shader and use a Sobel filter on both to determine if an edge has to be drawn.

I am however struggling immensely when it comes to implementing this, unity just does not want to play well.

I keep getting errors like: Shader error in 'Shader Graphs/Master': redefinition of '_CameraNormalsTexture' at line 183 (on metal)

#

I have tried 2 different methods:

  1. Make the following fullscreen shader graph
#

where the custom function Outline contains this hlsl code:

#

That causes these two compilation errors:

#

^ Idk why this won't work, unfortunately, I am not accustomed to using the frame debugger very well yet

quaint tundra
# median quail I have tried 2 different methods: 1. Make the following fullscreen shader graph

The graph may already be defining _CameraNormalsTexture through an include file : DeclareDepthNormals.hlsl

Possibly _CameraDepthTexture too (through DeclareDepthTexture.hlsl), though that might only be defined when using the Scene Depth node since that one doesn't seem to be erroring.

Just removing the normals texture from the blackboard might fix it.
Though to be safer, it might be better to remove both and add those includes to your hlsl file.

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"

(Even if the graph is automatically including them, the #ifndef on line 1 prevents them being included multiple times)
Could even use the SampleSceneNormals/SampleSceneDepth functions inside those for sampling too.

median quail
#

Tried doing some Googling, but what I found seems to indicate that it has to do with the import overwriting some stuff maybe? I'm assuming I have to insert some sort of ifndef somewhere

quaint tundra
#

For example, I write a lot of functions intended only for URP like this

void MainLight_float (out float3 Direction, out float3 Color, out float DistanceAtten){
    #ifdef SHADERGRAPH_PREVIEW
        Direction = normalize(float3(1,1,-0.4));
        Color = float4(1,1,1,1);
        DistanceAtten = 1;
    #else
        Light mainLight = GetMainLight();
        Direction = mainLight.direction;
        Color = mainLight.color;
        DistanceAtten = mainLight.distanceAttenuation;
    #endif
}

GetMainLight() here only exists in URP so breaks within shadergraph (as it can target other pipelines). Using the SHADERGRAPH_PREVIEW avoids it erroring.