Last active
December 19, 2018 09:48
-
-
Save TheStoneBook/fe031ed2280dcc6488dab535953f7e54 to your computer and use it in GitHub Desktop.
【Unity】リムライティングっぽいシェーダー(StandardShader版)
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 "Custom/RimLightingStandard" { | |
Properties { | |
_MainColor ("MainColor", Color) = (1,1,1,1) | |
_MainTex ("Albedo (RGB)", 2D) = "white" {} | |
_RimColor("RimColor",Color)=(1,1,1,1) | |
_RimPower("RimPower", Range(0.1, 10.0)) = 3.0 | |
_RimAmplitude("RimAmplitude",Float)=1 | |
_Alpha("Alpha",Range(0.0,1.0))=1 | |
} | |
SubShader { | |
Tags { "RenderType"="Transparent" "Queue"="Transparent" } | |
LOD 200 | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass{ | |
ZWrite ON | |
ColorMask 0 | |
} | |
CGPROGRAM | |
#pragma surface surf Standard fullforwardshadows alpha:fade | |
#pragma target 3.0 | |
sampler2D _MainTex; | |
fixed4 _MainColor; | |
fixed4 _RimColor; | |
half _RimPower; | |
float _RimAmplitude; | |
float _Alpha; | |
struct Input { | |
float2 uv_MainTex; | |
float3 worldPos; | |
float3 worldNormal; | |
float3 viewDir; | |
}; | |
void surf (Input IN, inout SurfaceOutputStandard o) { | |
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _MainColor; | |
float3 normalDir = normalize(IN.worldNormal); | |
float3 viewDir = normalize(_WorldSpaceCameraPos.xyz-IN.worldPos.xyz); | |
float NVdot = 1 - dot(viewDir,normalDir); | |
float rim=pow(NVdot,_RimPower)*_RimAmplitude; | |
o.Albedo += rim*(1-abs(_Alpha*2-1))*_RimColor.rgb; | |
o.Alpha = _Alpha * (1 + rim); | |
} | |
ENDCG | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment