作者:陈大也也_384 | 来源:互联网 | 2024-09-29 21:07
1、顶点颜色变换UpgradeNOTE:replacedmul(UNITY_MATRIX_MVP,*)withUnityObjectToClipPos(*)ShaderCusto
1、顶点颜色变换
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "Custom/s_nine" {SubShader{pass {CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"float4x4 mvp;float4x4 rm;float4x4 sm;struct v2f {float4 pos:POSITION;fixed4 color : COLOR;};v2f vert(appdata_base v) {v2f o;float4x4 m = mul(sm, UNITY_MATRIX_MVP);o.pos = mul(m,v.vertex);if (float(v.vertex.x) > 0)o.color = fixed4(1, 0, 0, 1); //显示为红色elseo.color = fixed4(0,0,1,1); //显示为蓝色return o;}fixed4 frag(v2f IN) :COLOR{return IN.color;}ENDCG}}
}
运行结果:中间颜色自动渐变
2、改变某个顶点的颜色值
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "Custom/s_nine" {SubShader{pass {CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"float4x4 mvp;float4x4 rm;float4x4 sm;struct v2f {float4 pos:POSITION;fixed4 color : COLOR;};v2f vert(appdata_base v) {v2f o;float4x4 m = mul(sm, UNITY_MATRIX_MVP);o.pos = mul(m,v.vertex);if (float(v.vertex.x) == 0.5&&v.vertex.y==0.5&&v.vertex.z==0.5)o.color = fixed4(1, 0, 0, 1); //显示为红色elseo.color = fixed4(0,0,1,1); //显示为蓝色return o;}fixed4 frag(v2f IN) :COLOR{return IN.color;}ENDCG}}
}
3、
在不同的位置,颜色不一样
4、加上时间因子后,颜色的变化
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "Custom/s_nine" {SubShader{pass {CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "unitycg.cginc"float4x4 mvp;float4x4 rm;float4x4 sm;struct v2f {float4 pos:POSITION;fixed4 color : COLOR;};v2f vert(appdata_base v) {v2f o;float4x4 m = mul(sm, UNITY_MATRIX_MVP);o.pos = mul(m,v.vertex);if (float(v.vertex.x) == 0.5&&v.vertex.y == 0.5&&v.vertex.z == 0.5)o.color = fixed4(_SinTime.w/2+0.5,_CosTime.w/2+0.5,_SinTime.y/2 + 0.5,1); //显示为红色elseo.color = fixed4(0, 0, 1, 1); //显示为蓝色return o;}fixed4 frag(v2f IN) :COLOR{return IN.color;}ENDCG}}
}