Created
July 2, 2020 02:30
-
-
Save esnya/6fe8c457e661d079beca61777552fbae to your computer and use it in GitHub Desktop.
Unity用法線可視化シェーダー
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
| // MIT License (c) http://github.com/esnya | |
| Shader "Unlit/WorldNormal" | |
| { | |
| Properties | |
| { | |
| _MainTex ("Texture", 2D) = "white" {} | |
| _BumpMap ("Texture", 2D) = "bump" {} | |
| _BumpScale ("Normal Scale", Range(0, 1)) = 1.0 | |
| _MixFactor ("Mix Factor", Range(0, 1)) = 1 | |
| } | |
| SubShader | |
| { | |
| Tags { "RenderType"="Opaque" } | |
| LOD 100 | |
| Pass | |
| { | |
| CGPROGRAM | |
| #pragma vertex vert | |
| #pragma fragment frag | |
| // make fog work | |
| #pragma multi_compile_fog | |
| #include "UnityCG.cginc" | |
| struct appdata | |
| { | |
| float4 vertex : POSITION; | |
| float3 normal : NORMAL; | |
| float2 uv : TEXCOORD; | |
| }; | |
| struct v2f | |
| { | |
| float4 vertex : SV_POSITION; | |
| float3 normal : NORMAL; | |
| float2 uv : TEXCOORD; | |
| UNITY_FOG_COORDS(1) | |
| }; | |
| sampler2D _MainTex; | |
| float4 _MainTex_ST; | |
| sampler2D _BumpMap; | |
| float4 _BumpMap_ST; | |
| float _BumpScale; | |
| float _MixFactor; | |
| v2f vert (appdata v) | |
| { | |
| v2f o; | |
| o.vertex = UnityObjectToClipPos(v.vertex); | |
| o.normal = v.normal; | |
| o.uv = v.uv; | |
| UNITY_TRANSFER_FOG(o,o.vertex); | |
| return o; | |
| } | |
| fixed4 frag (v2f i) : SV_Target | |
| { | |
| fixed3 normal = normalize(i.normal + UnpackNormal(tex2D(_BumpMap, i.uv)) * _BumpScale); | |
| fixed4 col = lerp(tex2D(_MainTex, i.uv), fixed4(normal, 1), _MixFactor); | |
| // apply fog | |
| UNITY_APPLY_FOG(i.fogCoord, col); | |
| return col; | |
| } | |
| ENDCG | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment