zoukankan      html  css  js  c++  java
  • 根据模型的Height进行颜色的渐变 (Shader相关)

    有个Shader需求:
    1.根据模型的Height进行颜色的渐变
    2.a值读取给定的皮肤Texture
    自己写了个,基本满足:



    //
    Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' Shader "Test/Shader_HeightColorLocalSpace" { Properties { _Color("SourceColor", Color) = (1,0,0,1) _Color2("DestColor2", Color) = (1,1,1,1) _ButtonY("ModelHeight", Range(0.1,1000)) = 1 _Glossiness("Smoothness", Range(0,1)) = 0.5 _Metallic("Metallic", Range(0,1)) = 0.0 _MainTex("MainTex",2D)= "white" {} } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" } Fog { Mode Off } Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Off Pass { ColorMaterial AmbientAndDiffuse SetTexture [_MainTex] { Combine texture * primary } } Pass { Offset 1, 1 Fog { Mode Off } ZWrite On ZTest LEqual Cull Off Lighting Off CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile __ ENABLE_SPLITALPHA #include "UnityCG.cginc" fixed4 _Color; fixed4 _Color2; float _ButtonY; sampler2D _MainTex; struct appdata_t { float4 vertex : POSITION; half4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : POSITION; float2 uv : TEXCOORD1; half4 color : COLOR; }; v2f o; uniform float4 _MainTex_ST; v2f vert (appdata_t v) { o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); o.color = (lerp(_Color, _Color2, o.vertex.y / _ButtonY)); return o; } half4 frag (v2f IN) : COLOR { half4 col; col.rgb = IN.color; fixed4 texcol = tex2D(_MainTex, IN.uv); col.a = texcol.a; // col.a = 1; return col; } ENDCG } } }
    改变自己
  • 相关阅读:
    Android 8.0编译过程
    Ubuntu下映射网络驱动器
    Android 指定调用已安装的某个“相机”App
    sendMessage 与 obtainMessage (sendToTarget)比较
    Linux tee命令
    Android P(9.0) userdebug版本执行adb remount失败
    adb shell get/setprop, setenforce...
    Bluedroid: 蓝牙协议栈源码剖析
    android o logcat read: unexpected EOF!
    Winform 打包 混淆 自动更新
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/15032289.html
Copyright © 2011-2022 走看看