DX11: Simplest way to convert RGBA 2D Texture to SRBA

Started by
3 comments, last by ddlox 3 years, 5 months ago

Hello,

I have a 2D DX11 texture in DXGI_FORMAT_B8G8R8A8_UNORM but I need DXGI_FORMAT_B8G8R8X8_UNORM. What would be the simpliest, quickiest way to convert on the GPU?

I plan to use VS/PS, render texture onto quad rendering into another texture. Do I need to do anything special in the Pixel shader to output SRGB color out of RGBA color?

Cheers!

Advertisement

VytsL said:
…..I need DXGI_FORMAT_B8G8R8X8_UNORM. What would be the simpliest, quickiest way to convert on the GPU?

I'm not sure i fully understand your question here, but just in case:

1/ u can change the format of your texture description like so:
D3D11_TEXTURE2D_DESC texture;
...
texture_desc.format = DXGI_FORMAT_B8G8R8X8_UNORM; //or check the DXGI_FORMAT in the documentation

if that's not what u meant, then, maybe u mean this:

2/ so u want to use ...A8_UNORM here as you were:
D3D11_TEXTURE2D_DESC texture;
...
texture_desc.format = DXGI_FORMAT_B8G8R8A8_UNORM; 

but in your pixel shader when you get texels out you want ...X8_UNORM:
float4 my_pixel_shader(...)
{
  float3 my_texel = my_texture.Sample(my_sampler, my_texture_coord).bgr; // ignore A value
  
  ...
  do sometin with my_texel
  ...
  
  // has to be float4 on return, A==1 but amend as needed if your alpha blending setting is enabled 
  return float4(my_texel.b, ...g, ...r, 1); 
}

VytsL said:
Do I need to do anything special in the Pixel shader to output SRGB color out of RGBA color?

no, d3d supports writing to sRGB gamma textures, so just create a render target with DXGI_FORMAT_B8G8R8X8_UNORM_SRGB (or whatever other SRGB need you have…) and write your colours out to it;

That's it … all the best ?

@undefined Thank you - my question was about PS and it worked! ?

wonderful ?

This topic is closed to new replies.

Advertisement