Jump to content

  • Log In with Google      Sign In   
  • Create Account

Koder4Fun

Member Since 21 Jan 2009
Offline Last Active Aug 31 2012 08:18 AM

#4969401 Dynamic Reflections and omnidirectional Shadows approach

Posted by Koder4Fun on 14 August 2012 - 05:05 AM

If you want to make reflection in realtime on moving objects you need cubemaps to gain fast access in pixel shaders, but rendering a scene 6 times for each frame is not reasonable. You can time-slice the work to do.

Keeping in mind a playable frame-rate (like 60 FPS) you can update onlyone cubemap for each frame, after 6 frames (in this case) you have all cubemaps updated with a refresh rate of 1/6 of current FPS. You can see a little "swimming" of reflections but is not so noticeable.


The same for point light shadow mapping. (you need to use cubemap or Dual-Paraboloid Shadow Maps).

This approach can be used also for non-graphics problems to distribute work on the CPU or GPU over time. (for example AI).


#4968983 Independent resolution

Posted by Koder4Fun on 13 August 2012 - 02:46 AM

I've seen the blog and downloaded the source code, that is for XNA 3.0.

If you use XNA 4.0 you must change a line on your spriteBatch.Begin() call like this:
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.None, RasterizerState.CullNone, null, Resolution.getTransformationMatrix());
Note: if you want old stile blocky pixels change SamplerState.LinearClamp to SamplerState.PointClamp.

The small image with a black border is due to the wrong setting of:
Resolution.SetVirtualResolution(1024, 768);
Resolution.SetResolution(1280, 800, false);
the SetResolution() must be always been set to the real size of the window (or real resolution in full-screen):
Resolution.SetVirtualResolution(1024, 768);
Resolution.SetResolution(GraphicsDevice.DisplayMode.Width, GraphicsDevice.DisplayMode.Height, true);

Now you can freely change the SetVirtualResolution() to any resolution you want.

With these corrections the code work properly on XNA 4.0 (I have tested it) and retain correct aspect ratio when drawing with SpriteBatch, without changing any other code.

Has last note if you prefer black border you need to change the _Device.GraphicsDevice.Clear(Color.CornflowerBlue); inside the Resolution.BeginDraw(); (in resolution.cs)

Hope it helped.
If you have questions, please tell me.


PARTNERS