Created
December 9, 2021 10:23
-
-
Save cs-altshift/a7404796599eb6284c92e3a19a4cf99b to your computer and use it in GitHub Desktop.
Screen-space normals shader for Unity - Compatible with URP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Unlit/Screen Space Normals" | |
{ | |
Properties | |
{ | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL0; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 viewNormal : NORMAL0; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
float3 worldNormal = UnityObjectToWorldNormal(v.normal); | |
o.viewNormal = mul((float3x3)UNITY_MATRIX_V, worldNormal); | |
return o; | |
} | |
float4 frag (v2f i) : SV_Target | |
{ | |
float4 color = 0; | |
color.rgb = i.viewNormal * 0.5 + 0.5; | |
return color; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment