zoukankan      html  css  js  c++  java
  • Unity3D Shader落雪效果

    Shader "Custom/Snow" {
        Properties {
            _MainTex ("Base (RGB)", 2D) = "white" {}
            _RimColor("Rim Color", Color) = (1,1,1,1)
            _SnowPower ("Snow Power",range(0,1)) = 0.2//边缘强度
            _SnowRang("Snow Range",range(0,1)) = 0.1
        }
    
        SubShader {
    
    
            Pass
            {
            
            CGPROGRAM
    
            #include "UnityCG.cginc"
    
            
    
            struct v2f
            {
                float4 vertex:POSITION;
                float2 uv:TEXCOORD0;
                float3 normal:TEXCOORD1;
                float rim:COLOR;
            };
    
            sampler2D _MainTex;
            float4 _RimColor;
            float _SnowPower;
            float _SnowRang;
    
            v2f vert(appdata_base  v)
            {
                v2f o;
    
    
                
                o.uv = v.texcoord;
                
                float3 sn = mul((float3x3)_World2Object, float3(0,1,0));
    
                o.normal = normalize(mul((float3x3)_Object2World,v.normal));
                float diff = saturate(dot(v.normal,sn));
                if( 1-diff<_SnowRang)
                {
                    v.vertex.xyz+=normalize(diff*sn+(1-diff)*v.normal)*_SnowPower;
                }
                
                o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                return o;
            }
    
            fixed4 frag (v2f IN):COLOR
            {
                fixed4  c = tex2D(_MainTex, IN.uv);
                float diff = saturate(dot(float3(0,1,0),IN.normal));
    
                if(1-diff<_SnowRang)
                {
                    float range = (diff/0.8)*(diff/0.8);
                    //c.rgb = _RimColor.rgb*range+c.rgb*(1-range);
                    c.rgb = _RimColor.rgb;
                }
                
                return c;
            }
    
            #pragma vertex vert
            #pragma fragment frag
    
            ENDCG
            }
        } 
        FallBack "Diffuse"
    }
  • 相关阅读:
    LOJ164 高精度除法
    CQOI2013 新Nim游戏 和 BZOJ1299 巧克力棒
    UOJ514 通用测评号 和 CF891E Lust
    CF526F Pudding Monsters 和 CF997E Good Subsegments
    UOJ513 清扫银河
    SNOI2020 水池
    NOI2015 品酒大会 和 SNOI2020 字符串
    SNOI2020 生成树
    BJOI2020 封印
    UOJ523 半前缀计数
  • 原文地址:https://www.cnblogs.com/mrblue/p/7457434.html
Copyright © 2011-2022 走看看