Jump to content
  • Advertisement
Sign in to follow this  
terry_burns85

Applying a second texture dx9

This topic is 3031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, Having a little trouble getting access to a second texture in a pixel shader in DirectX 9. Ive checked that everything is loaded correctly and is functional. But it seems that any texture i add at stage 1 doesnt get passed through to the pixel shader. Can anyone see any blatant code I've over looked In setting the texture I have:
dxDevice->SetTexture( 0, Texture1);
dxDevice->SetTexture( 1, Texture2);
and to test this my pixel shader looks like this:

sampler2D Texture1; 
sampler2D Texture2; 


struct PS_Input
{
    float2 TexCoord0     : TEXCOORD0;
    float3 WorldPosition : TEXCOORD1; 
    float3 WorldNormal   : TEXCOORD2; 
};

struct PS_Output
{
	float4 Colour : COLOR0;
};


void main( in PS_Input i, out PS_Output o ) 
{
    o.Colour = tex2D( Texture2, i.TexCoord0 );	
}
This still results in Texture1 being applied regardless. Anyone any ideas whats going wrong?

Share this post


Link to post
Share on other sites
Advertisement
Shouldn't you be calling SetTexture on the effect or shader, not the device?

Share this post


Link to post
Share on other sites
Yes you are correct, I was getting confused by the effects interface. Sorry.

Share this post


Link to post
Share on other sites
similar to semantics you can specify the GPU register for a variable to be in, so try

Texture tex0 : register(t0)
Texture tex1 : register(t1)

which specifies that tex0 is in texture register 0 and tex1 is in register 1 so that you aren't relying on the compiler guessing how you want them mapped.

Share this post


Link to post
Share on other sites
"ender_341":s suggestion will work.

The reason why you see the texture bound in the slot 0 (instead of slot 1) is that the shader compiler optimizes out texture variables if you don't use them. Since you don't refer to the first texture in your shader, the compiler doesn't allocate it at all and the second texture variable gets the slot 0. On the other hand, if you force the textures to given registers, the compiler doesn't move them.

You can verify this with fxc, it shows you all the resources that are actually used.

Share this post


Link to post
Share on other sites
I've never used a Texture object, i normally rely on the texture to be passed through the pipeline correctly and use a sampler2D object to return the colour at a specified position. The texture is loaded correctly as if i pass the texture through at stage 0 the texture applied to the model is the other texture.

--edit

Based on the idea that the first texture isnt be used so it gets ommited I altered my shader to look like this:


sampler2D Texture1;
sampler2D Texture2;


struct PS_Input
{
float2 TexCoord0 : TEXCOORD0;
float3 WorldPosition : TEXCOORD1;
float3 WorldNormal : TEXCOORD2;
};

struct PS_Output
{
float4 Colour : COLOR0;
};


void main( in PS_Input i, out PS_Output o )
{
float4 firstColour = tex2D( Texture1, i.TexCoord0 );
o.Colour = tex2D( Texture2, i.TexCoord0 );
}



even now though it is being referenced the shader still ignores the second texture. Any other suggestions?

[Edited by - terry_burns85 on March 28, 2010 3:20:17 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!