2008-01-05 18:11:29 +00:00
|
|
|
// 3D world rendering shader
|
|
|
|
// Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
|
|
|
|
// Vertex input data
|
|
|
|
struct VertexData
|
|
|
|
{
|
|
|
|
float3 pos : POSITION;
|
|
|
|
float4 color : COLOR0;
|
|
|
|
float2 uv : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Pixel input data
|
|
|
|
struct PixelData
|
|
|
|
{
|
|
|
|
float4 pos : POSITION;
|
|
|
|
float4 color : COLOR0;
|
|
|
|
float2 uv : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
2008-12-14 23:24:40 +00:00
|
|
|
// Modulation color
|
|
|
|
float4 modulatecolor;
|
|
|
|
|
2009-04-15 22:16:30 +00:00
|
|
|
// Highlight color
|
|
|
|
float4 highlightcolor;
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Matrix for final transformation
|
|
|
|
float4x4 worldviewproj;
|
|
|
|
|
|
|
|
// Texture input
|
|
|
|
texture texture1;
|
|
|
|
|
2008-11-17 00:41:52 +00:00
|
|
|
// Filter settings
|
|
|
|
dword minfiltersettings;
|
|
|
|
dword magfiltersettings;
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Texture sampler settings
|
|
|
|
sampler2D texturesamp = sampler_state
|
|
|
|
{
|
|
|
|
Texture = <texture1>;
|
2008-11-17 00:41:52 +00:00
|
|
|
MagFilter = magfiltersettings;
|
|
|
|
MinFilter = minfiltersettings;
|
|
|
|
MipFilter = magfiltersettings;
|
2008-01-05 18:11:29 +00:00
|
|
|
AddressU = Wrap;
|
|
|
|
AddressV = Wrap;
|
2008-05-26 06:54:32 +00:00
|
|
|
MipMapLodBias = 0.0f;
|
2008-05-23 09:54:51 +00:00
|
|
|
};
|
2008-01-05 18:11:29 +00:00
|
|
|
|
|
|
|
// Vertex shader
|
|
|
|
PixelData vs_main(VertexData vd)
|
|
|
|
{
|
|
|
|
PixelData pd;
|
|
|
|
|
|
|
|
// Fill pixel data input
|
|
|
|
pd.pos = mul(float4(vd.pos, 1.0f), worldviewproj);
|
|
|
|
pd.color = vd.color;
|
|
|
|
pd.uv = vd.uv;
|
|
|
|
|
|
|
|
// Return result
|
|
|
|
return pd;
|
|
|
|
}
|
|
|
|
|
2009-01-04 11:59:24 +00:00
|
|
|
// Normal pixel shader
|
2008-01-05 18:11:29 +00:00
|
|
|
float4 ps_main(PixelData pd) : COLOR
|
|
|
|
{
|
|
|
|
float4 tcolor = tex2D(texturesamp, pd.uv);
|
|
|
|
|
2009-01-04 11:59:24 +00:00
|
|
|
// Blend texture color, vertex color and modulation color
|
2008-12-14 23:24:40 +00:00
|
|
|
return tcolor * pd.color * modulatecolor;
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 11:59:24 +00:00
|
|
|
// Full-bright pixel shader
|
|
|
|
float4 ps_fullbright(PixelData pd) : COLOR
|
|
|
|
{
|
|
|
|
float4 tcolor = tex2D(texturesamp, pd.uv);
|
|
|
|
|
|
|
|
// Blend texture color and modulation color
|
|
|
|
return tcolor * modulatecolor;
|
|
|
|
}
|
|
|
|
|
2009-04-15 22:16:30 +00:00
|
|
|
// Normal pixel shader with highlight
|
|
|
|
float4 ps_main_highlight(PixelData pd) : COLOR
|
|
|
|
{
|
|
|
|
float4 tcolor = tex2D(texturesamp, pd.uv);
|
|
|
|
|
|
|
|
// Blend texture color, vertex color and modulation color
|
|
|
|
float4 ncolor = tcolor * pd.color * modulatecolor;
|
|
|
|
float4 hcolor = float4(highlightcolor.rgb, ncolor.a);
|
|
|
|
|
|
|
|
return ncolor + hcolor * highlightcolor.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Full-bright pixel shader with highlight
|
|
|
|
float4 ps_fullbright_highlight(PixelData pd) : COLOR
|
|
|
|
{
|
|
|
|
float4 tcolor = tex2D(texturesamp, pd.uv);
|
|
|
|
|
|
|
|
// Blend texture color and modulation color
|
|
|
|
float4 ncolor = tcolor * modulatecolor;
|
|
|
|
float4 hcolor = float4(highlightcolor.rgb, ncolor.a);
|
|
|
|
|
|
|
|
return ncolor + hcolor * highlightcolor.a;
|
|
|
|
}
|
|
|
|
|
2008-01-05 18:11:29 +00:00
|
|
|
// Technique for shader model 2.0
|
|
|
|
technique SM20
|
|
|
|
{
|
2009-01-04 11:59:24 +00:00
|
|
|
// Normal
|
2008-01-05 18:11:29 +00:00
|
|
|
pass p0
|
|
|
|
{
|
|
|
|
VertexShader = compile vs_2_0 vs_main();
|
|
|
|
PixelShader = compile ps_2_0 ps_main();
|
|
|
|
}
|
2009-01-04 11:59:24 +00:00
|
|
|
|
|
|
|
// Full brightness mode
|
|
|
|
pass p1
|
|
|
|
{
|
|
|
|
VertexShader = compile vs_2_0 vs_main();
|
|
|
|
PixelShader = compile ps_2_0 ps_fullbright();
|
|
|
|
}
|
2009-04-15 22:16:30 +00:00
|
|
|
|
|
|
|
// Normal with highlight
|
|
|
|
pass p2
|
|
|
|
{
|
|
|
|
VertexShader = compile vs_2_0 vs_main();
|
|
|
|
PixelShader = compile ps_2_0 ps_main_highlight();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Full brightness mode with highlight
|
|
|
|
pass p3
|
|
|
|
{
|
|
|
|
VertexShader = compile vs_2_0 vs_main();
|
|
|
|
PixelShader = compile ps_2_0 ps_fullbright_highlight();
|
|
|
|
}
|
2008-01-05 18:11:29 +00:00
|
|
|
}
|