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

Started by
6 comments, last by matt77hias 6 years, 4 months ago

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

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.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

An additional D3D11 example using cube map arrays for which an RTV is created for each face:

https://github.com/matt77hias/MAGE/blob/master/MAGE/MAGE/src/rendering/buffer/shadow_map_buffer.cpp

🧙

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.

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

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

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

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

 

🧙

This topic is closed to new replies.

Advertisement