热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

VertexShader几何变换顶点颜色变换1

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}}
}

























推荐阅读
author-avatar
陈大也也_384
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有