• Advertisement


This topic is now archived and is closed to further replies.

HLSL - Multitexturing

This topic is 5137 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 I'm having a weird problem. I have a simple pixelshader that takes 3 textures and blend them together. From the shader I can access all three textures, but #2 and #3 is the same texture as #1 !!!? I think it might be a dx-problem, so here is my code for binding the three textures:
//Set textures

g_pApp->m_pD3DDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
g_pApp->m_pD3DDevice->SetTexture( 0, g_pNormal1Texture );

g_pApp->m_pD3DDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 1);
g_pApp->m_pD3DDevice->SetTexture( 1, g_pNormal2Texture );

g_pApp->m_pD3DDevice->SetTextureStageState(2, D3DTSS_TEXCOORDINDEX, 2);
g_pApp->m_pD3DDevice->SetTexture( 2, g_pDynamicTexture );

//Enable pixel

Is this wrong!? Eventhough the pixelshader tries to take the color from g_pNormal2Texture or g_pDynamicTexture, it would get the colors from g_pNormal1Texture ? The pixelshader-source is as follows:
sampler2D NormalTexture;
sampler2D NormalTexture2;
sampler2D SourceTexture;
float Time;

struct VS_OUTPUT
   float2 t0 : TEXCOORD0;
   float2 t1 : TEXCOORD1;
   float2 t2 : TEXCOORD2;

struct PS_OUTPUT
   vector finalPixelColor : COLOR0;

   PS_OUTPUT output = (PS_OUTPUT)0;

   float4 texColor0 = tex2D(NormalTexture,  In.t0 );
   float4 texColor1 = tex2D(NormalTexture2, In.t1 );
   float4 texColor2 = tex2D(SourceTexture,  In.t2 );

   // Setting finalPixelColor = texColor0, texColor1 or texColor2 makes no difference!!!? <- WEIRD!

   output.finalPixelColor = (texColor0 + texColor1 + texColor2) / 3.0f;

   return output;
Hope you can help me! Best regards Roquqkie [edited by - Roquqkie on February 27, 2004 3:21:57 PM] [edited by - Roquqkie on February 27, 2004 3:27:21 PM]

Share this post

Link to post
Share on other sites
Try to bind the samplers in your pixel shader to specific stages.

sampler2D NormalTexture : register( s0 );
sampler2D NormalTexture2 : register( s1 );
sampler2D SourceTexture : register( s2 );

Also, since you''re not using the fixed function pipeline, your calls to SetTextureStageState to specify the texture coordinates are unnecessary.


Share this post

Link to post
Share on other sites
You have to somehow associate your "sampler2D" objects in the shader with texture stages in your application. One way to do it is to specifify it directly in the shader. I think that another way to do it is inside your application using the constant table, but I don''t remember how exactly right now.

If you were using D3DXEffect, then you could do something like

pEffect->SetTexture("NormalTexture", m_pNormalTexture);

from inside your application. That way, you wouldn''t have to specify which texture stage you were using inside your actual pixel shader.


Share this post

Link to post
Share on other sites

  • Advertisement