Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Texture2D Load only returns red channel


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
5 replies to this topic

#1 trevex   Members   -  Reputation: 125

Like
0Likes
Like

Posted 10 January 2013 - 07:11 AM

I am currently planning to implement a few Post-Process Effects. The first thing I did was rendering into a texture, when I have a look at the
texture in PixWin it looks totally fine.

The texture has the format "DXGI_FORMAT_R8G8B8A8_UNORM".

The next step was to render the texture to the screen, but the output is simply "red" only the red channel is rendered.

 

float4 VSMain(in float3 Position : POSITION) : SV_Position 
{ 
	return float4(Position, 1.0f); 
}

float PSDisabledMain(in float4 screenPos : SV_Position) : SV_Target0 
{ 
	int3 sampleIndices = int3(screenPos.xy, 0);
	float3 color = BackBufferMap.Load(sampleIndices).xyz;
	return color;
}

 

 

I played around with the shader code but nothing seems to fix it. I am new to directx coming from a opengl background and seem to have overseen something.

Thanking you in anticipation,
Nik

P.S. If you need more informations or anything else let me know

EDIT:

My assumption is it has something todo with the texture format but unsure how to fix it...


Edited by trevex, 10 January 2013 - 07:13 AM.


Sponsor:

#2 Zaoshi Kaba   Crossbones+   -  Reputation: 4426

Like
1Likes
Like

Posted 10 January 2013 - 07:54 AM

How did you define BackBufferMap? Please note that Load() gets texels without filtering and it uses integer offset, not UVs (pretty much raw access to memory).
Also you return only float, which is single number, wonder why that code even compiled for you.
If you're simply rendering fullscreen quad it's normally done like this:

SamplerState BackBufferSampler : register(s0);
Texture2D BackBufferMap : register(t0);

float4 PSDisabledMain(in float4 screenPos : SV_POSITION) : SV_TARGET0 {
    return BackBufferMap.Sample(BackBufferSampler, screenPos.xy);
}

Edited by Zaoshi Kaba, 10 January 2013 - 07:56 AM.


#3 mhagain   Crossbones+   -  Reputation: 8136

Like
1Likes
Like

Posted 10 January 2013 - 09:19 AM

I think that Zaoshi Kaba is on the right track here - you're returning a single float from your shader, whereas for colour you would normally return float4 instead; have you checked your shader compiler output for any warnings?

 

Also note the comment about using Load - this may seem fine for simpler effects, but if you're going to be doing anything that distorts or warps the texture, you will definitely be wanting a linear Sample instead.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 trevex   Members   -  Reputation: 125

Like
0Likes
Like

Posted 11 January 2013 - 04:09 AM

I am totally confused right now when I use sample the screen is simply red, but the general problem persists.

 

Why is Load only returning the red value?

 

the color variable always just receives the red value and the rest are underscores in pix...

 

The shader with vertex shader

float4 VSMain(in float3 Position : POSITION) : SV_Position 
{ 
	return float4(Position, 1.0f); 
}

float PSDisabledMain(in float4 screenPos : SV_Position) : SV_Target0 
{ 
	//BackBufferMap.Sample(TexureSampler, screenPos.xy);
	int3 sampleIndices = int3(screenPos.xy, 0);
	float4 color = BackBufferMap.Load(sampleIndices);
	return color;
}

 

 

The vertices used:

 

glm::vec3 vertices[] =
{
	glm::vec3(-1.0f, -1.0f,  0.0f),
	glm::vec3(-1.0f,  1.0f,  0.0f),
	glm::vec3( 1.0f, -1.0f,  0.0f),
	glm::vec3( 1.0f,  1.0f,  0.0f),
};	

 

The vertices and Load function is simply the same I am using in my deferred rendering shaders...

 

And here's how I create the backbuffer:

 


	D3D11_TEXTURE2D_DESC backTextureDesc;
	D3D11_RENDER_TARGET_VIEW_DESC backTargetViewDesc;
	D3D11_SHADER_RESOURCE_VIEW_DESC backResourceViewDesc;


	ZeroMemory(&backTextureDesc, sizeof(backTextureDesc));
	backTextureDesc.Width = width;
	backTextureDesc.Height = height;
	backTextureDesc.MipLevels = 1;
	backTextureDesc.ArraySize = 1;
	backTextureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	backTextureDesc.SampleDesc.Count = 1;
	backTextureDesc.Usage = D3D11_USAGE_DEFAULT;
	backTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
	backTextureDesc.CPUAccessFlags = 0;
	backTextureDesc.MiscFlags = 0;

	HR(m_d3dDevice->CreateTexture2D(&backTextureDesc, NULL, &m_BackTargetTexture));
	
	backTargetViewDesc.Format = backTextureDesc.Format;
	backTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
	backTargetViewDesc.Texture2D.MipSlice = 0;

	HR(m_d3dDevice->CreateRenderTargetView(m_BackTargetTexture, &backTargetViewDesc, &m_BackTargetView));

	backResourceViewDesc.Format = backTextureDesc.Format;
	backResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	backResourceViewDesc.Texture2D.MostDetailedMip = 0;
	backResourceViewDesc.Texture2D.MipLevels = 1;

	HR(m_d3dDevice->CreateShaderResourceView(m_BackTargetTexture, &backResourceViewDesc, &m_BackResourceView));


#5 mhagain   Crossbones+   -  Reputation: 8136

Like
1Likes
Like

Posted 11 January 2013 - 04:11 AM

See this:

float PSDisabledMain

It means that your pixel shader is just returning a single float.  Change that "float" to "float4".


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#6 trevex   Members   -  Reputation: 125

Like
0Likes
Like

Posted 11 January 2013 - 04:13 AM

Oh god can't believe I didn't notice that! Thank you so much!






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