• Advertisement
Sign in to follow this  

Environment mapping and performance issue

This topic is 1662 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

I'm trying to create dynamic cube map, having a serious problem with the performance, getting less than 20-25 FPS when I render the scene 6 times to create cube texture for environment mapping.

 

I think I need to render the scene with less resolution when I create the cube texture, not sure how...

 

How do I make the performance back to normal?

Share this post


Link to post
Share on other sites
Advertisement

Do you create the texture with WRITE_ONLY flag in the default pool?

 

Perhaps since your total drawcalls and state changes have increased sevenfold, then you might have hit some limitations.

Share this post


Link to post
Share on other sites

Do you create the texture with WRITE_ONLY flag in the default pool?

 

Shouldn't be relevant unless you're locking it; that would be a theoretical worst-case for performance: render as normal to backbuffer, LockRect it, LockRect a cube face, and memcpy the data over - ouch!!!  (WRITE_ONLY woudn't help here though - it may even make things worse!)

 

Another bad case would be to StretchRect from the backbuffer to each cube face; I don't think that's going to drop to 20fps though.

 

The right way is to create a cubemap with D3DUSAGE_RENDERTARGET in D3DPOOL_DEFAULT, then set each face as a new render target, adjust the viewport to the size of the cubemap and the projection matrix to a 90 degree x and y FOV, clear the depth buffer, and draw the scene to that face.  Do it 6 times, and you have your cubemap.

 

Of course, the 7x overhead in draw calls and state changes would still hurt here (as well as all of those render target switches and depth buffer clears).

Share this post


Link to post
Share on other sites

Can you describe more about the scene you are rendering, and the hardware you are working on?  The bottleneck could be CPU calls due to the scene being rendered several times.  Are there lots of draw calls being issued?

 

If so, can you do some instancing to help reduce the number of calls?  In general, if your cube map size isn't ridiculously large then modern hardware should blow through an environment map with no problems...

Share this post


Link to post
Share on other sites

@Jason Z: No, I don't really need to use instancing, I just have few models in the scene (sky, terrain and around 6-7 other models).

 

GPU: GTX 550 Ti

Share this post


Link to post
Share on other sites

Hmmm, GTX 550 Ti should be fairly powerful for such a simple scene.

 

?You should implement a triangle count. From my experience, there is nothing you can do to a make an under 1 million triangle scene that uses a lot of vertex buffers run like crap and if it does, there is something wrong somewhere else. Either on the CPU side, or you are doing very heavy texture sampling. Or cascaded shadow mapping.

 

But for environmental mapping, you can use a fairly low resolution and very blurred image. You can omit small objects, use cheap filters, omit normal mapping, render meshes with a lower LOD, etc.. You could also recreate the cube map only once in a while, or when some object close to the environmental mapped object changes. You could render one face of a cube a frame, so you have a new cube every 6 frames, reducing you draw calls to 2x. Also, you should have very good batching behavior, but if you only have a few objects, this is probably not your bottleneck.

Share this post


Link to post
Share on other sites

One thing that bothers me with this is that if many things in the scene should reflect stuff and the environment map is created from the camera position, what happens if a character stands between the shiny surface and the map? Should not the character be reflected aswell?

Share this post


Link to post
Share on other sites

Very important question here is what does the game look like. Often environment mapping is just a subtle effect used on some shiny objects and the player almost doesn't pay attention to it. It makes the game look better, but nobody examines the reflection to verify how accurate it is. You can be fine with just few prerendered cubemaps for the scene or if you really need a dynamically updated cubemap then maybe you could be fine without any fancy shaders, without shadows etc. It's mostly about the basic feeling from the scene - the basic colors and shapes of objects in the scene.

 

But I repeat - it depends on the game. Simple reflections are fine for example for cars in racing games, metal parts of weapons in FPS games and so on. Also the shape of the reflective object is important - more complicated shapes are fine with less detailed cube map and vice versa. If you have a perfect reflective sphere in the middle of a room and you can slowly walk around it and examine it then you probably need great reflections to make it believable.

Edited by Tom KQT

Share this post


Link to post
Share on other sites

@Medo3337: What is the size of your environment map?  Have you tried to decrease its resolution?  If you have very few draw calls, and they aren't huge, then it is likely related to how large of a texture you are populating every frame.

 

Can you take a PIX frame grab and post it somewhere so that we can see what you are submitting to the API?

Share this post


Link to post
Share on other sites

@Jason Z: I'm setting the cube texture resolution to 256, reducing the cube map resolution doesn't make any difference in performance.

 

@DwarvesH: I'm getting better performance when I render one cube side each frame instead of 6 per frame, however I'm not sure how can I make the performance even better.

 

How do I render meshes with a lower LOD? I'm using LPD3DXMESH.

Share this post


Link to post
Share on other sites

@belfegor: No, debug mode.

 

I'm getting much better performance in release mode.

 

BTW, I always have performance issues in debug mode...

Edited by Medo3337

Share this post


Link to post
Share on other sites

You cannot make reliable performance analysis in "Debug" mode.

 

Still, you want to listen what others have written especially Tom KQT.

Edited by belfegor

Share this post


Link to post
Share on other sites

You cannot make reliable performance analysis in "Debug" mode.

 

You can if you're profiling GPU-side stuff (but yeah, be certain that it is GPU-side stuff you're profiling before drawing any conclusions).

