Skip to content

Instantly share code, notes, and snippets.

@ninpl
Last active March 7, 2023 10:49
Show Gist options
  • Save ninpl/f58cbc84fcc30ae3a31225fdcba5b730 to your computer and use it in GitHub Desktop.
Save ninpl/f58cbc84fcc30ae3a31225fdcba5b730 to your computer and use it in GitHub Desktop.
Shader Cell - Iluminación personalizada.
Shader "NinePlus/CellShading"
{
Properties
{
_MainTex("Albedo (RGB)", 2D) = "white" {}
_RampTex("Ramp", 2D) = "white" {}
_CelShadingLevels("Cel Shading Levels", Range(0,15)) = 5
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// En lugar de Standart, apunta a una funcion llamada LightingToon()
#pragma surface surf Toon
#pragma target 3.0
sampler2D _MainTex;
sampler2D _RampTex;
float _CelShadingLevels;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb;
}
half4 LightingToon(SurfaceOutput s, half3 lightDir, half atten)
{
half NdotL = dot(s.Normal, lightDir);
// Ajustar el nivel de iluminacion
half cel = floor(NdotL * _CelShadingLevels) / (_CelShadingLevels - 0.5);
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (cel * atten * 1);
c.a = s.Alpha;
return c;
}
ENDCG
}
FallBack "Diffuse"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment