Jump to content
  • Advertisement
Sign in to follow this  

[DX10] Skybox

This topic is 3933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, in my application I am trying to dynamically create a skybox and render this skybox. This is the code to create all resources (annotation in the comments):
ID3D10Texture2D* envMap;             // Environment map
ID3D10Texture2D* envMapDepthStencil; // Depth stencil for the environment map
ID3D10RenderTargetView*  envMapRTView[6];        // 6 render target view, each view is used for 1 face of the env map
ID3D10DepthStencilView*  envMapDepthStencilView; // Depth stencil view for environment map. 

ID3D10ShaderResourceView*   envMapShaderView; 
ID3D10ShaderResourceView*   envMapShaderViewSingleFace[6];// Single-face shader resource view

// A) Create cubic depth stencil texture.
dstex.Width = ENVMAPSIZE;
dstex.Height = ENVMAPSIZE;
dstex.MipLevels = 1;
dstex.ArraySize = 6;         // Maybe 1 instead of 6??
dstex.SampleDesc.Count = 1;
dstex.SampleDesc.Quality = 0;
dstex.Format = DXGI_FORMAT_D32_FLOAT;
dstex.Usage = D3D10_USAGE_DEFAULT;
dstex.BindFlags = D3D10_BIND_DEPTH_STENCIL;
dstex.CPUAccessFlags = 0;
V( d3d10device->CreateTexture2D( &dstex, NULL, &envMapDepthStencil ));
// B) Create the depth stencil view for the entire cube
DescDS.Texture2DArray.FirstArraySlice = 0;
DescDS.Texture2DArray.ArraySize = 1;
DescDS.Texture2DArray.MipSlice = 0;
V(d3d10device->CreateDepthStencilView(envMapDepthStencil, &DescDS, &envMapDepthStencilView ));

// C) Create the cube map for env map render target
dstex.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; // Correct Format??
dstex.MipLevels = MIPLEVELS;
V(d3d10device->CreateTexture2D(&dstex, NULL, &envMap));

DescRT.Format = dstex.Format;
DescRT.Texture2DArray.FirstArraySlice = 0;
DescRT.Texture2DArray.ArraySize = 1;
DescRT.Texture2DArray.MipSlice = 0;

// Create render target views. One Rendertarget for each face
for( int i = 0; i < 6; ++i ) {
   DescRT.Texture2DArray.FirstArraySlice = i;
   V( d3d10device->CreateRenderTargetView( envMap, &DescRT, &envMapRTView ));
// Create the shader resource view for the cubic env map
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
SRVDesc.Format = dstex.Format;
SRVDesc.TextureCube.MipLevels = MIPLEVELS;
SRVDesc.TextureCube.MostDetailedMip = 0;
V( d3d10device->CreateShaderResourceView(envMap, &SRVDesc, &envMapShaderView));

So basically I create 2 Textures: One is the cubemap (can I call this Texture a Texture2DArray?) and the other is the DepthStencil Texture. First I create the DepthStencil Texture, then a view onto this Texture. Then I create the environment map Texture and then 6 RenderTargetViews onto this Environment Map Texture. At last I create a ShaderResourceView for the Environment map Texture. My questions: 0) If I create a Texture2D and then a View onto this texture and then I render onto this view, then I change the Texture2D and NOT the view. Is this correct? 1) In A) I create the depth stencil texture with: dstex.ArraySize = 6; But if I render to the faces, I always use the same DepthStencilView. So is 6 correct or should I use 1? 2) On C) I create the env map Texture and use the format: dstex.Format = DXGI_FORMAT_R16G16B16A16_FLOAT; I used this format from the CubeMapGS Sample, but why should I use a float format? And how does this influence my shader? For example if I use the Format DXGI_FORMAT_R32G32B32_UINT, does my pixel shader then has to return an int3? 3) How can I inspect the 6 faces of my cubemap? Im rendering into the array envMapRTView, but I neither cant save this array to a file (I just found D3DX10SaveTextureToFileW, but this saves only the first element from the 6 textures). I needed something like SaveTexture2DArrayToFile(). PIX also doesnt show me the 6 elements of envMap. So how can I check envMap? 4) Biggest question: After update the skybox faces I want to render the skybox. This is how I render the cube:
for(int i=0; i < 6; i++) {
   skyBoxFaceIndexSC->SetFloat( (float)i);
   d3d10device->Draw(4, 4*i);
First I set the View onto the env map and then for every face I pass an Face-Index to the shader and render the face (made of 4 vertices). This is my pixel shader:
Texture2DArray skyBoxTextures;
SamplerState samSkyBoxTexture {
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp; 
float skyBoxFaceIndex;
float4 SkyBox_Render_PS(SKYBOX_VS_OUTPUT input) : SV_Target {
   return skyBoxTextures.Sample(samSkyBoxTexture, float3(input.starTexCoord, skyBoxFaceIndex));

input.starTexCoord are just the 2D texture coordinates of each box vertex and skyBoxFaceIndex is the index passed to the shader (0=Front, 1=back etc.) The problem is: I get the wrong result. The Image is flipped and it looks like I only see 1/4 of the image. What could be the problem? Is it right to use Texture2DArray? Do I sample right? Im really stuck at this problem and would be thankful for any help! Thanks

Share this post

Link to post
Share on other sites
Can really no one answer at least some of these questions? Im really despaired about this now :/

Share this post

Link to post
Share on other sites
You need to be more patient. You need to find someone who actually knows exactly how to help you before you're going to get an answer. 20 minutes isn't generally enough time for someone to stumble upon your questions.

Share this post

Link to post
Share on other sites
Sign in to follow this  

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