Jump to content

  • Log In with Google      Sign In   
  • Create Account


Shader sampling from wrong texture? [fixed]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Orangeatang   Members   -  Reputation: 1383

Like
0Likes
Like

Posted 12 July 2013 - 08:58 AM

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, 12 July 2013 - 09:51 AM.


Sponsor:

#2 Orangeatang   Members   -  Reputation: 1383

Like
0Likes
Like

Posted 12 July 2013 - 09:21 AM

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?



#3 Zaoshi Kaba   Crossbones+   -  Reputation: 3379

Like
1Likes
Like

Posted 12 July 2013 - 09:34 AM

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);


#4 Orangeatang   Members   -  Reputation: 1383

Like
0Likes
Like

Posted 12 July 2013 - 09:40 AM

 

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 :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS