Sign in to follow this  
mishal153

How to bind samplers to texture stages ?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this