• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lipsryme

Rendering & Saving Environment Maps

11 posts in this topic

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 ?

0

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

@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) ? 

0

Share this post


Link to post
Share on other sites

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!

1

Share this post


Link to post
Share on other sites

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²) ?

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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

2

Share this post


Link to post
Share on other sites

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
0

Share this post


Link to post
Share on other sites

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.

2

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  
Followers 0