Created
December 24, 2017 12:35
-
-
Save Santarh/00e5d7f5d93f4e77bce0449a42ad7deb to your computer and use it in GitHub Desktop.
Unity Shader Template
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 "SantarhTemplate" | |
{ | |
Properties | |
{ | |
} | |
SubShader | |
{ | |
Tags { "RenderType" = "Opaque" "Queue" = "Geometry" } | |
Cull Back | |
ZWrite On | |
CGINCLUDE | |
#include "Lighting.cginc" | |
#include "AutoLight.cginc" | |
#pragma target 3.0 | |
struct v2f | |
{ | |
float4 pos : SV_POSITION; | |
float4 posWorld : TEXCOORD0; | |
float3 normal : TEXCOORD1; | |
float3 tangent : TEXCOORD2; | |
float2 uv0 : TEXCOORD3; | |
float2 uv1 : TEXCOORD4; | |
SHADOW_COORDS(5) | |
UNITY_FOG_COORDS(6) | |
}; | |
v2f vert(appdata_full v) | |
{ | |
v2f o; | |
o.pos = UnityObjectToClipPos(v.vertex); | |
o.posWorld = mul(unity_ObjectToWorld, v.vertex); | |
o.uv0 = v.texcoord; | |
o.uv1 = v.texcoord1; | |
o.normal = normalize(UnityObjectToWorldNormal(v.normal)); | |
o.tangent = normalize(mul(unity_ObjectToWorld, float4(v.tangent.xyz, 0.0)).xyz); | |
TRANSFER_SHADOW(o); | |
UNITY_TRANSFER_FOG(o, o.pos); | |
return o; | |
} | |
float4 frag(v2f i) : SV_TARGET | |
{ | |
float3 view = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz); | |
float3 viewReflect = reflect(-view, i.normal); | |
UNITY_LIGHT_ATTENUATION(atten, i, i.posWorld.xyz); | |
half3 lightDir; | |
if (_WorldSpaceLightPos0.w == 0) | |
{ | |
lightDir = _WorldSpaceLightPos0.xyz; | |
} | |
else | |
{ | |
lightDir = normalize(_WorldSpaceLightPos0.xyz - i.posWorld.xyz); | |
} | |
half3 directLighting = saturate(dot(lightDir, i.normal)) * _LightColor0.rgb * atten; | |
half3 indirectLighting = ShadeSH9(half4(i.normal, 1)); | |
half4 col = half4(indirectLighting + directLighting, 1); | |
UNITY_APPLY_FOG(i.fogCoord, col); | |
return col; | |
} | |
ENDCG | |
Pass | |
{ | |
Name "FORWARD" | |
Tags { "LightMode" = "ForwardBase" } | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fwdbase | |
#pragma multi_compile_fog | |
ENDCG | |
} | |
Pass | |
{ | |
Name "FORWARD_DELTA" | |
Tags { "LightMode" = "ForwardAdd" } | |
Blend One One | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#pragma multi_compile_fwdadd_fullshadows | |
#pragma multi_compile_fog | |
ENDCG | |
} | |
} | |
Fallback "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment