Single Pass!!!

Daily 09/25/03

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

8,539 views 5 replies
Reply #1 Top
Very cool...I don't pretend to understand a lot of what you're up to here code wise but I was curious how you're specifying where the glow effect for the lights occur. What I thought was going on was the the alpha channel telling where to place the color transform in which case you would need another map to tell the glow goes...or maybe the information is held elsewhere(i.e. in the geometry?)
Reply #2 Top
On hardware, a '24bit texture' doesn't exist, it's really a 32 bit texture. (multiples of 3 are bad in HW)

Also, 8-bit textures are basically un-hardware friendly nowadays, I recommend using DXT1, which is an effective 4-bits per pixel. DXTn is also tiled which is texture cache friendly.

I designed hardware for 6 years, trust me.

Reply #3 Top
The glow is actually just a light map texture. There isn't anything in the geometry telling me where to put lights. That's not to say that we won't do that anyways. Running lights for instance are best done as point sprites and for those, I'd need reference points on the geometry.
Reply #4 Top
Thanks for the input. We'll definately use this information. DXT1 may be a little constraining for us though. The 1 bit alpha doesn't lend well to glow falloff. But I guess I could always just use black instead of an alpha and do an ADD op instead of a MODULATE. We'll experiment with that.