-
-
Save unitycoder/39d207a0858be70922d9f7f54238e5a6 to your computer and use it in GitHub Desktop.
Screen-space normals shader for Unity - Compatible with URP
This file contains hidden or 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