纳金网
标题:
混合顶点色和贴图的shader
[打印本页]
作者:
会飞的鱼
时间:
2012-6-26 14:59
标题:
混合顶点色和贴图的shader
代码:
Shader " Vertex Color 2" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
BindChannels {
Bind "Vertex", vertex
Bind "texcoord", texcoord
Bind "Color", color
}
Pass {
Tags {"LightMode" = "Vertex"}
Color [_PPLAmbient]
SetTexture [_MainTex] {constantColor [_Color] combine texture * primary, texture * constant }
}
}
FallBack "Diffuse", 1
}有时候需要在上面显示阴影,就需要换一种方法了
复制内容到剪贴板代码:
Shader "Diffuse Vectex Color" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
//Category {
// Blend AppSrcAdd AppDstAdd
// Fog { Color [_AddFog] }
SubShader {
// Pixel lights
Pass {
Name "
PL"
Tags { "LightMode" = "
ixel" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
s***ct appdata {
float4 vertex: POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 color : COLOR;
};
s***ct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
float2 uv;
float3 normal : NORMAL;
float3 lightDir;
float4 color : COLOR;
};
uniform float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.normal = v.normal;
o.lightDir = ObjSpaceLightDir( v.vertex );
o.color = v.color;
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
uniform sampler2D _MainTex;
float4 frag (v2f i) : COLOR
{
// The eternal tradeoff: do we normalize the normal?
//float3 normal = normalize(i.normal);
float3 normal = i.normal;
half4 texcol = tex2D( _MainTex, i.uv ) * i.color;
return DiffuseLight( i.lightDir, normal, texcol, LIGHT_ATTENUATION(i) );
}
ENDCG
}
}
// }
FallBack "Diffuse", 1
}
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5