DXGI_FORMAT_R8_UNORM for luminance gives me only red channel

Started by
7 comments, last by kubera 11 years, 3 months ago

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

Juan Camilo Acosta Arango

Bogotá, Colombia

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.

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

Juan Camilo Acosta Arango

Bogotá, Colombia

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 restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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?

Juan Camilo Acosta Arango

Bogotá, Colombia

As noted in the documentation, you can replicate the D3D9 behavior by using .r to swizzle the data in the shader.

So something like this:

float4 color = float4(textureColor.rrr, 1.0f);

Mike Popoloski | Journal | SlimDX

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....

Juan Camilo Acosta Arango

Bogotá, Colombia

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

The bottom of blog would be interesting (comments):

http://blogs.msdn.com/b/chuckw/archive/2010/07/15/ddswithoutd3dx-sample-update.aspx

This topic is closed to new replies.

Advertisement