XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

Last post 5/30/2008 11:47 AM by PaulB. 5 replies.
  • 5/29/2008 3:01 PM

    Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    Hi all,

    Hope someone can help me with this one! Because of performance, i want to render a reflection map/texture without antialiasing while rendering the whole scene (which draws a plane with the reflectiontexture) to the screen with antialiasing.

    My application, that includes a reflection plane, worked fine without antialiasing. Than I added this code to turn on antialiasing:

    GraphicsDevice.PresentationParameters.MultiSampleType = MultiSampleType.FourSamples;  
     
    GraphicsDevice.RenderState.MultiSampleAntiAlias = true;  
     
    graphics.PreferMultiSampling = true;  
     
    graphics.ApplyChanges();  
     
     

    But now i get message: "The active render target and depth stencil surface must have the same pixel size and multisampling type".

    This is how my reflextion target is declaired:

                 reflectionRenderTarg = new RenderTarget2D(graphics.GraphicsDevice,   
                                graphics.PreferredBackBufferWidth,  
                                graphics.PreferredBackBufferHeight,   
                                1, SurfaceFormat.Color); 

    When i change it to reflectiontarget to multisampling like this:

                reflectionRenderTarg = new RenderTarget2D(graphics.GraphicsDevice,  
                                graphics.PreferredBackBufferWidth,  
                                graphics.PreferredBackBufferHeight,  
                                1, SurfaceFormat.Color, graphics.GraphicsDevice.PresentationParameters.MultiSampleType,   
                                graphics.GraphicsDevice.PresentationParameters.MultiSampleQuality); 

    my application runs to slow!

    Than i tried to draw the reflectiontarget whithout multisampling like this in the draw method:

    graphics.PreferMultiSampling = false;     
    graphics.ApplyChanges();    
     
    //HERE I DRAW REFLECTION TO REFLECTIONTARGET  
     
    graphics.PreferMultiSampling = true;     
    graphics.ApplyChanges();   
     
    // HERE I DRAW WHOLE SCENE INCLUDING THE REFLECTION PLANE THAT USES THE REFLECTION TEXTURE.   
     
     
     

    But now I end up with 2 FPS :-(

    What is an efficient way to draw a reflection low quality (without multisampling antialiasing) and than draw everything to the screen(with multisampling antialisating)?

  • 5/29/2008 3:06 PM In reply to

    Re: Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    You should not call ApplyChanges each frame - that will be terribly slow because it recreates the entire graphics device.

    Your original error meant exactly what it said: "the active render target and depth stencil surface must have the same pixel size and multisampling type". If you set a rendertarget with a different multisampling type to the main backbuffer, you must also set a depth stencil surface that matches that same multisampling type.

    XNA Framework Developer - blog - homepage
  • 5/29/2008 3:28 PM In reply to

    Re: Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    Ok, i get that. But how do i manage that the rendering of the reflection texture is done normally(without antialiasing) and that the render to the screen is antialiased?
  • 5/29/2008 4:21 PM In reply to

    Re: Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    Turn on multisampling when you create your main graphics device.

    Create a rendertarget without multisampling.

    Create a matching depth buffer without multisampling.

    Make sure you always use the correct depth buffer to go with whatever format rendertarget is currently set.

    XNA Framework Developer - blog - homepage
  • 5/29/2008 6:19 PM In reply to

    Re: Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    What Shawn is saying is that "multisampling or not" is decided based on the currently configured render target; it is not a render state per se.

    The "antialiasing" or "multisampling" parameters of the device are only used for creating the initial render target and depth buffer.


    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
  • 5/30/2008 11:47 AM In reply to

    Re: Render a reflection map/texture WITHOUT antialiasing while redering the whole scene on the scene WITH antialiasing

    Thanks for the help! I managed to do the trick. For other forum users, here is my code. I create a custom depthbuffer:

    reflectionDepthStencilBuffer = new DepthStencilBuffer(graphics.GraphicsDevice,  
         graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight,  
         graphics.GraphicsDevice.DepthStencilBuffer.Format,  
         MultiSampleType.None, 0); 

    before drawing to the custom rendertarget(for the texture) i use my custom depthbuffer:

    graphics.GraphicsDevice.DepthStencilBuffer = reflectionDepthStencilBuffer; 

    Then i draw some stuff to the rendertarget and afterwards i tell the graphicsdevice switch back to the standard rendertarget and depthbuffer again.

    graphics.GraphicsDevice.SetRenderTarget(0, null);  
    graphics.GraphicsDevice.DepthStencilBuffer = oldDepthStencilBuffer; 
Page 1 of 1 (6 items) Previous Next