• Advertisement
Sign in to follow this  

Shader sampling from wrong texture? [fixed]

This topic is 1654 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 there!

 

I'm working on a deferred rendering system for a game I'm building, and am having trouble with the final lighting shader. I have three render targets that I'm passing in to the shader, but it only seems to be sampling from the first.

 

So my lighting shader is set up like this :

Texture2D ColourMap;
SamplerState ColourSampler
{
	Texture 	= (ColourMap);
	AddressU 	= CLAMP;
	AddressV 	= CLAMP;
	MagFilter 	= LINEAR;
	MinFilter 	= LINEAR;
	MipFilter 	= LINEAR;
};

Texture2D NormalMap;
SamplerState NormalSampler
{
	Texture 	= (NormalMap);
	AddressU	= CLAMP;
	AddressV	= CLAMP;
	MagFilter	= POINT;
	MinFilter	= POINT;
	MipFilter	= POINT;
};

Texture2D DepthMap;
SamplerState DepthSampler
{
	Texture 	= (DepthMap);
	AddressU	= CLAMP;
	AddressV	= CLAMP;
	MagFilter	= POINT;
	MinFilter	= POINT;
	MipFilter	= POINT;
};

...

float4 PS( PixelShaderInput anInput ) : SV_TARGET
{
 // lighting bits and pieces
}

And in my pixel shader, returning a sample from the colour target :

return ColourMap.Sample( ColourSampler, anInput.myTexCoords );

Produces the same out put as :

return NormalMap.Sample( NormalSampler, anInput.myTexCoords );

I've been saving the colour and normal targets to screenshots (.dds format) and can confirm that they're different... in fact now I'm just filling my normal render target up with (1.0f, 0.0f, 0.0f) to be safe.

 

This is how I'm setting my sampler states :

ID3D11ShaderResourceView* shaderResources[] = { myColourTarget->myShaderResource, myNormalTarget->myShaderResource, myDepthTarget->myShaderResource };

shader->SetShaderResources( shaderResources, 3 )

...

SetShaderResources( ID3D11ShaderResourceView** someShaderResources, int aShaderResourceCount )
{
 myDeviceContext->PSSetSHaderResources( 0, aShaderResourceCount, someShaderResources );
}

Anything obvious that I'm not spotting here?

 

Thanks for your help!

Edited by Orangeatang

Share this post


Link to post
Share on other sites
Advertisement

I'm not setting up a SamplerState for each texture I'm passing in to the pixel shader on the code side of things... do I need to if I've defined the state in the pixel shader source?

Share this post


Link to post
Share on other sites

You don't define which texture goes into which register, compiler might've removed unused variables and uses wrong register.

You probably want

Texture2D ColourMap : register(t0);
Texture2D NormalMap : register(t1);
Texture2D DepthMap : register(t2);

Share this post


Link to post
Share on other sites

 

You don't define which texture goes into which register, compiler might've removed unused variables and uses wrong register.

You probably want

Texture2D ColourMap : register(t0);
Texture2D NormalMap : register(t1);
Texture2D DepthMap : register(t2);

 

That sorted it out :) Thanks! 

 

I figured it would map the textures consecutively... guess not :)

Share this post


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

  • Advertisement