Sign in to follow this  
XVincentX

D3D10 Cubemap rendering

Recommended Posts

Hello. In a scene i need to use a cubemap, and i've got some troubles about it. At first i created a render target array in this way
__forceinline void MakeCubeMap()
{
	ID3D10Texture2D *text;

	D3D10_TEXTURE2D_DESC desc;

	desc.ArraySize = 6;
	desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = 0;
	desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	desc.Usage = D3D10_USAGE_DEFAULT;
	desc.Height = 150;
	desc.Width = 150;
	desc.MiscFlags = D3D10_RESOURCE_MISC_TEXTURECUBE;
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.MipLevels = 1;

	device->CreateTexture2D(&desc,NULL,&text);

	D3D10_RENDER_TARGET_VIEW_DESC dsc;

	dsc.Format = desc.Format;
	dsc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
	dsc.Texture2DArray.ArraySize = desc.ArraySize;
	dsc.Texture2DArray.FirstArraySlice = 0;
	dsc.Texture2DArray.MipSlice = 0;
	
	device->CreateRenderTargetView(text,&dsc,&CubeMapRT);

	D3D10_SHADER_RESOURCE_VIEW_DESC ds;

	ds.Format = desc.Format;
	ds.ViewDimension = D3D10_SRV_DIMENSION_TEXTURECUBE;
	ds.Texture2DArray.ArraySize = dsc.Texture2DArray.ArraySize;
	ds.Texture2DArray.MostDetailedMip = 0;
	ds.Texture2DArray.FirstArraySlice = 0;
	ds.Texture2DArray.MipLevels = 1;

	device->CreateShaderResourceView(text,&ds,&CubeMapSR);

	text->Release();

	desc.Format = DXGI_FORMAT_D32_FLOAT;
	desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;

	device->CreateTexture2D(&desc,NULL,&text);

	D3D10_DEPTH_STENCIL_VIEW_DESC d;

	d.Format = desc.Format;
	d.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
	d.Texture2DArray.ArraySize = 6;
	d.Texture2DArray.FirstArraySlice = 0;
	d.Texture2DArray.MipSlice = 0;

	device->CreateDepthStencilView(text,&d,&CubeMapDS);

	text->Release();
}


Ok and now? I've only to set it as render target and draw on it via geometry shader. I wrote this
__forceinline void CubeMapRendering()
{

	D3D10_VIEWPORT vp;

	vp.Height = vp.Width = 150;
	vp.TopLeftX = vp.TopLeftY = 0;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;

	float color[4] = { 0.0f, 1.0f, 0.0f, 0.0f };

	device->ClearRenderTargetView(CubeMapRT,color);
	device->ClearDepthStencilView(CubeMapDS,D3D10_CLEAR_DEPTH,1.0f,0);

	device->OMSetRenderTargets(1,&CubeMapRT,CubeMapDS);
	device->RSSetViewports(1,&vp);

	shader->GetVariableByIndex(1)->AsMatrix()->SetMatrix((float*)&geometry->Matrix);

	device->IASetInputLayout(geometry->Layout);	
	geometry->Mesh->CommitToDevice();

	for (UINT i = 0; i < geometry->MatNum; i++)
	{
		shader->GetVariableByIndex(7)->AsShaderResource()->SetResource(geometry->Textures[i]);
		shader->GetTechniqueByIndex(0)->GetPassByIndex(2)->Apply(0);
		geometry->Mesh->DrawSubset(i);
	}
//Set the cubemap and restore default values.
	shader->GetVariableByIndex(10)->AsShaderResource()->SetResource(CubeMapSR);

	vp.Height = 600;
	vp.Width = 800;

	device->OMSetRenderTargets(1,&RenderTarget,depthstencil);
	device->RSSetViewports(1,&vp);

}

It's enough? PIX shows me the render target cleared without nothing (it's green). Have i done all? Have i miss something?

Share this post


Link to post
Share on other sites
Well, you don't check any error return codes. Always check the return codes! Your entire program could be failing and crashing down around you and you wouldn't notice a thing.

Besides that, there are many reasons why it might not be drawing. Could be some culling error. Could have failed the depth test. Maybe your shader is wrong or your matrices are off. Since you're already using PIX, you should be able to view the mesh as it passes through the pipeline (you should be able to see where the vertices are post-vs, post-gs, etc).

You can also right click on the render target and view a pixel's history, and use that to determine if the pixel was inadvertently culled or something like that.

Share this post


Link to post
Share on other sites
Yes i should check error but i looked them via PIX and they looks like ok.
Anyway, the error comes from geometry shader as i can see, becouse it's void.
I'm using this simple GS


[maxvertexcount(24)]
void gs_cube(triangle VS_INPUT In[3], inout TriangleStream<PS_CUBE_INPUT> Stream)
{
PS_CUBE_INPUT Out = (PS_CUBE_INPUT)0;

for (int i = 0; i < 6; i++)
{
Out.Index = i;

for(int t = 0; t < 3; t++)
{
Out.Pos = mul(mul(mul(In[t].Pos,WorldMatrix),ViewMatrix[i]),ProjMatrix);
Out.Tex = In[t].Tex;

Stream.Append(Out);
}

Stream.RestartStrip();
}
}





EDIT
It's a matrix guilty.

[Edited by - XVincentX on October 10, 2008 6:55:33 AM]

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

Sign in to follow this