Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Shader con sombras

Iniciado por jones512, Julio 24, 2015, 01:01:54 PM

Tema anterior - Siguiente tema
Hola devs!!!Estoy intendo conseguir un shader que permita utilizar texturas planas y ademas que permite arrojar sombras. Por ahora el resultado es el que busco, pero tengo el problema de que cuando pongo una luz de cualquier color, la textura no se tinta de ese mismo color.Os dejo el código:

 
Shader "Unnamed Shaders/Toony Shadows"
{
    Properties
    {
        _Color ("Main Color", Color) = (1,1,1,1)
   
        _MainTex ("Base (RGB)", 2D) = "white" {}
        _Ramp ("Toon Ramp (RGB)", 2D) = "gray" {}
        _Brightness ("Brightness 1 = neutral", Float) = 1.0  
       
        _SColor ("Shadow Color", Color) = (0.0,0.0,0.0,1)
        _LColor ("Highlight Color", Color) = (0.5,0.5,0.5,1)
    }
 
    SubShader
    {
        //Pass
        //{
            Tags { "RenderType"="Opaque" }
            LOD 200
       
            CGPROGRAM
            #pragma surface surf ToonRamp addshadow
       
            sampler2D _MainTex;
            sampler2D _Ramp;
            float4 _LColor;
            float4 _SColor;
            float4 _Color;
       
            // custom lighting function that uses a texture ramp based
            // on angle between light direction and normal
            #pragma lighting ToonRamp exclude_path:prepass
            inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
            {
                #ifndef USING_DIRECTIONAL_LIGHT
                lightDir = normalize(lightDir);
                #endif
           
                //Calculate N . L
                half d = (dot (s.Normal, lightDir)*0.5 + 0.5)*atten;
                //Basic toon shading
                half3 ramp = tex2D(_Ramp, float2(d,d)).rgb;
                //Gooch shading
                ramp = lerp(_SColor,_LColor,ramp);
           
                half4 c;
                c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
                c.a = 0;
           
                return c;
            }
       
            struct Input
            {
                float2 uv_MainTex : TEXCOORD0;
            };
       
            void surf (Input IN, inout SurfaceOutput o)
            {
                half4 c = tex2D(_MainTex, IN.uv_MainTex);
           
                o.Albedo = c.rgb * _Color.rgb;
                o.Alpha = c.a;
            }
            ENDCG
   
        //}
 
        Pass
        {
            Tags {"RenderType"="Opaque" "LightMode" = "ForwardBase"}
            CGPROGRAM
               
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdbase
                #pragma fragmentoption ARB_fog_exp2
                #pragma fragmentoption ARB_precision_hint_fastest
               
                #include "UnityCG.cginc"
                #include "AutoLight.cginc"
               
                struct v2f
                {
                    float4    pos            : SV_POSITION;
                    float2    uv            : TEXCOORD0;
                    LIGHTING_COORDS(1,2)
                };
 
                float4 _MainTex_ST;
 
                v2f vert (appdata_tan v)
                {
                    v2f o;
                   
                    o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
                    o.uv = TRANSFORM_TEX (v.texcoord, _MainTex).xy;
                    TRANSFER_VERTEX_TO_FRAGMENT(o);
                    return o;
                }
 
                sampler2D _MainTex;
                fixed _Brightness;
 
                fixed4 frag(v2f i) : COLOR
                {
                    fixed atten = LIGHT_ATTENUATION(i) * _Brightness;    // Light attenuation + shadows.
                    //fixed atten = SHADOW_ATTENUATION(i); // Shadows ONLY.
                    return tex2D(_MainTex, i.uv) * atten; //_Brightness;
                }
 
            ENDCG
        }
 
        Pass
        {
            Tags {"RenderType"="Opaque" "LightMode" = "ForwardAdd"}
            Blend One One
            CGPROGRAM
               
                #pragma vertex vert
                #pragma fragment frag
                #pragma multi_compile_fwdadd_fullshadows
                #pragma fragmentoption ARB_fog_exp2
                #pragma fragmentoption ARB_precision_hint_fastest
               
                #include "UnityCG.cginc"
                #include "AutoLight.cginc"
               
                struct v2f
                {
                    float4    pos            : SV_POSITION;
                    float2    uv            : TEXCOORD0;
                    LIGHTING_COORDS(1,2)
                };
 
                float4 _MainTex_ST;
 
                v2f vert (appdata_tan v)
                {
                    v2f o;
                   
                    o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
                    o.uv = TRANSFORM_TEX (v.texcoord, _MainTex).xy;
                    TRANSFER_VERTEX_TO_FRAGMENT(o);
                    return o;
                }
 
                sampler2D _MainTex;
                fixed _Brightness;
 
                #if _COLOR_ON
                fixed4 _Color;
                #endif
 
                fixed4 frag(v2f i) : COLOR
                {
                    fixed atten = LIGHT_ATTENUATION(i) * _Brightness;    // Light attenuation + shadows.
                    //fixed atten = SHADOW_ATTENUATION(i)* _Brightness; // Shadows ONLY.
                    return tex2D(_MainTex, i.uv) * atten;//_Brightness;
                }
            ENDCG
        }
    }
   
    Fallback "Diffuse"
}
Alguna idea?

Gracias de antemano

Etiquetas: