Unity3d中用vertex program和fragment program写的3d模型UV测试shader
此代码为vertex shader 和 fragment shader的一个简单示例。
Shader "test/dexter1"
{
Properties
{
_number("Section Number", Range(2,30)) = 10
}
SubShader
{
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform float _number;
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos: SV_POSITION;
fixed4 color: COLOR;
float4 uv: TEXCOORD0;
};
v2f vert(appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = fixed4(v.normal * 0.5 + 0.5,1);
o.uv = v.texcoord;
return o;
}
float4 frag(v2f i):COLOR
{
float4 co;
if(fmod(i.uv.x, 1/_number) < 0.002 || fmod(i.uv.y,1/_number) < 0.002)
{
co = float4(i.uv.x * 0.6 , i.uv.x * 0.6 , i.uv.x *0.6 , 1);
}
else
{
co = i.color;
}
return co;
}
ENDCG
}
}
}
浙公网安备 33010602011771号