Advertisement

Shader4ComponentMapping explain?

Started by November 23, 2017 07:11 AM
4 comments, last by VietNN 7 years, 2 months ago

Hi all,

The D3D12_SHADER_RESOURCE_VIEW_DESC has a member Shader4ComponentMapping but I don't really know what is it used for? As several example set its value to D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING. I also read the document on MSDN but still do not understand anything about it.

https://msdn.microsoft.com/en-us/library/windows/desktop/dn903814(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/windows/desktop/dn770406(v=vs.85).aspx

Anyone could help me, thank you.

In older API's there were some formats that, when fetched in the shader as a float4 value, you'd get (Red, Red, Red, 1), or (Red, Green, Blue, 1) or (Blue, Green, Red, Alpha), or (Red, Green, 0, 1), etc...

In Dx12, you're given control over this behaviour yourself. If you want the shader's float4 'x' value to contain the data from the texture's green channel, you can do that. If you want to hard-code the alpha result to 0 or 1, you can do that.

Typically though you set it to return (Red, Green, Blue, Alpha) / a.k.a. (component 0, component 1, component 2, component 3) 

Advertisement

Hi Hodgman, thanks for a quick respone,

So you mean in older API, some format like RGB (only 3 channel) will be fetched as RGBA(A=1) in shader ? (or I missunderstood).

One more question, in Dx12 if I send a texture RGB, Do I have to force alpha to 0 or 1 (by setting others flag not using the DEFAULT_MAPPING flag)? or what will happen if I still using default mapping flag?

Thank you

Lemme give you an example: A block compressed format, such as BC5, which only has R+G, will by default return B=0 and A=1 (I hope). You can force 1 or 0 into any channel, you can shuffle channels around, you can use some of them 1-4 times and you can drop any of them or all of them (replacing them by 0 or 1). I can't think of too many uses for this though.

O, thank you pcmaster. :)

This topic is closed to new replies.

Advertisement