Jump to content

  • Log In with Google      Sign In   
  • Create Account


Rendering & Saving Environment Maps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 26 April 2013 - 05:21 AM

I'm trying to render environment maps from my probes and I've read about a technique of using the GS to draw all 6 faces at the same time (?)

I haven't really found any details on how that is done, and if so is it the best way to do that? Or should I just render face after face 6 times ?

Now is there some way to compose this cubemap from my rendertargets or do I have to do that by hand using CubeMapGen from each face ?

And my last question how do I write this rendertarget to my filesystem as a *.DDS file ? Is there an API call or something ?



Sponsor:

#2 ATEFred   Members   -  Reputation: 1002

Like
1Likes
Like

Posted 26 April 2013 - 05:54 AM

Regarding the GS instancing to render to all faces in one pass, there is a nice little sample in the dxsdk showing exactly that.



#3 kauna   Crossbones+   -  Reputation: 2157

Like
0Likes
Like

Posted 26 April 2013 - 06:05 AM

Yes, you may use GS to output a primitive to multiple render targets (the DX SDK example does exactly that). 

 

However, it is perfectly fine to render each cube map side separately too. The performance difference may be negligible since GS is typically a performance hog if used to output lots of primitives. I prefer slightly rendering each side separately since then you don't need separate vertex shaders for rendering cube maps / rendering normally. Since cube map render target gives you 6 rendertargetviews, you can render them separately by just selecting the desired target. 

 

There is a function in D3DX to save dds files (may work with cubemaps), but MSDN suggests using DirectXTK with similar function since D3DX is almost deprecated. 

 

[edit] It seems that DirectXTK won't save cubemaps correctly.

 

Cheers!


Edited by kauna, 26 April 2013 - 06:50 AM.


#4 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 26 April 2013 - 06:58 AM

@kauna So I should use D3DX to do that ?

 

And if I wanted to render dynamic cubemaps what size would be okay to render them (128x128, 256x256, 512x512) ?

Also does it make sense to interleave them over a few frames (i.e. render it only every 5 frames) ? 



#5 kauna   Crossbones+   -  Reputation: 2157

Like
1Likes
Like

Posted 26 April 2013 - 07:35 AM

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476298(v=vs.85).aspx You could try using this function for saving. It may or may not work with cube maps. 

 

The cube map resolution is up to your needs. How many cube maps you are planning to use in every scene? What is the cube map surface format? Are you using HDR rendering? Are you using cube maps for specular reflections? 

 

It is ok to render cubemaps "when needed". It is even possible to only render one side at a time and then swap the cube map when finished rendering. 

However, if you are considering supporting SLI rendering, then there might be some things to know. 

 

Cheers!



#6 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 26 April 2013 - 10:05 AM

So I don't do anything wrong...am I correct in thinking that for deferred rendering I need to create the entire GBuffer RenderTargets for each theoretical cubemap size?

(meaning 64², 128², 256², 512²) ?



#7 CryZe   Members   -  Reputation: 768

Like
1Likes
Like

Posted 27 April 2013 - 04:36 AM

The way it works with the geometry shader, is, that you project each vertex inside the geometry shader onto the different sides and than output the resulting vertices with a SV_RenderTargetArrayIndex semantic which represents which side the projected vertex you are outputting is on.



#8 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 27 April 2013 - 06:17 AM

Well I've managed to get the rendering done (but using 6 passes) now...

How do I combine these 6 RenderTargets to a single CubeMap ShaderResource ?

Is there any way to do that using each RT's ID3D11Texture* ?

 

edit:

I tried something like:

	ID3D11Texture2D* cubeFaces[6];
	for(unsigned int i = 0; i < 6; i++)
	{
		this->faces[i] = new CustomRenderTarget(this->device, DXGI_FORMAT_R8G8B8A8_UNORM, this->size, this->size);
		cubeFaces[i] = this->faces[i]->GetRenderTargetTexture();
	}

	D3D11_SUBRESOURCE_DATA subData;
	subData.pSysMem = cubeFaces;
	subData.SysMemPitch = sizeof(XMFLOAT4) * this->size;

	ID3D11Texture2D* cubeMap = NULL;
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = this->size;
	texDesc.Height = this->size;
	texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	texDesc.MipLevels = 0;
	texDesc.ArraySize = 6;
	texDesc.SampleDesc.Count = 1;
	texDesc.Usage = D3D11_USAGE_DEFAULT;
	texDesc.SampleDesc.Quality = 0;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
	
	HRESULT hr = this->device->CreateTexture2D(&texDesc, &subData, &cubeMap);

 

But I'm getting an error on the last line saying Invalid arguments.


Edited by lipsryme, 27 April 2013 - 07:25 AM.


#9 ATEFred   Members   -  Reputation: 1002

Like
2Likes
Like

Posted 27 April 2013 - 11:13 AM

Well I've managed to get the rendering done (but using 6 passes) now...

How do I combine these 6 RenderTargets to a single CubeMap ShaderResource ?

Is there any way to do that using each RT's ID3D11Texture* ?

 

edit:

I tried something like:

	ID3D11Texture2D* cubeFaces[6];
	for(unsigned int i = 0; i < 6; i++)
	{
		this->faces[i] = new CustomRenderTarget(this->device, DXGI_FORMAT_R8G8B8A8_UNORM, this->size, this->size);
		cubeFaces[i] = this->faces[i]->GetRenderTargetTexture();
	}

	D3D11_SUBRESOURCE_DATA subData;
	subData.pSysMem = cubeFaces;
	subData.SysMemPitch = sizeof(XMFLOAT4) * this->size;

	ID3D11Texture2D* cubeMap = NULL;
	D3D11_TEXTURE2D_DESC texDesc;
	texDesc.Width = this->size;
	texDesc.Height = this->size;
	texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	texDesc.MipLevels = 0;
	texDesc.ArraySize = 6;
	texDesc.SampleDesc.Count = 1;
	texDesc.Usage = D3D11_USAGE_DEFAULT;
	texDesc.SampleDesc.Quality = 0;
	texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	texDesc.CPUAccessFlags = 0;
	texDesc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
	
	HRESULT hr = this->device->CreateTexture2D(&texDesc, &subData, &cubeMap);

 

But I'm getting an error on the last line saying Invalid arguments.

 

 

It's all in the sample I mentioned in the first answer in the dxsdk, you should really take a look at it.

You create a texture with 6 slices, and the correct flags.

You create one shader resource view

you create 6 rendertarget views if you want to do the 6 passes manually, each referencing a specific slice. Job done



#10 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 27 April 2013 - 11:48 AM

Oh I see, sorry I thought it was just a sample about doing the GS "thing" ;)

I'll have a look asap rolleyes.gif

 

Update: Got it working now !

@kauna D3DX11SaveTextureToFile() works brilliantly.

 

My cube maps appear rather dark since I'm not rendering to my backbuffer (which is R8G8B8A8_SRGB).

Is there anything I need to know for gamma correct rendering ? Or rendering them to an FP16 format ?

 

Also my cubemap seems to reflect the opposite side of what's there. (basically like I can look through)

Not sure why that is...

I've defined my RT's in the order of X+, X-, Y+, Y-, Z+, Z-.

And here's my shader:


float4 PS(VSO input) : SV_TARGET
{
	float3 Normal_WS = normalize(input.NormalWS);
	float3 View_WS = normalize(input.CamPosWS.xyz - input.PosWS.xyz);
	float3 R = reflect(Normal_WS, View_WS);

	float3 reflectionColor = EnvironmentMap.SampleLevel(LinearSampler, R, 0).xyz;

	return float4(reflectionColor, 1.0f);
}


Edited by lipsryme, 27 April 2013 - 03:52 PM.


#11 Jason Z   Crossbones+   -  Reputation: 4690

Like
2Likes
Like

Posted 29 April 2013 - 07:09 PM

In case you are interested in more details about how the technique works, you can take a look here.  There is descriptions for sphere mapping, cube mapping, and dual paraboloid mapping too, all of them as single pass techniques.



#12 lipsryme   Members   -  Reputation: 985

Like
0Likes
Like

Posted 30 April 2013 - 12:22 AM

I've managed to fix my problems so far. Great info on that link though.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS