How to bind samplers to texture stages ?
If i declare a sampler in my HLSL pixel shader then how do bind a particular texture stage to that sampler ? Like we initialize uniform variables is there any way to initialize samplers from app code ?
thanks
Mishal
I tried a small experiment. Here's my Pixel shader :
// Pixel shader input structure
struct PS_INPUT
{
float2 Texture : TEXCOORD0;
};
// Pixel shader output structure
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
// Global variables
sampler2D Tex0;
sampler2D Tex1;
PS_OUTPUT ps_main( in PS_INPUT In )
{
PS_OUTPUT Out; //create an output pixel
Out.Color = tex2D(Tex1, In.Texture);
// Out.Color = tex2D(Tex0, In.Texture)
return Out; //return output pixel
}
//------------end of shader----------------
In my app i have 2 different textures. I set one on stage 0 and another in stage 1. But in my shader both Tex0 and Tex1 point to the texture on stage 1 for some reason. How do i use the stage 0 texture ?
// Pixel shader input structure
struct PS_INPUT
{
float2 Texture : TEXCOORD0;
};
// Pixel shader output structure
struct PS_OUTPUT
{
float4 Color : COLOR0;
};
// Global variables
sampler2D Tex0;
sampler2D Tex1;
PS_OUTPUT ps_main( in PS_INPUT In )
{
PS_OUTPUT Out; //create an output pixel
Out.Color = tex2D(Tex1, In.Texture);
// Out.Color = tex2D(Tex0, In.Texture)
return Out; //return output pixel
}
//------------end of shader----------------
In my app i have 2 different textures. I set one on stage 0 and another in stage 1. But in my shader both Tex0 and Tex1 point to the texture on stage 1 for some reason. How do i use the stage 0 texture ?
ok this is extremely stupid. Firstly, i was making a mistake in creating textures...i was using the same pointer to texture(LPDIRECT3DTEXTURE9). Forget it...after rectifying it i see that if there are 2 textures set and the pixel shader is doing:
PS_OUTPUT Out; //create an output pixel
float4 c0 = tex2D(Tex0, In.Texture);
float4 c1 = tex2D(Tex1, In.Texture);
Out.Color = c0*c1;
then both textures are sampled and all goes well. BUT if i do:
Out.Color = c0;
or
Out.Color = c1;
i get same color !!
driver acting over smart ?
PS_OUTPUT Out; //create an output pixel
float4 c0 = tex2D(Tex0, In.Texture);
float4 c1 = tex2D(Tex1, In.Texture);
Out.Color = c0*c1;
then both textures are sampled and all goes well. BUT if i do:
Out.Color = c0;
or
Out.Color = c1;
i get same color !!
driver acting over smart ?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement