From addf7b0b00af93fa97058627f99e43a49d30c824 Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Sat, 1 Nov 2014 22:09:11 +0100 Subject: [PATCH] Ajout CellShader --- Assets/shaders.meta | 5 ++ Assets/shaders/CellShader.shader | 111 ++++++++++++++++++++++++++ Assets/shaders/CellShader.shader.meta | 5 ++ 3 files changed, 121 insertions(+) create mode 100644 Assets/shaders.meta create mode 100644 Assets/shaders/CellShader.shader create mode 100644 Assets/shaders/CellShader.shader.meta diff --git a/Assets/shaders.meta b/Assets/shaders.meta new file mode 100644 index 0000000..4d3ab82 --- /dev/null +++ b/Assets/shaders.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: b7086103ad8ed184bbd2bf659314d70f +folderAsset: yes +DefaultImporter: + userData: diff --git a/Assets/shaders/CellShader.shader b/Assets/shaders/CellShader.shader new file mode 100644 index 0000000..6e2fd30 --- /dev/null +++ b/Assets/shaders/CellShader.shader @@ -0,0 +1,111 @@ +// Credit for all code goes to Arthur B. (Pvloon) +// Released to the Unify Community Wiki as part of a contest, for free or commercial use; +// HOWEVER, THIS NOTICE MUST BE RETAINED IF ANY OF THE FOLLOWING CODE IS USED. + +// Upgrade NOTE: replaced 'V2F_POS_FOG' with 'float4 pos : SV_POSITION' + +Shader "CellShader" { + Properties { + _Color ("Main Color", Color) = (1,1,1,1) + _MainTex ("Color 1 (RGB)", 2D) = "white" {} + _MainTex2 ("Color 2 (RGB)", 2D) = "white" {} + _MainTex3 ("Color 3 (RGB)", 2D) = "white" {} + _MainTex4 ("Color 4 (RGB)", 2D) = "white" {} + _Mask ("Mixing Mask (RGBA)", 2D) = "gray" {} + _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} + _Base ("Base Color (RGB)", 2D) = "white" {} + _LightCutoff("Light Cutoff", Range(0, 0.5)) = 0.05 + } + + Category { + Lighting On + Cull Back + Fog { Color [_AddFog] } + Subshader + { + CGPROGRAM + #pragma surface surf ToonRamp + + sampler2D _Ramp; + float _LightCutoff; + + inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten) + { + #ifndef USING_DIRECTIONAL_LIGHT + lightDir = normalize(lightDir); + #endif + + half d = dot (s.Normal, lightDir)*0.5 + 0.5; + + half3 ramp = tex2D (_Ramp, float2(d,d)).rgb; + + half4 c; + + if (atten > (1.0 - _LightCutoff)) + atten = 1.0; + else if (atten < _LightCutoff) + atten = 0; + + c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2); + c.a = 0; + return c; + } + + sampler2D _MainTex; + sampler2D _MainTex2; + sampler2D _MainTex3; + sampler2D _MainTex4; + sampler2D _Mask; + float4 _Color; + + struct Input { + float4 pos : SV_POSITION; + float2 uv_MainTex; + float2 uv_MainTex2; + float2 uv_MainTex3; + float2 uv_MainTex4; + float2 uv_Mask; + float2 uv_Base; + + + float4 diffuse : COLOR; + }; + + + + void surf (Input IN, inout SurfaceOutput o) { + // get the first three layer colors + half4 color1 = tex2D( _MainTex, IN.uv_MainTex); + half4 color2 = tex2D( _MainTex2, IN.uv_MainTex2); + half4 color3 = tex2D( _MainTex3, IN.uv_MainTex3); + half4 color4 = tex2D( _MainTex4, IN.uv_MainTex4); + + // get the mixing mask texture + half4 mask = tex2D( _Mask, IN.uv_Mask.xy); + // mix the three layers + + half4 color = color1 * mask.r + color2 * mask.g + color3 * mask.b + color4 * mask.a; + + o.Albedo = color.rgb; + o.Alpha = color.a; + } + + ENDCG + } + } + + // ------------------------------------------------------------------ + // Radeon 7000 / 9000 + SubShader { + Pass { + Material { + Diffuse [_Color] + Ambient [_Color] + } + Lighting On + SetTexture [_Base] { + Combine texture * primary DOUBLE, texture * primary + } + } + } +} \ No newline at end of file diff --git a/Assets/shaders/CellShader.shader.meta b/Assets/shaders/CellShader.shader.meta new file mode 100644 index 0000000..7b60fbb --- /dev/null +++ b/Assets/shaders/CellShader.shader.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: e06fbfc02a7365d4fbe662a4beaa14c3 +ShaderImporter: + defaultTextures: [] + userData: