欢迎光临散文网 会员登陆 & 注册

自用代码2

2023-02-25 14:34 作者:梦夏萤火虫  | 我要投稿

Shader "Custom/myShader10" //shader名称 摆放位置 {   //在这里添加自定义的变量,即shader的外部输入变量 Properties { //ProPerties中的变量都可以在脚本代码中动态访问及修改 //_变量名(“Inspector中的提示名字”,类型) = “默认值”{} _MainColor("Main Color",Color) = (1.0,1.0,1.0,1.0) _MainTex("Base (RGB)",2D) = "White"{} _Bump("Bump",2D) = "bump"{} _Snow("Level of snow",Range(-1,1)) = 0 _SnowColor("Color of snow",Color) = (1.0,1.0,1.0,1.0) _SnowDirection("Direction of snow",Vector) = (0,1,0) _SnowDepth("Depth of snow",Range(0,0.1)) = 0    } SubShader { Tags { "RenderType"="Opaque" } //说明性标签 LOD 200   CGPROGRAM //#pragma surface surf Lambert vertex:vert #pragma surface surf Standard vertex:vert   sampler2D _MainTex; sampler2D _Bump; float _Snow; float4 _SnowColor; float4 _MainColor; float4 _SnowDirection; float _SnowDepth;   struct Input{  float2 uv_MainTex;  float2 uv_Bump;  float3 worldNormal;  INTERNAL_DATA };     //定点函数(Vertex) void vert(inout appdata_full v) {    float4 sn = mul(transpose(unity_ObjectToWorld),_SnowDirection);//转化成物理坐标    if (dot(v.normal, sn.xyz) >= _Snow) {    //if (dot(v.normal, sn.xyz) >= lerp(1, -1, (_Snow * 2) / 3)) {   v.vertex.xyz += (sn.xyz + v.normal) * _SnowDepth * abs(_Snow);    }     }   //面元函数(Fragment) //面元函数的输出,一定是fixed4(定常浮点数)表示本物体在屏幕上的显示颜色 void surf(Input IN, inout SurfaceOutputStandard o){  half4 c = tex2D(_MainTex,IN.uv_MainTex);  o.Normal = UnpackNormal(tex2D(_Bump,IN.uv_Bump));  //转化为世界坐标系,实现向上的面,有积雪效果  if (dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz) >= _Snow) {  //if (dot(WorldNormalVector(IN, o.Normal), _SnowDirection.xyz) >= lerp(1, -1, _Snow)) {   o.Albedo = _SnowColor.rgb;    }    else {   o.Albedo = c.rgb * _MainColor;    }    //shader将向上的面处理为白色    //o.Albedo = 1; } ENDCG } }

自用代码2的评论 (共 条)

分享到微博请遵守国家法律