So far all I've got is a map loader and emulating the 256 color palette using pixel shaders. The textures are in A8L8 format to save space, plus I need the alpha channel since Doom uses all 256 colors, the palette index is stored in the L byte.
No shader:
With shader:
This is the shader I'm using for now:
float LightLevel = 1.0f;float4x4 WorldViewProj : WORLDVIEWPROJ;Texture ColorTexture;sampler ColorTextureSampler = sampler_state { texture = ; magfilter = NONE; minfilter = NONE; mipfilter = NONE; AddressU = wrap; AddressV = wrap; };Texture PaletteTexture;sampler PaletteTextureSampler = sampler_state { texture = ; magfilter = NONE; minfilter = NONE; mipfilter = NONE; AddressU = wrap; AddressV = wrap; };struct a2v{ float4 Position : POSITION0; float2 TexCoords : TEXCOORD0;};struct v2p{ float4 Position : POSITION0; float2 TexCoords : TEXCOORD0;};struct p2f{ float4 Color : COLOR0;};void vs( in a2v IN, out v2p OUT ){ OUT.Position = mul( IN.Position, WorldViewProj ); OUT.TexCoords = IN.TexCoords;}void ps( in v2p IN, out p2f OUT ){ float4 TextureColor = tex2D( ColorTextureSampler, IN.TexCoords ); OUT.Color = tex1D( PaletteTextureSampler, TextureColor.r ); OUT.Color *= LightLevel; OUT.Color.a = TextureColor.a;}technique PaletteTechnique{ pass p0 { vertexshader = compile vs_1_1 vs(); pixelshader = compile ps_1_4 ps(); }}
One "problem" is that I never actually set ColorTexture and yet it seems to work. I'm just using Device.SetTexture. Can anyone explain this? My guess is it's undefined behaviour and I'm lucky it doesn't crash and explode.