Share this post


Link to post
Share on other sites

I want to know how do I reduce the meshes LOD?

 

You can't do this automatically. You need your 3D artists to make multiple versions of the same object. Generally two will do. And use the high LOD when close, the low LOD when far. Most simple objects will be able to be rendered with a low LOD mesh that only has a few to a few dozen polygons.

 

Having the object use appropriate normal map and having vertices have similar normals will help making the object pop less when the LOD switch happens. But don't worry about this: try and find one AAA multi-million dollar release where you can't find pop-in when you are looking for it. I can't find one :).

Share this post


Link to post
Share on other sites

Maybe you could try progressive meshes (i didn't tried it so i am not aware of its limitations, if any). For example, since you are using create one from existing ID3DXMesh with D3DXGeneratePMesh function, then you should have ability to switch between LODs.

Share this post


Link to post
Share on other sites

It's probably some simple black&white reflection map. On such complicated shapes you really don't need accurate reflections, so it's common to prepare some abstract cube map (something like this http://www.cgarena.com/freestuff/tutorials/max/chrome/fakereflection2.jpg) and use it. That's enough to make the feeling of a reflective material and it's higly possible that nobody will ever realise that it doesn't really reflect the actual world around it.

In this case it can be a good idea to make the cube map black&white, so that all objects will keep their own color and the reflections will just affect the brightness.

 

But generally and especially for materials without their own distinct colours (red car paint isn't this case while a polished chrome object is) you shouldn't force the reflections to be black&white unless you have a reason for it, because it helps a lot to make the reflections more believable if the object gets a tint of the general colours around it (blue at the top from sky, green at the bottom from grass etc.).

 

If it sounds contradictory or confusing for you, then let me add one more sentence: It all depends on your particular situation, what are you rendering and what will look best for you.

A funny, surprising but absolutely true fact is that sometimes the most realistic and accurate way looks much worse than a fake simple solution, which even is much cheaper. So a fake static reflection map prepared in a picture editor (having abslutely nothing in common with the scene) can sometimes even look better than a dynamicaly updated hi-resolution cube map rendered from the real scene. And rendering speed cannot even be compared smile.png

 

 

Oh and if you really want to make the reflections black&white, then simply either create the cube map BW or make the color BW when you read it in the shader. To make a shades-of-gray color from a color with r, g, b channels, just make the average of the channels:

float4 originalColor = ......;
float gray = (originalColor.r + originalColor.g + originalColor.b) / 3.0f;
float4 bwColor = float4(gray, gray, gray, originalColor.a);
Edited by Tom KQT

Share this post


Link to post
Share on other sites

@Tom KQT: How do I create a cube map texture from just a single image file?

 

I tried using "DirectX Texture Tool" which come with the SDK to create the 6 sides from the same texture, but when I run my game scene I notice that the transformation from cube side to another is not smooth.

Edited by Medo3337

Share this post


Link to post
Share on other sites

No no, that was just an example of how generaly such a reflection map can look like. The picture is just 2D and you cannot easily make a cube map from it. I'm sure someone would be able to do it in Photoshop or something, but I don't know how :)

 

Try to find some cubemaps on the internet, even a simple search for "cubemap" in google pictures returns tons of them. I didn't see any similar to the fake abstract reflection image, but imho many of them could do the same job if you just made them B&W in some picture editor. And then made a real cubemap in the DirectX Texture Tool from the 6 sides.

Share this post


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

  • Advertisement