private void InitializeFXAACompositor() { CompositorInstance instance = viewport.AddCompositor("FXAA"); if (instance != null) { instance.Enabled = true; } }
private void CreateViewport() { int index = instance.views.IndexOf(this); DestroyViewport(); Vec2I textureSize = GetNeededTextureSize(); string textureName = TextureManager.Instance.GetUniqueName( string.Format("MultiViewRendering{0}", index)); PixelFormat format = PixelFormat.R8G8B8; int fsaa; if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out fsaa)) fsaa = 0; texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize, 1, 0, format, Texture.Usage.RenderTarget, false, fsaa); if (texture == null) { Log.Fatal("MultiViewRenderingManager: Unable to create texture."); return; } RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget(); renderTarget.AutoUpdate = true; renderTarget.AllowAdditionalMRTs = true; //create camera camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName(string.Format("MultiViewRendering{0}", index))); camera.Purpose = Camera.Purposes.MainCamera; //add viewport viewport = renderTarget.AddViewport(camera, 0); viewport.ShadowsEnabled = true; //Create compositor for HDR render technique bool hdrCompositor = RendererWorld.Instance.DefaultViewport.GetCompositorInstance("HDR") != null; if (hdrCompositor) { viewport.AddCompositor("HDR"); viewport.SetCompositorEnabled("HDR", true); } //FXAA antialiasing post effect bool fxaaCompositor = RendererWorld.Instance.DefaultViewport.GetCompositorInstance("FXAA") != null; if (fxaaCompositor) { viewport.AddCompositor("FXAA"); viewport.SetCompositorEnabled("FXAA", true); } //add listener renderTargetListener = new ViewRenderTargetListener(this); renderTarget.AddListener(renderTargetListener); initializedTextureSize = textureSize; }
private bool CreateRenderTarget() { DestroyRenderTarget(); if (RendererWorld.Instance == null) { return(false); } Vec2I textureSize = GetDemandTextureSize(); if (textureSize.X < 1 || textureSize.Y < 1) { return(false); } string textureName = TextureManager.Instance.GetUniqueName("WPFRenderTexture"); int hardwareFSAA = 0; if (!RendererWorld.InitializationOptions.AllowSceneMRTRendering) { if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out hardwareFSAA)) { hardwareFSAA = 0; } } texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize, 1, 0, Engine.Renderer.PixelFormat.R8G8B8, Texture.Usage.RenderTarget, false, hardwareFSAA); if (texture == null) { return(false); } currentTextureSize = textureSize; renderTexture = texture.GetBuffer().GetRenderTarget(); renderTexture.AutoUpdate = false; renderTexture.AllowAdditionalMRTs = true; camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName("UserControl")); camera.Purpose = Camera.Purposes.MainCamera; //update camera settings camera.NearClipDistance = cameraNearFarClipDistance.Minimum; camera.FarClipDistance = cameraNearFarClipDistance.Maximum; camera.AspectRatio = (float)texture.Size.X / (float)texture.Size.Y; camera.FixedUp = cameraFixedUp; camera.Position = cameraPosition; camera.Direction = cameraDirection; camera.Fov = cameraFov; camera.ProjectionType = cameraProjectionType; camera.OrthoWindowHeight = cameraOrthoWindowHeight; viewport = renderTexture.AddViewport(camera); //Initialize HDR compositor for HDR render technique if (EngineApp.RenderTechnique == "HDR") { viewport.AddCompositor("HDR", 0); viewport.SetCompositorEnabled("HDR", true); } //Initialize Fast Approximate Antialiasing (FXAA) { bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering; string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing; if ((useMRT && (fsaa == "" || fsaa == "RecommendedSetting") && IsActivateFXAAByDefault()) || fsaa == "FXAA") { if (RenderSystem.Instance.HasShaderModel3()) { InitializeFXAACompositor(); } } } //add listener renderTargetListener = new ViewRenderTargetListener(this); renderTexture.AddListener(renderTargetListener); if (guiRenderer == null) { guiRenderer = new GuiRenderer(viewport); } else { guiRenderer.ChangeViewport(viewport); } if (controlManager == null) { controlManager = new ScreenControlManager(guiRenderer); } //initialize D3DImage output if (d3dImageIsSupported && allowUsingD3DImage) { // create a D3DImage to host the scene and monitor it for changes in front buffer availability if (d3dImage == null) { d3dImage = new D3DImage(); d3dImage.IsFrontBufferAvailableChanged += D3DImage_IsFrontBufferAvailableChanged; CompositionTarget.Rendering += D3DImage_OnRendering; } // set output to background image Background = new ImageBrush(d3dImage); // set the back buffer using the new scene pointer HardwarePixelBuffer buffer = texture.GetBuffer(0, 0); GetD3D9HardwarePixelBufferData data = new GetD3D9HardwarePixelBufferData(); data.hardwareBuffer = buffer._GetRealObject(); data.outPointer = IntPtr.Zero; unsafe { GetD3D9HardwarePixelBufferData *pData = &data; if (!RenderSystem.Instance.CallCustomMethod("Get D3D9HardwarePixelBuffer getSurface", (IntPtr)pData)) { Log.Fatal("Get D3D9HardwarePixelBuffer getSurface failed."); } } d3dImage.Lock(); d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, data.outPointer); d3dImage.Unlock(); } return(true); }
bool CreateRenderTarget() { DestroyRenderTarget(); if( RendererWorld.Instance == null ) return false; Vec2I textureSize = GetDemandTextureSize(); if( textureSize.X < 1 || textureSize.Y < 1 ) return false; string textureName = TextureManager.Instance.GetUniqueName( "WPFRenderTexture" ); int hardwareFSAA = 0; if( !RendererWorld.InitializationOptions.AllowSceneMRTRendering ) { if( !int.TryParse( RendererWorld.InitializationOptions.FullSceneAntialiasing, out hardwareFSAA ) ) hardwareFSAA = 0; } texture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize, 1, 0, Engine.Renderer.PixelFormat.R8G8B8, Texture.Usage.RenderTarget, false, hardwareFSAA ); if( texture == null ) return false; currentTextureSize = textureSize; renderTexture = texture.GetBuffer().GetRenderTarget(); renderTexture.AutoUpdate = false; renderTexture.AllowAdditionalMRTs = true; camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName( "UserControl" ) ); camera.Purpose = Camera.Purposes.MainCamera; //update camera settings camera.NearClipDistance = cameraNearFarClipDistance.Minimum; camera.FarClipDistance = cameraNearFarClipDistance.Maximum; camera.AspectRatio = (float)texture.Size.X / (float)texture.Size.Y; camera.FixedUp = cameraFixedUp; camera.Position = cameraPosition; camera.Direction = cameraDirection; camera.Fov = cameraFov; camera.ProjectionType = cameraProjectionType; camera.OrthoWindowHeight = cameraOrthoWindowHeight; viewport = renderTexture.AddViewport( camera ); //Initialize HDR compositor for HDR render technique if( EngineApp.RenderTechnique == "HDR" ) { viewport.AddCompositor( "HDR", 0 ); viewport.SetCompositorEnabled( "HDR", true ); } //Initialize Fast Approximate Antialiasing (FXAA) { bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering; string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing; if( ( useMRT && ( fsaa == "" || fsaa == "RecommendedSetting" ) && IsActivateFXAAByDefault() ) || fsaa == "FXAA" ) { if( RenderSystem.Instance.HasShaderModel3() ) InitializeFXAACompositor(); } } //add listener renderTargetListener = new ViewRenderTargetListener( this ); renderTexture.AddListener( renderTargetListener ); if( guiRenderer == null ) guiRenderer = new GuiRenderer( viewport ); else guiRenderer.ChangeViewport( viewport ); if( controlManager == null ) controlManager = new ScreenControlManager( guiRenderer ); //initialize D3DImage output if( d3dImageIsSupported && allowUsingD3DImage ) { // create a D3DImage to host the scene and monitor it for changes in front buffer availability if( d3dImage == null ) { d3dImage = new D3DImage(); d3dImage.IsFrontBufferAvailableChanged += D3DImage_IsFrontBufferAvailableChanged; CompositionTarget.Rendering += D3DImage_OnRendering; } // set output to background image Background = new ImageBrush( d3dImage ); // set the back buffer using the new scene pointer HardwarePixelBuffer buffer = texture.GetBuffer( 0, 0 ); GetD3D9HardwarePixelBufferData data = new GetD3D9HardwarePixelBufferData(); data.hardwareBuffer = buffer._GetRealObject(); data.outPointer = IntPtr.Zero; unsafe { GetD3D9HardwarePixelBufferData* pData = &data; if( !RenderSystem.Instance.CallCustomMethod( "Get D3D9HardwarePixelBuffer getSurface", (IntPtr)pData ) ) Log.Fatal( "Get D3D9HardwarePixelBuffer getSurface failed." ); } d3dImage.Lock(); d3dImage.SetBackBuffer( D3DResourceType.IDirect3DSurface9, data.outPointer ); d3dImage.Unlock(); } return true; }
void CreateViewport() { int index = instance.views.IndexOf(this); DestroyViewport(); Vec2I textureSize = GetNeededTextureSize(); string textureName = TextureManager.Instance.GetUniqueName( string.Format("MultiViewRendering{0}", index)); PixelFormat format = PixelFormat.R8G8B8; int fsaa; if (!int.TryParse(RendererWorld.InitializationOptions.FullSceneAntialiasing, out fsaa)) { fsaa = 0; } texture = TextureManager.Instance.Create(textureName, Texture.Type.Type2D, textureSize, 1, 0, format, Texture.Usage.RenderTarget, false, fsaa); if (texture == null) { Log.Fatal("MultiViewRenderingManager: Unable to create texture."); return; } RenderTarget renderTarget = texture.GetBuffer().GetRenderTarget(); renderTarget.AutoUpdate = true; renderTarget.AllowAdditionalMRTs = true; //create camera camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName(string.Format("MultiViewRendering{0}", index))); camera.Purpose = Camera.Purposes.MainCamera; //add viewport viewport = renderTarget.AddViewport(camera, 0); viewport.ShadowsEnabled = true; //Create compositor for HDR render technique bool hdrCompositor = RendererWorld.Instance.DefaultViewport.GetCompositorInstance("HDR") != null; if (hdrCompositor) { viewport.AddCompositor("HDR"); viewport.SetCompositorEnabled("HDR", true); } //FXAA antialiasing post effect bool fxaaCompositor = RendererWorld.Instance.DefaultViewport.GetCompositorInstance("FXAA") != null; if (fxaaCompositor) { viewport.AddCompositor("FXAA"); viewport.SetCompositorEnabled("FXAA", true); } //add listener renderTargetListener = new ViewRenderTargetListener(this); renderTarget.AddListener(renderTargetListener); initializedTextureSize = textureSize; }
bool CreateRenderTarget() { DestroyRenderTarget(); if (RendererWorld.Instance == null) { return(false); } Vec2I size = new Vec2I(ClientRectangle.Size.Width, ClientRectangle.Size.Height); if (size.X < 1 || size.Y < 1) { return(false); } renderWindow = RendererWorld.Instance.CreateRenderWindow(Handle, size); if (renderWindow == null) { return(false); } renderWindow.AutoUpdate = false; renderWindow.AllowAdditionalMRTs = true; camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName("UserControl")); camera.Purpose = Camera.Purposes.MainCamera; //update camera settings camera.NearClipDistance = cameraNearFarClipDistance.Minimum; camera.FarClipDistance = cameraNearFarClipDistance.Maximum; camera.AspectRatio = (float)renderWindow.Size.X / (float)renderWindow.Size.Y; camera.FixedUp = cameraFixedUp; camera.Position = cameraPosition; camera.Direction = cameraDirection; camera.Fov = cameraFov; camera.ProjectionType = cameraProjectionType; camera.OrthoWindowHeight = cameraOrthoWindowHeight; viewport = renderWindow.AddViewport(camera); //Initialize HDR compositor for HDR render technique if (EngineApp.RenderTechnique == "HDR") { viewport.AddCompositor("HDR", 0); viewport.SetCompositorEnabled("HDR", true); } //Initialize Fast Approximate Antialiasing (FXAA) { bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering; string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing; if ((useMRT && (fsaa == "" || fsaa == "RecommendedSetting") && IsActivateFXAAByDefault()) || fsaa == "FXAA") { if (RenderSystem.Instance.HasShaderModel3()) { InitializeFXAACompositor(); } } } //add listener renderTargetListener = new ViewRenderTargetListener(this); renderWindow.AddListener(renderTargetListener); if (guiRenderer == null) { guiRenderer = new GuiRenderer(viewport); } else { guiRenderer.ChangeViewport(viewport); } if (controlManager == null) { controlManager = new ScreenControlManager(guiRenderer); } return(true); }
void UpdateCurrentPostEffect() { string name = GetListCompositorItemName(listBox.SelectedItem.ToString()); bool enabled = checkBoxEnabled.Checked; CompositorInstance instance = viewport.GetCompositorInstance(name); if (enabled) { //Enable instance = viewport.AddCompositor(name); if (instance != null) { instance.Enabled = true; } } else { //Disable if (name == "MotionBlur") { //MotionBlur game specific. No remove compositor. only disable. if (instance != null) { instance.Enabled = false; } } else { viewport.RemoveCompositor(name); } } if (enabled) { //MotionBlur specific if (name == "MotionBlur") { //Update post effect parameters MotionBlurCompositorInstance.Blur = scrollBarFloatParameters[0].Value; } //Blur specific if (name == "Blur") { //Update post effect parameters BlurCompositorInstance.Fuzziness = scrollBarFloatParameters[0].Value; } //RadialBlur specific if (name == "RadialBlur") { //Update post effect parameters RadialBlurCompositorInstance.BlurFactor = scrollBarFloatParameters[0].Value; } //HDR specific if (name == "HDR") { //Update post effect parameters HDRCompositorInstance.Adaptation = checkBoxBoolParameters[0].Checked; HDRCompositorInstance.AdaptationVelocity = scrollBarFloatParameters[1].Value; HDRCompositorInstance.AdaptationMiddleBrightness = scrollBarFloatParameters[2].Value; HDRCompositorInstance.AdaptationMinimum = scrollBarFloatParameters[3].Value; HDRCompositorInstance.AdaptationMaximum = scrollBarFloatParameters[4].Value; HDRCompositorInstance.BloomBrightThreshold = scrollBarFloatParameters[5].Value; HDRCompositorInstance.BloomScale = scrollBarFloatParameters[6].Value; //Update controls for (int n = 1; n <= 4; n++) { scrollBarFloatParameters[n].Enable = HDRCompositorInstance.Adaptation; } } //LDRBloom specific if (name == "LDRBloom") { //Update post effect parameters LDRBloomCompositorInstance.BloomBrightThreshold = scrollBarFloatParameters[0].Value; LDRBloomCompositorInstance.BloomScale = scrollBarFloatParameters[1].Value; } } }
private bool CreateRenderTarget() { DestroyRenderTarget(); if (RendererWorld.Instance == null) return false; Vec2I size = new Vec2I(ClientRectangle.Size.Width, ClientRectangle.Size.Height); if (size.X < 1 || size.Y < 1) return false; renderWindow = RendererWorld.Instance.CreateRenderWindow(Handle, size); if (renderWindow == null) return false; renderWindow.AutoUpdate = false; renderWindow.AllowAdditionalMRTs = true; camera = SceneManager.Instance.CreateCamera( SceneManager.Instance.GetUniqueCameraName("UserControl")); camera.Purpose = Camera.Purposes.MainCamera; //update camera settings camera.NearClipDistance = cameraNearFarClipDistance.Minimum; camera.FarClipDistance = cameraNearFarClipDistance.Maximum; camera.AspectRatio = (float)renderWindow.Size.X / (float)renderWindow.Size.Y; camera.FixedUp = cameraFixedUp; camera.Position = cameraPosition; camera.Direction = cameraDirection; camera.Fov = cameraFov; camera.ProjectionType = cameraProjectionType; camera.OrthoWindowHeight = cameraOrthoWindowHeight; viewport = renderWindow.AddViewport(camera); //Initialize HDR compositor for HDR render technique if (EngineApp.RenderTechnique == "HDR") { viewport.AddCompositor("HDR", 0); viewport.SetCompositorEnabled("HDR", true); } //Initialize Fast Approximate Antialiasing (FXAA) { bool useMRT = RendererWorld.InitializationOptions.AllowSceneMRTRendering; string fsaa = RendererWorld.InitializationOptions.FullSceneAntialiasing; if ((useMRT && (fsaa == "" || fsaa == "RecommendedSetting") && IsActivateFXAAByDefault()) || fsaa == "FXAA") { if (RenderSystem.Instance.HasShaderModel3()) InitializeFXAACompositor(); } } //add listener renderTargetListener = new ViewRenderTargetListener(this); renderWindow.AddListener(renderTargetListener); if (guiRenderer == null) guiRenderer = new GuiRenderer(viewport); else guiRenderer.ChangeViewport(viewport); if (controlManager == null) controlManager = new ScreenControlManager(guiRenderer); return true; }