zoukankan      html  css  js  c++  java
  • 在场景中融合物体的阴影与背景-Unity3d shader的灵活运用

    好久没来博客园了,忙于生活的奔波,迷失在这世间的万紫千红,只有坐在电脑前才会让我感到平静。

    这个shader使用了3个pass,来实现物体阴影与背景融合的效果,里面的宏参阅include的几个文件。

    //code--------start

    Shader "tcRecShadowAR" {//by tc ,at cas,in otc

    subShader{

         Tags { "Queue"="Opaque" "IgnoreProjector"="True" "RenderType"="Opaque" }
         LOD 200
    //    
         GrabPass {}
        
    //visibly
    Pass {
        
    Tags {"LightMode" = "ForwardBase"}
    Blend SrcAlpha OneMinusSrcAlpha
        
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest
    #pragma multi_compile_fwdbase
    #include "UnityCG.cginc"
    #include "AutoLight.cginc"
    #include "Lighting.cginc"

    struct v2f
    {
         float4 pos : POSITION;
         float4  uv  : texcoord0;
         LIGHTING_COORDS(1,2)

    };
    //
    float4 _GrabTexture_ST;
    v2f vert(appdata_base v)
    {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
         #if UNITY_UV_STARTS_AT_TOP
         float scale = -1.0;
         #else
         float scale = 1.0;
         #endif
         o.uv.xy = (float2(o.pos.x, o.pos.y*scale) + o.pos.w) * 0.5;
         o.uv.zw = o.pos.zw;
         TRANSFER_VERTEX_TO_FRAGMENT(o);

         return o;
    }
    //
    sampler2D _GrabTexture;
    float4 frag(v2f i) : COLOR
    {
         float4 c;
        
         float  atten = LIGHT_ATTENUATION(i);
         c.rgb = tex2Dproj( _GrabTexture, UNITY_PROJ_COORD(i.uv)) * atten;
         c.a = saturate(1 - atten);
         return c;
    }
    ENDCG
             
         }
    //
    Pass {
              Name "ShadowCollector"
              Tags { "LightMode" = "ShadowCollector" }
              //
              Fog {Mode Off}
              ZWrite On
              ZTest LEqual


    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma fragmentoption ARB_precision_hint_fastest
    #pragma multi_compile_shadowcollector
    #define SHADOW_COLLECTOR_PASS
    #include "UnityCG.cginc"
    //
    struct appdata {
         float4 vertex : POSITION;
    };

    struct v2f {
         V2F_SHADOW_COLLECTOR;
    };
    v2f vert (appdata v)
    {
         v2f o;
         TRANSFER_SHADOW_COLLECTOR(o)
         return o;
    }
    fixed4 frag (v2f i) : COLOR
    {
         SHADOW_COLLECTOR_FRAGMENT(i)
    }
    ENDCG

         }
    }

    }

    //code--------end

    http://www.cnblogs.com/litiecheng/
  • 相关阅读:
    设计模式-代理模式
    设计模式-策略模式
    设计模式-单例模式
    优先队列
    n!中质因子个数
    计算组合数
    高精度
    memset用法
    质因子分解
    素数筛法
  • 原文地址:https://www.cnblogs.com/litiecheng/p/3870184.html
Copyright © 2011-2022 走看看