1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- Shader "Unlit/RimShaderPlus"
- {
- Properties
- {
- _MainTex("Base 2D", 2D) = "white"{}
- _InSideRimColor ("InSideRimColor", Color) = (1,1,1,1)
- _InSideRimPower("InSideRimPower", Range(0.0,5)) = 0
- _InSideRimIntensity("InSideRimIntensity", Range(0.0, 10)) = 0
- }
- SubShader
- {
- Tags
- {
- "RenderType"="Opaque"
- }
- LOD 100
- Pass
- {
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #include "UnityCG.cginc"
- #include "Lighting.cginc"
- sampler2D _MainTex;
- float4 _MainTex_ST;
- uniform float4 _MainColor;
- uniform float4 _InSideRimColor;
- uniform float _InSideRimPower;
- uniform float _InSideRimIntensity;
- struct appdata
- {
- float4 vertex : POSITION;
- float2 uv : TEXCOORD0;
- float3 normal : NORMAL;
- float4 tangent : TANGENT;
- };
- struct v2f
- {
- float2 uv : TEXCOORD0;
- float3 normal : TEXCOORD1;
- float4 vertex : SV_POSITION;
- float4 vertexWorld : TEXCOORD2;
- };
- v2f vert(appdata v)
- {
- v2f o;
- o.normal = mul(unity_ObjectToWorld, float4(v.normal, 0)).xyz;
- o.vertex = UnityObjectToClipPos(v.vertex);
- o.vertexWorld = mul(unity_ObjectToWorld, v.vertex);
- o.uv = v.uv;
- return o;
- }
- fixed4 frag(v2f i) : SV_Target
- {
- i.normal = normalize(i.normal);
- float3 worldViewDir = normalize(_WorldSpaceCameraPos.xyz - i.vertexWorld.xyz);
- half NdotV = max(0, dot(i.normal, worldViewDir));
- NdotV = 1.0 - NdotV;
- float fresnel = pow(NdotV, _InSideRimPower) * _InSideRimIntensity;
- fresnel *= i.normal.x;
- fresnel = max(0, fresnel);
- float3 Emissive = _InSideRimColor.rgb * fresnel;
- return tex2D(_MainTex, i.uv) + float4(Emissive, 1);
- }
- ENDCG
- }
- }
- }
|