Jump to content
  • Advertisement
mark_braga

DX12 Casting a cubemap to be used as 6 separate 2d texture srvs

Recommended Posts

I was wondering if it is possible to use individual faces of cubemap for creating 2D srvs. So the underlying ID3D12Resource will be the cubemap but we can also access it as 6 separate 2d textures in shader code.

ID3D12Resource* pCubeMap = createCubeMap();

SRV cubeMapFace1 = {};

cubeMapFace1.dimension = 2D;
cubeMapFace1.xxx = 0; // This will be the face index (is this the plane slice field in D3D12_TEX2D_SRV? How does it map to Vulkan since there is no plane slice in VkImageViewCreateInfo)

// Plan is to create an srv for only the first face of the cubemap and use it as a normal 2D texture in shader code
createSRV(pCubeMap, &cubeMapFace1);

Thank you

Edited by mark_braga

Share this post


Link to post
Share on other sites
Advertisement

Have a look at https://github.com/NightCreature/SpaceSim/blob/master/SpaceSim/Graphics/RenderSystem.cpp and function initialiseCubemapRendererAndResources.

This initialises a cubemaps and SRVs and RTVs for use in a cubemap renderer, were the target and resource are cubemaps but are rendered to as single target RTs. This is D3D11 but I have a feeling this will extend into D3D12 too.

Edited by NightCreature83

Share this post


Link to post
Share on other sites

I just wanted to confirm that it's basically the same in D3D12 as it is in D3D11: you just need to specify which array slice the SRV will read from by filling out the "Texture2DArray.FirstArraySlice" and Texture2DArray.ArraySize" members of the D3D12_SHADER_RESOURCE_VIEW_DESC structure. You can also do this to make a view into a sub-array if you want, or to make a view that only sees a subset of the mip levels.

Share this post


Link to post
Share on other sites

Thanks for posting these links. They have given a lot of insight.

So just to confirm if I want to create a 2D view of face 3 of a cubemap, will the code look something like this?

SRV_DESC desc = {};
desc.dimension = TEXTURE_2D_ARRAY;
desc.tex2DArray.firstArraySlice = 3; // Face 3 in the cubemap
desc.tex2DArray.arraySize = 1;       // Only need one face
addSRV(pCubeMapResource, &desc);

Thank you

Share this post


Link to post
Share on other sites
5 minutes ago, mark_braga said:

Thanks for posting these links. They have given a lot of insight.

So just to confirm if I want to create a 2D view of face 3 of a cubemap, will the code look something like this?


SRV_DESC desc = {};
desc.dimension = TEXTURE_2D_ARRAY;
desc.tex2DArray.firstArraySlice = 3; // Face 3 in the cubemap
desc.tex2DArray.arraySize = 1;       // Only need one face
addSRV(pCubeMapResource, &desc);

Thank you

Use index 2 because in computer science we start counting at 0. Also rememeber that the faces are in the cubemap as you render into them so if you have face 0 be positive Z axis that is the image you will get back

Edited by NightCreature83

Share this post


Link to post
Share on other sites

My local transforms look in the direction of the positive  z-axis. The y-axis points up and the x-axis points to the left. This results in the following transformation matrices and indices for each of the six planes of the cube map.

static const XMMATRIX rotations[6] = {
    XMMatrixRotationY(-XM_PIDIV2), // Look: +x Index: 0
    XMMatrixRotationY( XM_PIDIV2), // Look: -x Index: 1
    XMMatrixRotationX( XM_PIDIV2), // Look: +y Index: 2
    XMMatrixRotationX(-XM_PIDIV2), // Look: -y Index: 3
    XMMatrixIdentity(),            // Look: +z Index: 4
    XMMatrixRotationY(XM_PI),      // Look: -z Index: 5
 };

 

Edited by matt77hias

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 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!