作者:Amyjionydp | 来源:互联网 | 2023-09-01 17:37
unity 卡通动物 shader 包含边缘光,ramp,描边
上shader
Shader "Unlit/TestShader"
{Properties {_Diff ("Diff", 2D) = "white" {}_MainColor ("MainColor", Color) = (0,0,0,1) _RAMP ("RAMP", 2D) = "white" {}_Light ("Light", Vector) = (0,0,0,0)_InSideRimColor ("InSideRimColor", Color) = (1,1,1,1)_InSideRimPower("InSideRimPower", Range(0.0,5)) = 0 _InSideRimIntensity("InSideRimIntensity", Range(0.0, 10)) = 0 _Outline_Width ("Outline_Width", Float ) = 1_Outline_Color ("Outline_Color", Color) = (0.5,0.5,0.5,1)_Outline_Offset_X ("Outline_Offset_X", Float) = 0_Outline_Offset_Y ("Outline_Offset_Y", Float) = 0_GradHeight ("GradHeight",float) =1_GradColor ("GradColor", Color) = (0.125,0.125,0.125,1)}SubShader {Tags {"RenderType"="Opaque"}LOD 100Pass {Name "ForwardBase"Tags {"LightMode"="ForwardBase" "Queue" = "Geometry"}Fog {Mode Off}CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#pragma multi_compile_fwdbase_fullshadows#pragma exclude_renderers xbox360 ps3 flash d3d11_9x #pragma target 2.0uniform sampler2D _Diff; uniform float4 _Diff_ST;uniform float4 _MainColor;uniform sampler2D _RAMP; uniform float4 _RAMP_ST;uniform float4 _Light;uniform float4 _InSideRimColor;uniform float _InSideRimPower;uniform float _InSideRimIntensity; uniform fixed4 _GradColor;uniform half _GradHeight;uniform float _Outline_Offset_X;uniform float _Outline_Offset_Y;struct VertexInput {float4 vertex : POSITION;float2 uv : TEXCOORD0;float3 normal : NORMAL;};struct VertexOutput {float2 uv : TEXCOORD0;float3 normal : TEXCOORD1;float4 vertex : SV_POSITION;float4 vertexWorld : TEXCOORD2;half grad:TEXCOORD3;};VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0;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;o.grad = mul(unity_ObjectToWorld, v.vertex).y;return o;}fixed4 frag(VertexOutput i) : COLOR {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;float3 Emissive=_InSideRimColor.rgb*fresnel; float4 _Diff_var = tex2D(_Diff,TRANSFORM_TEX(i.uv, _Diff)); float4 FinalCompOut = _Diff_var*_MainColor;float RampUV_var = max(0,dot(mul( unity_WorldToObject, float4(_Light.rgb,0) ).xyz,i.normal));float2 RampUV = float2(RampUV_var,RampUV_var);float4 _RAMP_var = tex2D(_RAMP,TRANSFORM_TEX(RampUV, _RAMP));FinalCompOut.rgb*=_RAMP_var.rgb;FinalCompOut.rgb = FinalCompOut.rgb+Emissive;FinalCompOut.xyz = lerp(_GradColor.xyz*FinalCompOut.xyz,FinalCompOut.xyz,clamp(i.grad,0,_GradHeight)/_GradHeight);return FinalCompOut;}ENDCG}Pass {Name "Outline"Tags {"Queue" = "Transparent"}Cull FrontZWrite OffOffset [_Outline_Offset_X], [_Outline_Offset_Y]CGPROGRAM#pragma vertex vert#pragma fragment frag#include "UnityCG.cginc"#pragma exclude_renderers xbox360 ps3 flash d3d11_9x #pragma target 3.0uniform float _Outline_Width;uniform float4 _Outline_Color;struct VertexInput {float4 vertex : POSITION;float3 normal : NORMAL;};struct VertexOutput {float4 pos : SV_POSITION;};VertexOutput vert (VertexInput v) {VertexOutput o = (VertexOutput)0;o.pos = UnityObjectToClipPos(v.vertex);float3 norm = mul ((float3x3)UNITY_MATRIX_IT_MV, v.normal);float2 offset = TransformViewToProjection(norm.xy);o.pos.xy += offset * o.pos.z * _Outline_Width;return o;}float4 frag(VertexOutput i, float facing : VFACE) : SV_Target{return _Outline_Color;}ENDCG}}FallBack "Diffuse"
}