Jump to content

  • Log In with Google      Sign In   
  • Create Account

DXGI_FORMAT_R8_UNORM for luminance gives me only 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
8 replies to this topic

#1 Juan Camilo Acosta Arango   Members   -  Reputation: 152

Like
0Likes
Like

Posted 18 January 2013 - 01:29 PM

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


Sponsor:

#2 MJP   Moderators   -  Reputation: 11347

Like
0Likes
Like

Posted 18 January 2013 - 01:31 PM

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.



#3 Juan Camilo Acosta Arango   Members   -  Reputation: 152

Like
0Likes
Like

Posted 18 January 2013 - 01:39 PM

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


#4 L. Spiro   Crossbones+   -  Reputation: 13581

Like
0Likes
Like

Posted 18 January 2013 - 03:53 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#5 Juan Camilo Acosta Arango   Members   -  Reputation: 152

Like
0Likes
Like

Posted 18 January 2013 - 09:06 PM

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


#6 Mike.Popoloski   Crossbones+   -  Reputation: 2911

Like
0Likes
Like

Posted 18 January 2013 - 10:27 PM

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

#7 Juan Camilo Acosta Arango   Members   -  Reputation: 152

Like
0Likes
Like

Posted 19 January 2013 - 01:25 AM

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


#8 L. Spiro   Crossbones+   -  Reputation: 13581

Like
0Likes
Like

Posted 19 January 2013 - 02:45 AM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 kubera   Members   -  Reputation: 917

Like
0Likes
Like

Posted 19 January 2013 - 05:14 AM

The bottom of blog would be interesting (comments):

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






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