More ship woes and then...the "Ah Ha!" moment.
Have you ever read "Illusions" by Richard Bach? I had one of those moments
this morning. That was the break through moment for my day. I was putting away
my books from yesterday when I decided to open up "Advanced 3D Game
Programming". It opened to Pg.438 and my eyes immediately caught D3DTA_SPECULAR.
Booom!!!
That's the answers to all my problems. That's how you can map to COLOR1 in a
vertex shader. Whoo hoo! Now we're down to one pass!!!! Here's what I mean.
struct Output
{
float4 position : POSITION;
float4 diffuse : COLOR0;
float4 specular : COLOR1; // This is the cool guy
float2 uv0 : TEXCOORD0;
float2 uv2 : TEXCOORD2; // This is for the third stage (light map)
};
Output vs(float4 Position : POSITION,
float3 Normal : NORMAL,
float2 TexCoord :
TEXCOORD0)
{
Output out = (Output)0;
// Light direction (view space)
float3 L = LightDir; // Directional light.
// Position (view space)
float3 P = mul(Position, WorldView);
// Normal (view space)
float3 N = normalize(mul(Normal, (float3x3)WorldView));
out.position = mul(float4(P, 1), Projection);
out.diffuse = max(0, dot(-N, L));
out.specular = DecalColor; // Decal color passed in.
out.uv = TexCoord;
out.uv2 = TexCoord;
return out;
}technique tech0
{
pass0
{
// Decal tinting
Sampler[0] = <BaseSampler>; // Sampler with the
base texture
ColorOp[0] = BlendTextureAlpha;
ColorArg1[0] = Texture;
ColorArg2[0] = Specular; // This is the decal
color!
AlphaOp[0] = Disable;
// Lighting
ColorOp[1] = Modulate;
ColorArg1[1] = Current;
ColorArg2[1] = Diffuse; // This is calculated
diffuse (N, L)
// Light map
Sampler[2] = <LightSampler>;
ColorOp[2] = BlendTextureAlpha;
ColorArg1[2] = Texture;
ColorArg2[2] = Current;
AlphaOp[2] = Disable;
VertexShader = compile vs_1_1 vs();
}
}
|
Wow! I don't think my day can get any better
I got into a discussion with Paul about texture memory usage. Does a 24bit
texture take up roughly the same amount of memory as 3 8bit textures? It seems
right. There may be a little overhead from the texture headers and other
supporting data, but the bits should be roughly equivalent.
The rest of the day was spent in a long meeting. More tasks to do....