Sign in to follow this  

[DX10] Skybox

This topic is 3630 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.
D3D10_TEXTURE2D_DESC dstex;
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;
dstex.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
V( d3d10device->CreateTexture2D( &dstex, NULL, &envMapDepthStencil ));
	
// B) Create the depth stencil view for the entire cube
D3D10_DEPTH_STENCIL_VIEW_DESC DescDS;
DescDS.Format = DXGI_FORMAT_D32_FLOAT;
DescDS.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
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.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
dstex.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS | D3D10_RESOURCE_MISC_TEXTURECUBE;
dstex.MipLevels = MIPLEVELS;
V(d3d10device->CreateTexture2D(&dstex, NULL, &envMap));

D3D10_RENDER_TARGET_VIEW_DESC DescRT;
DescRT.Format = dstex.Format;
DescRT.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
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[i] ));
}
	
// Create the shader resource view for the cubic env map
D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc;
ZeroMemory(&SRVDesc, sizeof(SRVDesc));
SRVDesc.Format = dstex.Format;
SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
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++) {
   skyBoxFaceTextureSC->SetResource(envMapShaderView);
   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
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

This topic is 3630 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.

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

Sign in to follow this