Original Post
I'm trying to write a HLSL pixel shader which simply outputs the texture set at stage 1 (set via IDirect3DDevice9::SetTexture(1, texture). The source is as follows: The problem is, it outputs the texture at stage 0. I did some investigation and compiled the HLSL to assembly code, this is what it produces: Whilst what I actually want is: I fiddled around for a while and realised if I used both the textures in the pixel shader, I could access the texture on stage 1; for example if I do:
texture texture0; // texture
texture texture1; // normal map
sampler2D texSampler0 : TEXUNIT0 = sampler_state
{
Texture = <texture0>;
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
sampler2D texSampler1 : TEXUNIT1 = sampler_state
{
Texture = <texture1>;
MIPFILTER = LINEAR;
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
};
struct PS_INPUT
{
float4 Position : POSITION;
float3 Texture : TEXCOORD0;
};
struct PS_OUTPUT
{
float4 color : COLOR0;
};
PS_OUTPUT main( in PS_INPUT In )
{
PS_OUTPUT Out;
Out.color = tex2D(texSampler1, In.Texture);
return Out;
}
ps_2_0
dcl t0.xy
dcl_2d s0
texld r0, t0, s0
mov oC0, r0
ps_2_0
dcl t0.xy
dcl_2d s1
texld r0, t0, s1
mov oC0, r0
Out.color = tex2D(texSampler1, In.Texture) + tex2D(texSampler0, In.Texture) * 0.1;
Then the output is pretty much the second texture. Obviously I don't want to have to do this to my HLSL each time I want to access a particular texture. Is something wrong with my HLSL? Why does it always output the first texture unless I use both textures? Any help appreciated.