public void DoCulling() { totalPixelsVisible = 0; terrainNodesVisible = 0; objectsPixelsVisible = 0; //quadTreeObject.ComputeVisibility(Camera.GetCameraInstance()); queryManager.Reset(); occlusionRenderSurface.BeginScene(this.occlusionSurface); occlusionRenderSurface.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.White, 1.0f, 0); //scene.RenderScene(0, scene[null], false); scene.BeginRenderObject(0, scene[null]); foreach (IRenderable renderable in this.leaves) { scene.RenderObjectBoundingBox(renderable); } scene.EndRenderObject(); queryManager.IssueAllQueries(); this.totalPixelsVisible = queryManager.GetResults(); occlusionRenderSurface.EndScene(Filter.None); this.totalPixelsVisible = queryManager.TotalPixelsVisible; this.objectsPixelsVisible = queryManager.ObjectsPixelsVisible; this.terrainNodesVisible = queryManager.TerrainNodesVisible; }
public MDX1_Surface(Size size) { mSrcRect = new Rectangle(new Point(0, 0), size); mDisplay = Display.Impl as MDX1_Display; mDevice = mDisplay.D3D_Device; /* * Bitmap bitmap = new Bitmap(size.Width, size.Height); * Graphics g = Graphics.FromImage(bitmap); * g.Clear(Color.FromArgb(0, 0, 0, 0)); * g.Dispose(); */ //mTexture = Texture.FromBitmap(mDevice, bitmap, Usage.None, Pool.Managed); mTexture = new Ref <Texture>(new Texture(mDevice.Device, size.Width, size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed)); mRenderToSurface = new RenderToSurface(mDevice.Device, size.Width, size.Height, Format.A8R8G8B8, true, DepthFormat.D16); mRenderToSurface.BeginScene(mTexture.Value.GetSurfaceLevel(0)); mDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0); mRenderToSurface.EndScene(Filter.None); mRenderToSurface.Dispose(); mRenderToSurface = null; mTextureSize = mSrcRect.Size; InitVerts(); }
public SDX_Surface(Size size) { mSrcRect = new Rectangle(new Point(0, 0), size); mDisplay = Display.Impl as SDX_Display; mDevice = mDisplay.D3D_Device; mTexture = new Ref <Texture>(new Texture(mDevice.Device, size.Width, size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed)); RenderToSurface render = new RenderToSurface(mDevice.Device, size.Width, size.Height, Format.A8R8G8B8, Format.D16); Viewport v = new Viewport(0, 0, size.Width, size.Height); render.BeginScene(mTexture.Value.GetSurfaceLevel(0), v); mDevice.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0, 0).ToArgb(), 1.0f, 0); render.EndScene(Filter.None); render.Dispose(); render = null; mTextureSize = mSrcRect.Size; InitVerts(); }
//--------------------// #region Render /// <summary> /// Renders the content of a delegate to this texture /// </summary> /// <param name="render">The content to be rendered</param> internal void RenderTo(Action render) { #region Sanity checks if (Disposed) { throw new ObjectDisposedException(ToString()); } if (render == null) { throw new ArgumentNullException(nameof(render)); } #endregion // Don't initialise this earlier, would cause trouble with resetting the device if (_rtsHelper == null) { _rtsHelper = new RenderToSurface(_engine.Device, _rtsHelperSize.Width, _rtsHelperSize.Height, _engine.PresentParams.BackBufferFormat, _engine.PresentParams.AutoDepthStencilFormat); } using (new ProfilerEvent("Rendering to texture")) { _rtsHelper.BeginScene(Surface, Viewport); render(); _rtsHelper.EndScene(Filter.None); } }
private void RenderBGPointer() { Viewport view = new Viewport(); view.Width = 128; view.Height = 128; view.MaxZ = 1.0f; Matrix currentViewMatrix = device.Transform.View; rts.BeginScene(renderSurface, view); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); if (playerShip.State == ShipState.Normal && opponentShip.State == ShipState.Normal) { Matrix pointerViewMatrix = Matrix.Translation(0, 2, -15); pointerViewMatrix *= playerShip.Position.WorldMatrix; device.Transform.View = Matrix.Invert(pointerViewMatrix); bgPointer.Render(); drawingFont.DrawText(2, 2, Color.LimeGreen, "Range: " + range.ToString()); } rts.EndScene(Filter.Linear); device.Transform.View = currentViewMatrix; }
// ---] // [--- private void renderizarNaTextura() { // Prepara a configuração da janela de visualização Viewport visao = new Viewport(); visao.Width = superficie_ntam; visao.Height = superficie_ntam; visao.MaxZ = 1.0f; // Inicia a renderização da cena Renderizador.BeginScene(superficieAlvo, visao); // Limpa o dispositivo device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0); // Modo de preenchimento da renderização: pontos device.RenderState.FillMode = FillMode.Point; // Desenha o objeto na textura posicao = new Vector3(0.0f, 0.2f, -50.0f); rotacao = new Vector3(0, 0, 0); g_props = new Propriedades3D(posicao, rotacao); desenharObjeto(objeto3D, g_props); // Recupera modo de preenchimento da renderização: sólido device.RenderState.FillMode = FillMode.Solid; // Finaliza a cena no Renderizador Renderizador.EndScene(Filter.None); } // renderizarNaTextura()
public override void BeginRender() { // it looks like Direct3D creates a new surface. // so here we will create a new texture, and draw the current texture to it // then discard the old one. Texture t = new Texture(mDevice.Device, SurfaceWidth, SurfaceHeight, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); Direct3D.Surface surfaceTarget = t.GetSurfaceLevel(0); mRenderToSurface = new RenderToSurface(mDevice.Device, SurfaceWidth, SurfaceHeight, Format.A8R8G8B8, false, DepthFormat.D16); Viewport vp = new Viewport(); vp.X = 0; vp.Y = 0; vp.Width = SurfaceWidth; vp.Height = SurfaceHeight; mRenderToSurface.BeginScene(surfaceTarget, vp); Display.Clear(); Draw(); mTexture.Dispose(); mTexture = new Ref <Texture>(t); }
/// <summary>Set up the cube map by rendering the scene into it</summary> private void RenderSceneIntoCubeMap(Device device, double totalTime, float elapsedTime, Vector3 position) { if (invalidated) { rendering = true; CameraBase cam = Framework.Instance.CurrentCamera; cubeCamera.LookFrom = position; Framework.Instance.CurrentCamera = cubeCamera; for (int f = 0; f < 6; ++f) { CubeTexture cubeTex = cubeTexture.Texture as CubeTexture; using (Surface s = cubeTex.GetCubeMapSurface((CubeMapFace)f, 0)) { SetCubeMapCamera((CubeMapFace)f); renderHelper.BeginScene(s); cubeCamera.OnFrameMove(device, totalTime, elapsedTime); cubeCamera.OnFrameRender(device, totalTime, elapsedTime); if (OnFrameRenderMethod != null) { OnFrameRenderMethod(device, totalTime, elapsedTime); } device.Transform.World = Matrix.Identity; renderHelper.EndScene(Filter.None); } } Framework.Instance.CurrentCamera = cam; Framework.Instance.CurrentCamera.OnFrameRender(device, totalTime, elapsedTime); rendering = false; invalidated = false; } }
private void DrawToSurface() { rts.BeginScene(surface); FillMode prevFillMode = d3dDevice.RenderState.FillMode; d3dDevice.RenderState.FillMode = FillMode.WireFrame; DrawQ3Map(); d3dDevice.RenderState.FillMode = prevFillMode; rts.EndScene(Filter.None); }
void RenderThread() { Thread.CurrentThread.Name = "RenderThread"; GameTime renderTime = new GameTime(); while (!requestStop) { renderTime.Refresh(25); if (waitForReset) { Thread.Sleep(100); continue; } if (deviceReadyForRender) { try { // render to texture renderToSurface.BeginScene(renderToTexture.GetSurfaceLevel(0), new Viewport(0, 0, engine.GameResolution.x * renderScale, engine.GameResolution.y * renderScale, 0f, 1f)); device.Clear(ClearFlags.Target, 0x000000, 5.0f, 0); Render(renderTime); renderToSurface.EndScene(Filter.Triangle); // render texture to screen device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, 0x00000000, 5.0f, 0); device.BeginScene(); RenderTexture(); device.EndScene(); renderFinished.Set(); } catch (Exception) { } try { device.Present(); } catch (Exception) { OnLostResetDevice(); } } else { OnLostResetDevice(); } } }
void DoDraw(Device dev) { if (m_RogueForm == null) { return; } /////////////////////////////////// // Render the scene to the texture /////////////////////////////////// m_RenderToSurface.BeginScene(m_RenderSurface); { ///////// // Clear ///////// dev.Clear(ClearFlags.Target, m_ClearColor, 1.0f, 0); /////////////////// // Render each gfx /////////////////// foreach (IGfx gfx in m_Gfxs) { gfx.Draw(dev); } } m_RenderToSurface.EndScene(Filter.None); ////////////////////////////////////////////////////// // Then draw scene texture scaled to fit whole canvas ////////////////////////////////////////////////////// m_Device.BeginScene(); { m_Sprite.Begin(SpriteFlags.None); { m_Sprite.Draw2D(m_RenderTexture, new Rectangle(0, 0, RogueGame.CANVAS_WIDTH, RogueGame.CANVAS_HEIGHT), new SizeF(m_RogueForm.ClientRectangle.Width, m_RogueForm.ClientRectangle.Height), PointF.Empty, Color.White); } m_Sprite.End(); } m_Device.EndScene(); }
public void Draw() { // draw particles in _screenTexture RenderToSurface rts = new RenderToSurface(_Device, _width, _height, _screenTexture.GetLevelDescription(0).Format); Surface surface = _screenTexture.GetSurfaceLevel(0); rts.BeginScene(surface, new SharpDX.Viewport(0, 0, _width, _height, 0, 1)); drawTexture(_backGroundTexture, _particles.Fade); DrawQuadParticles(); rts.EndScene(Filter.None); surface.Dispose(); rts.Dispose(); //draw screenTexture in screen _Device.Viewport = new SharpDX.Viewport(0, 0, canvasWidth, canvasHeight, 0, 1); _Device.BeginScene(); // _Device.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 1); _Device.SetRenderState(RenderState.AlphaBlendEnable, true); _Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha); //SourceColor SourceAlpha SourceAlpha* _Device.SetRenderState(RenderState.DestinationBlend, Blend.DestinationAlpha); //DestinationAlpha SourceColor DestinationColor* if (_pointBool) { drawTexture(_earthTexture, 1.0f); } else { drawTexture(_earthWhite, 1.0f); } drawTexture(_screenTexture, 1.0f); _Device.SetRenderState(RenderState.AlphaBlendEnable, false); _Device.EndScene(); _Device.Present(); Texture temp = _backGroundTexture; _backGroundTexture = _screenTexture; _screenTexture = temp; }
public void BeginScene() { _renderToSurface.BeginScene(_surface, _viewport); }
private void updateParticles() { int particleRes = _particles.getParticleStateResolution(); RenderToSurface rts = new RenderToSurface(_Device, particleRes, particleRes, _stateParticleTexture1.GetLevelDescription(0).Format); Surface surface = _stateParticleTexture1.GetSurfaceLevel(0); rts.BeginScene(surface, new SharpDX.Viewport(0, 0, particleRes, particleRes, 0, 1)); /*set parametres shader*/ _updateParticleShader.SetTexture("d_wind", _windTexture); _Device.SetSamplerState(0, SamplerState.AddressU, TextureAddress.Clamp); _Device.SetSamplerState(0, SamplerState.AddressV, TextureAddress.Clamp); _Device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); _Device.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear); _updateParticleShader.SetTexture("d_particles", _stateParticleTexture0); _Device.SetSamplerState(1, SamplerState.AddressU, TextureAddress.Clamp); _Device.SetSamplerState(1, SamplerState.AddressV, TextureAddress.Clamp); _Device.SetSamplerState(1, SamplerState.MinFilter, TextureFilter.Point); _Device.SetSamplerState(1, SamplerState.MagFilter, TextureFilter.Point); //parametros JSON _updateParticleShader.SetValue("d_rand_seed", (float)new Random().NextDouble()); _updateParticleShader.SetValue("d_wind_resolution", new float[] { _windData.width, _windData.height }); _updateParticleShader.SetValue("d_wind_min", new float[] { _windData.uMin, _windData.vMin }); _updateParticleShader.SetValue("d_wind_max", new float[] { _windData.uMax, _windData.vMax }); _updateParticleShader.SetValue("d_particles_res", particleRes); _updateParticleShader.SetValue("d_particles_min", min_range); _updateParticleShader.SetValue("d_particles_max", max_range); //parametros Menu _updateParticleShader.SetValue("d_speed_factor", _particles.SpeedFactor); //correction texture inverse _updateParticleShader.SetValue("d_miPixX", -0.5f / _stateParticleTexture0.GetLevelDescription(0).Width); _updateParticleShader.SetValue("d_miPixY", -0.5f / _stateParticleTexture0.GetLevelDescription(0).Height); if (_particles.IsWave) { _updateParticleShader.Technique = "Wave"; } else { _updateParticleShader.Technique = "Default"; } /************************/ _updateParticleShader.SetValue("d_ParticulesByBlock", _particlesPerBlock); _updateParticleShader.SetValue("d_delta", dx); /************************/ _updateParticleShader.Begin(); _updateParticleShader.BeginPass(0); UtilDraw.drawInQuad(_Device); _updateParticleShader.EndPass(); _updateParticleShader.End(); rts.EndScene(Filter.None); surface.Dispose(); rts.Dispose(); /*Change index for fading and reset*/ updateIndexReset(); /*exchange texture*/ _tempTexture = _stateParticleTexture0; _stateParticleTexture0 = _stateParticleTexture1; _stateParticleTexture1 = _tempTexture; }
public void RenderTextures(Device device, double totalTime, float elapsedTime) { if (qualityLevel != QualityLevelEnum.Low) { rendering = true; if (reflectionSurface == null) { reflectionSurface = reflectionTexture.GetSurfaceLevel(0); } if (refractionSurface == null) { refractionSurface = refractionTexture.GetSurfaceLevel(0); } renderHelper.BeginScene(reflectionSurface); //Surface screen = device.GetRenderTarget(0); //Surface reflectionSurface = reflectionTexture.GetSurfaceLevel(0); device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, 0x00000000, 1.0f, 0); Framework.Instance.CurrentCamera.Reflected = true; /* * // create matrices to render with * Matrix camMatrix = Framework.Instance.CurrentCamera.ReflectionMatrix * * Framework.Instance.CurrentCamera.ProjectionMatrix; * camMatrix.Invert(); * camMatrix.Transpose(camMatrix); * * //Plane reflectionClipPlane = Plane.FromPointNormal(Vector3.Empty, planeNormalDirection); * Plane reflectionClipPlane = new Plane(0f, 1f, 0f, 0.1f); * reflectionClipPlane.Transform(camMatrix); * * device.ClipPlanes[0].Plane = reflectionClipPlane; * device.ClipPlanes[0].Enabled = true; */ device.Transform.View = Framework.Instance.CurrentCamera.ReflectionMatrix; if (onFrameRender != null) { onFrameRender(device, totalTime, elapsedTime, true); } Framework.Instance.CurrentCamera.Reflected = false; waterShader.SetVariable("xReflectionMap", reflectionTexture); //device.ClipPlanes.DisableAll(); device.Transform.World = Matrix.Identity; device.Transform.View = Framework.Instance.CurrentCamera.ViewMatrix; renderHelper.EndScene(Filter.None); renderHelper.BeginScene(refractionSurface); device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, 0x00000000, 1.0f, 0); //device.Transform.View = Framework.Instance.CurrentCamera.ViewMatrix; if (onFrameRender != null) { onFrameRender(device, totalTime, elapsedTime, false); } waterShader.SetVariable("xRefractionMap", refractionTexture); //device.ClipPlanes.DisableAll(); //device.Transform.World = Matrix.Identity; //device.Transform.View = Framework.Instance.CurrentCamera.ViewMatrix; renderHelper.EndScene(Filter.None); if (reflectionSurface != null) { reflectionSurface.Dispose(); reflectionSurface = null; } if (refractionSurface != null) { refractionSurface.Dispose(); refractionSurface = null; } rendering = false; } }
/// <summary> /// Method to build shadow maps. /// </summary> public void RenderShadowMap(LightObj light, int num, Matrix projection) { Matrix lightMatrix = Matrix.LookAtRH(light.Direction, new Vector3(0, 0, 0), new Vector3(0, 1, 0)) * projection; switch (num) { case 0: shadowHelp.BeginScene(shadowMap.GetSurfaceLevel(0)); //, device.Viewport); break; case 1: shadowHelp.BeginScene(shadowMap2.GetSurfaceLevel(0), device.Viewport); break; case 2: shadowHelp.BeginScene(shadowMap3.GetSurfaceLevel(0), device.Viewport); break; } device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0); effect.Technique = "ShadowMap"; effect.SetValue("maxDepth", light.Distance * 3); effect.SetValue("lightWVP", lightMatrix); effect.Begin(FX.None); effect.BeginPass(0); if (groundPlane.Enabled) { groundPlane.Mesh.DrawSubset(0); } for (int i = 0; i < mesh.Count; i++) { if (mesh[i].Enabled) { mesh[i].Mesh.DrawSubset(0); } } effect.EndPass(); effect.End(); shadowHelp.EndScene(Filter.Point); // shadowMap = shadowTest. switch (num) { case 0: effect.SetValue("shadowMapLight1", shadowMap); break; case 1: effect.SetValue("shadowMapLight2", shadowMap2); break; case 2: effect.SetValue("shadowMapLight3", shadowMap3); break; } }
/// <summary> /// Renders the scene. /// </summary> public void RenderScene(Color background, List <LightObj> lights, Camera camera) { bool useGlow = false; // Sets the variables for the shader. SetVariables(lights, camera); //effect.Technique = "Test"; for (int i = 0; i < mesh.Count; i++) { if (mesh[i].Emissive.Enable && !mesh[i].Emissive.Path.Equals("")) { useGlow = true; break; } } // If/Else statement to control rendering with emissive glow or not. if (useGlow) { RenderGlow(); } else { BeginRender(background); } // If emissive glow is used, the base scene is rendered to a texture. if (useGlow) { surfRender.BeginScene(renderedScene.GetSurfaceLevel(0), device.Viewport); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, background, 1.0f, 0); } if (groundPlane.Enabled) { RenderModel((Model)groundPlane, lights[0].Shadows, 0); } // Loops through all the models and renders each. for (int i = 0; i < mesh.Count; i++) { if (mesh[i].Enabled) { RenderModel(mesh[i], lights[0].Shadows, 0); } } if (showLights) { using (Sprite spriteobject = new Sprite(device)) { foreach (LightObj light in lights) { if (!light.Enabled) { continue; } spriteobject.SetWorldViewRH(device.Transform.World, device.Transform.View); spriteobject.Begin(SpriteFlags.AlphaBlend | SpriteFlags.Billboard | SpriteFlags.SortTexture | SpriteFlags.ObjectSpace); //spriteobject.Transform = Matrix.Scaling(0.25f, 0.25f, 0.25f); spriteobject.Draw(lightTexture, Rectangle.Empty, Vector3.Empty, light.Direction, Color.White); spriteobject.End(); } } } // If emissive glow is used, the textures are set to the shader and rendered to a sprite. if (useGlow) { surfRender.EndScene(Filter.None); effect.SetValue("renderedScene", renderedScene); BeginRender(background); using (Sprite spriteobject = new Sprite(device)) { prevTechnique = effect.Technique; effect.Technique = "Bloom"; effect.Begin(FX.None); spriteobject.Begin(SpriteFlags.None); effect.BeginPass(0); spriteobject.Draw(renderedGlow, Rectangle.Empty, new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.White); effect.EndPass(); spriteobject.End(); effect.End(); effect.Technique = prevTechnique; } } EndRender(); }
/// <summary> /// Zahajeni renderingu do textury /// </summary> public void BeginScene() { renderToSurface.BeginScene(surface); }