Sign in to follow this  
Mastaba

1.1 Pixel Shader Problem

Recommended Posts

I'm trying to do something with a 1.1 pixelshader that seems as though it should be rather straight forward, but unfortunately either I have a bug in the shader or in the app, or perhaps I'm just not correctly understanding the API. What I essentially want to do is create a rotating sub-palette. One or more values may stay the same from frame to frame while others shift by an amount passed to the shader from the program. And I want to do this on PS 1.1 hardware. I already got it working with a very simple 1.4 pixelshader. Here is what I've done to attempt to get it working with a 1.1 pixelshader. I store the palette as a 256x256 A8R8G8B8 texture. Each row contains a rotated version of the 256 color palette (though only the elements that are meant to be rotated are actually rotated). For example, here is a picture of one of the palette textures as captured with D3DSpy. In this one, 255 colors are rotated, the 256th one is one that doesn't shift. Next comes the object texture, which is a fullscreen sized texture which is drawn into pixel by pixel by my program and then uploaded to the video card. Here is just a snippet of it. The object texture, X8R8G8B8 format, is filled in this particular manner, the red channel contains the desired palette index, the green channel is saturated, and the blue channel is zero. Here is the vertex shader I am using in this particular scenario:
vs_1_1

def c0, 1.0,0,0,0
// c1 is set by the app as {0,v,0,0}, where v is a float and 0 <= v <= 1.0 
dcl_position v0
dcl_color0	v1 // not used by the following pixelshader, but it is by others
dcl_color1	v2 // ditto
dcl_texcoord0 v3

mov oPos, v0 // copy over the pretransformed vertex coordinates
mov oT0.xy, v3 // set t0.xy as {s,t} from the vertex texture coordinates
mov oT0.zw, c0.yy // set t0.zw as {0,0}
mov oT1, c0 // set t1 as {1,0,0,0}
mov oT2, c1 // set t2 as {0,v,0,0}
mov oD0, v1 // copy over the diffuse color
mov oD1, v2 // copy over the specular color
And here is the pixelshader I am currently using:
ps_1_1
tex t0 // sample the object texture
texm3x2pad t1, t0 // first row multiplication of 3x2 matrix,  s'=[1 0 0] * [R (G=1) (B=0)]T
texm3x2tex t2, t0 // second row multiplication of 3x2 matrix, t'=[0 v 0] * [R (G=1) (B=0)]T
                  // and sample texture unit 2 at (s', t')
mov r0, t2	// store t2 as the result
And then I draw a simple triangle strip (which works fine). What I thought this pixelshader would do with these textures is sample the palette texture (t2) at (R,V) given R from the red channel of the object texture (t0) and v from the t2 texture coordinates as set by the vertexshader. Unfortunately it does not seem to be working correctly. Every pixel in the output is set as the color of the (0,0) pixel of the palette texture. Can anyone tell if there is an obvious error in my logic so far as the shaders? I can not debug the shaders as I only have MSVC++ 6.0. Which brings up another question, does VC++ Express Beta 2 work with the shader debugger? If it does, I'll try getting it (though with a painfully slow 26.4 Kbps dial-up connection, I will need extreme patience.)

Share this post


Link to post
Share on other sites
Well one thing that may be an issue is that v3 is usually the normal, v7 is texcoordinate zero, so unless you are using a non-default vertex declaration, you may be just passing zero down.

Also, it's strange to set ot0.w to zero. I'd not set it, or set it to 1.0f.

Share this post


Link to post
Share on other sites
The vertex declaration is a custom one and works fine when I simply have the pixel shader sample the object texture with the vertex texture coordinates, and use that as the result, making the object texture appear in the scene. I changed the w component of t0 to 1 but that had no affect. Thanks for the suggestions though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this