Sign in to follow this  
Capoeirista

Shader sampling from wrong texture? [fixed]

Recommended Posts

Capoeirista    3266

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
Zaoshi Kaba    8434

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
Capoeirista    3266

 

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

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