You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/SliderRamp/Shaders/SliderRampSpecularRimTriPla...

245 lines
6.8 KiB
Plaintext

2 months ago
// Toony Colors Pro+Mobile 2
// (c) 2014-2020 Jean Moreno
Shader "Voodoo_LaunchOps/SliderRampSpecularRimTriPlanar"
{
Properties
{
[TCP2HeaderHelp(BASE, Base Properties)]
//TOONY COLORS
_Color ("Color", Color) = (1,1,1,1)
_HColor ("Highlight Color", Color) = (0.785,0.785,0.785,1.0)
_SColor ("Shadow Color", Color) = (0.195,0.195,0.195,1.0)
//DIFFUSE
_MainTex ("Main Texture", 2D) = "white" {}
[Header(Triplanar Mapping)]
_TriSide ("Sides", 2D) = "white" {}
[Space]
[TCP2Vector4Floats(Contrast X,Contrast Y,Contrast Z,Smoothing,1,16,1,16,1,16,0.05,1)] _TriplanarBlendStrength ("Triplanar Parameters", Vector) = (2,8,2,0.5)
[TCP2Separator]
//TOONY COLORS RAMP
[TCP2Header(RAMP SETTINGS)]
_RampThreshold ("Ramp Threshold", Range(0,1)) = 0.5
_RampSmooth ("Ramp Smoothing", Range(0.001,1)) = 0.1
[TCP2Separator]
[TCP2HeaderHelp(SPECULAR, Specular)]
//SPECULAR
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Smoothness ("Size", Float) = 0.2
_SpecSmooth ("Smoothness", Range(0,1)) = 0.05
[TCP2Separator]
[TCP2HeaderHelp(RIM, Rim)]
//RIM LIGHT
_RimColor ("Rim Color", Color) = (0.8,0.8,0.8,0.6)
_RimMin ("Rim Min", Range(0,2)) = 0.5
_RimMax ("Rim Max", Range(0,2)) = 1.0
[TCP2Separator]
//Avoid compile error if the properties are ending with a drawer
[HideInInspector] __dummy__ ("unused", Float) = 0
}
SubShader
{
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf ToonyColorsCustom vertex:vert exclude_path:deferred exclude_path:prepass
#pragma target 3.0
//================================================================
// VARIABLES
fixed4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _TriplanarBlendStrength;
sampler2D _TriSide;
float4 _TriSide_ST;
fixed _Smoothness;
fixed4 _RimColor;
fixed _RimMin;
fixed _RimMax;
float4 _RimDir;
#define UV_MAINTEX mainTexUv
struct Input
{
half2 mainTexUv;
float3 worldPos;
float3 worldNormal;
float3 viewDir;
};
//================================================================
// CUSTOM LIGHTING
//Lighting-related variables
fixed4 _HColor;
fixed4 _SColor;
half _RampThreshold;
half _RampSmooth;
fixed _SpecSmooth;
// Instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
//Custom SurfaceOutput
struct SurfaceOutputCustom
{
half atten;
fixed3 Albedo;
fixed3 Normal;
fixed3 Emission;
half Specular;
fixed Gloss;
fixed Alpha;
};
inline half4 LightingToonyColorsCustom (inout SurfaceOutputCustom s, half3 viewDir, UnityGI gi)
{
#define IN_NORMAL s.Normal
half3 lightDir = gi.light.dir;
#if defined(UNITY_PASS_FORWARDBASE)
half3 lightColor = _LightColor0.rgb;
half atten = s.atten;
#else
half3 lightColor = gi.light.color.rgb;
half atten = 1;
#endif
IN_NORMAL = normalize(IN_NORMAL);
fixed ndl = max(0, dot(IN_NORMAL, lightDir));
#define NDL ndl
#define RAMP_THRESHOLD _RampThreshold
#define RAMP_SMOOTH _RampSmooth
fixed3 ramp = smoothstep(RAMP_THRESHOLD - RAMP_SMOOTH*0.5, RAMP_THRESHOLD + RAMP_SMOOTH*0.5, NDL);
#if !(POINT) && !(SPOT)
ramp *= atten;
#endif
// Note: we consider that a directional light with a cookie is supposed to be the main one (even though Unity renders it as an additional light).
// Thus when using a main directional light AND another directional light with a cookie, then the shadow color might be applied twice.
// You can remove the DIRECTIONAL_COOKIE check below the prevent that.
#if !defined(UNITY_PASS_FORWARDBASE) && !defined(DIRECTIONAL_COOKIE)
_SColor = fixed4(0,0,0,1);
#endif
_SColor = lerp(_HColor, _SColor, _SColor.a); //Shadows intensity through alpha
ramp = lerp(_SColor.rgb, _HColor.rgb, ramp);
//Blinn-Phong Specular (legacy)
half3 h = normalize(lightDir + viewDir);
float ndh = max(0, dot (IN_NORMAL, h));
float spec = pow(ndh, s.Specular*128.0) * s.Gloss * 2.0;
spec = smoothstep(0.5-_SpecSmooth*0.5, 0.5+_SpecSmooth*0.5, spec);
spec *= atten;
fixed4 c;
c.rgb = s.Albedo * lightColor.rgb * ramp;
#if (POINT || SPOT)
c.rgb *= atten;
#endif
#define SPEC_COLOR _SpecColor.rgb
c.rgb += lightColor.rgb * SPEC_COLOR * spec;
c.a = s.Alpha;
#ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
c.rgb += s.Albedo * gi.indirect.diffuse;
#endif
return c;
}
void LightingToonyColorsCustom_GI(inout SurfaceOutputCustom s, UnityGIInput data, inout UnityGI gi)
{
gi = UnityGlobalIllumination(data, 1.0, IN_NORMAL);
s.atten = data.atten; //transfer attenuation to lighting function
gi.light.color = _LightColor0.rgb; //remove attenuation
}
//Vertex input
struct appdata_tcp2
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
#if defined(LIGHTMAP_ON) && defined(DIRLIGHTMAP_COMBINED)
float4 tangent : TANGENT;
#endif
#if UNITY_VERSION >= 550
UNITY_VERTEX_INPUT_INSTANCE_ID
#endif
};
//================================================================
// VERTEX FUNCTION
void vert(inout appdata_tcp2 v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.mainTexUv = TRANSFORM_TEX(v.texcoord, _MainTex);
}
//================================================================
// SURFACE FUNCTION
void surf(Input IN, inout SurfaceOutputCustom o)
{
//Triplanar Texture Blending
half2 uv_ground = IN.worldPos.xz;
half2 uv_sideX = IN.worldPos.xy;
half2 uv_sideZ = IN.worldPos.zy;
//ground
fixed4 mainTex = tex2D(_MainTex, uv_ground * _MainTex_ST.xy + _MainTex_ST.zw);
//sides
fixed4 tex_sideX = tex2D(_TriSide, uv_sideX * _TriSide_ST.xy + _TriSide_ST.zw);
fixed4 tex_sideZ = tex2D(_TriSide, uv_sideZ * _TriSide_ST.xy + _TriSide_ST.zw);
//blending
#define WORLD_NORMAL IN.worldNormal
half3 blendWeights = pow(abs(WORLD_NORMAL), _TriplanarBlendStrength.xyz / _TriplanarBlendStrength.w);
blendWeights = blendWeights / (blendWeights.x + abs(blendWeights.y) + blendWeights.z);
mainTex = tex_sideZ * blendWeights.x + mainTex * blendWeights.y + tex_sideX * blendWeights.z;
o.Albedo = mainTex.rgb * _Color.rgb;
o.Alpha = mainTex.a * _Color.a;
//Specular
o.Gloss = 1;
o.Specular = _Smoothness;
//Rim
float3 viewDir = normalize(IN.viewDir);
half rim = 1.0f - saturate( dot(viewDir, o.Normal) );
rim = smoothstep(_RimMin, _RimMax, rim);
o.Emission += (_RimColor.rgb * rim) * _RimColor.a;
}
ENDCG
}
Fallback "Diffuse"
CustomEditor "TCP2_MaterialInspector_SG"
}