phort99:I found a very different solution than the one I was looking for.
I wound up pulling this off by using a rendertarget with a surface format that allowed alpha transparency. I used spritebatch to draw my color texture twice (for the top and bottom half) on top of the alpha texture, moving down the render target using gameTime, and used GraphicsDevice blend mode settings so that the minimum alpha value would be used. I saved the render target result in a texture and applied that on the model, and voilà, a moving texture with a static alpha channel! Now I just need to sort out some problems with depth buffering because the transparent parts of the object now obscure the rest of the object when they pass in front of it.
Here was my inspiration for the alpha blending stuff:
http://www.gamedev.net/community/forums/topic.asp?topic_id=532775
And I didn't even have to change from using the BasicEffect!
Legalize, I found another link to Chapter 11 of your book in another thread when I was trying to solve this! It wasn't much help to me in this case since it isn't XNA-specific and I was still looking for the specific XNA code for accessing the texture coordinates so i could transform them. Sorry!
You don't want to access your texture coordinates on the CPU side, you want to do this on the GPU side it's much faster (orders of magnitude faster). For that you either have to write your own shader like this
Vertex Shader:
| float4x4 matViewProjection; |
| float time; |
| |
| struct VS_INPUT |
| { |
| float4 Position : POSITION0; |
| float2 Texcoord : TEXCOORD0; |
| }; |
| |
| struct VS_OUTPUT |
| { |
| float4 Position : POSITION0; |
| float2 Texcoord : TEXCOORD0; |
| float2 Texcoord2 : TEXCOORD1; |
| }; |
| |
| VS_OUTPUT vs_main( VS_INPUT Input ) |
| { |
| VS_OUTPUT Output; |
| |
| Output.Position = mul( Input.Position, matViewProjection ); |
| Output.Texcoord = Input.Texcoord; |
Output.Texcoord2 = Input.Texcoord;
Output.Texcoord2.x += time; |
| |
| return( Output ); |
| } |
| |
Pixel Shader:
| sampler2D baseMap; |
| sampler2D staticAlpha; |
| |
| struct PS_INPUT |
| { |
| float2 Texcoord : TEXCOORD0; |
| float2 Texcoord2 : TEXCOORD1; |
| }; |
| |
| float4 ps_main( PS_INPUT Input ) : COLOR0 |
| { |
| return tex2D( baseMap, Input.Texcoord2 ) * tex2D( staticAlpha, Input.Texcoord ).a; |
| |
| } |
The fixed function way of doing it would have been:
D3DXMATRIX16A textureTransform;
//Seeing we are in an update loop with a gameTime variable
D3DXCreateMatrixTranslation(&textureTransform, gameTime, 0.0f, 0.0f);
m_device->SetTransform(D3DST_TEXTURE0, &textureTransform);
//yourColorTexture defined elsewhere
m_device->SetTexture(0, &yourColorTexture );
//yourAlphaTexture defined elsewhere
m_device->SetTexture(1, &yourAlphaTexture );
//Set up blending stuff
...
//Draw polygon
...
results are:
Screen shot 1
Screen shot 2
Seeing that the basic effect doesn't support setting texture matrices you will need to write your own shader most of the time.