Jump to content
  • Advertisement
Sign in to follow this  
ja0335

DX11 DXGI_FORMAT_R8_UNORM for luminance gives me only red channel

This topic is 2075 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...
I am trying to load a texture with the DXGI_FORMAT_R8_UNORM to obtain its luminance version(grayScale), in D3D9 i was used D3DFMT_L8 and the result is okay but in D3D11 i only obtain the red channel, what i am doing wrong?
 
Rendered Color image: 
good.png
 
Render with DXGI_FORMAT_R8_UNORM(bad!!): 
DXGI_FORMAT_R8_UNORM.png
 
 
here is the code:
 

	D3DX11_IMAGE_INFO* pImgInfo = 0;
	HRESULT imghr = D3DX11GetImageInfoFromFile( L"Tiles.png", NULL, pImgInfo, NULL);
	
	D3DX11_IMAGE_LOAD_INFO imgLoadInfo;
		imgLoadInfo.Width = D3DX11_DEFAULT;
		imgLoadInfo.Height = D3DX11_DEFAULT;
		imgLoadInfo.Depth = D3DX11_DEFAULT;
		imgLoadInfo.FirstMipLevel = D3DX11_DEFAULT;
		imgLoadInfo.MipLevels = D3DX11_DEFAULT;
		imgLoadInfo.Usage = D3D11_USAGE_DEFAULT;
		imgLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
		imgLoadInfo.CpuAccessFlags = 0;
		imgLoadInfo.MiscFlags = 0;
		imgLoadInfo.Format = DXGI_FORMAT_R8_UNORM;
		//imgLoadInfo.Format = DXGI_FORMAT_R16G16B16A16_UNORM;
		imgLoadInfo.Filter = D3DX11_FILTER_NONE;
		imgLoadInfo.MipFilter = D3DX11_DEFAULT;
		imgLoadInfo.pSrcInfo = pImgInfo;


	m_Texture = m_pRenderer11->LoadTexture( L"Tiles.png", &imgLoadInfo  );

Share this post


Link to post
Share on other sites
Advertisement

R8_UNORM means you have a texture with just a red channel. If you load an RGB texture with that format, you will only get the red channel from that texture. If you want a texture containing the luminance of the RGB values, you'll need to do that yourself.

Share this post


Link to post
Share on other sites
R8_UNORM means you have a texture with just a red channel. If you load an RGB texture with that format, you will only get the red channel from that texture. If you want a texture containing the luminance of the RGB values, you'll need to do that yourself.

 

Is there no a way like in D3D9 with the format  D3DFMT_L8? when i used these forma to load a texture it visually return a gray scale version

Share this post


Link to post
Share on other sites

Use the R value from your DXGI_FORMAT_R8_UNORM texture for all channels of the returned color except for A, which should be set to 1.0f.

 

 

L. Spiro

Share this post


Link to post
Share on other sites
Use the R value from your DXGI_FORMAT_R8_UNORM texture for all channels of the returned color except for A, which should be set to 1.0f.

 

 

L. Spiro

 

i'm so sorry L.Spiro, i'm a beginner in d3d11, may you be more specific? When i call LoadTexture how can i set the channels as you said?

Share this post


Link to post
Share on other sites

Ok thanks for your help...

 

Now i have errors with the texture sampler, it is only happening with the R8_unorm format.

 

Here is the result: 

bad_sampling.png

 

And here is the source image:

woman.jpg

 

this is the pixel shader:

// Pixel Shader
float4 main_ps( v2p input ) : SV_TARGET
{
	float4 l_color0;
	l_color0 = g_frostTexture.Sample(SampleType, input.texCoord);
	l_color1 = float4( l_color1.rrr, 1.0f);
	returnl_color1;
}

 

thanks in advance....

Share this post


Link to post
Share on other sites

I don’t use Ogre but the error seems apparent: The image is now 4 times as wide and the RGB channels are all the same (so every 3 pixels are grey) and the A channel is white (so every 4th pixel is white).

 

In other words, something is expecting 1 result but is being fed 4.  For whatever reason it is actually using all 4 results and treating them as separate results.  Instead of combining the RGBA values into one pixel, it is spreading them out over 4 pixels.

 

That is basically the problem, but I have never seen this and I am not familiar with Ogre, so I can’t tell you where to look.  The first things I would check would be the texture-creation values and the render-target creation values.

 

 

L. Spiro

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!