/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); // NOTE: this is a workaround for the fact that the ThirdPersonCamera is not parented to the target... // before we can remove this, we need to parent it properly, currently it's transform only follows // the target during Update() and input event processing. scene.Update((float)e.Time); fpsCalc.newFrame(e.Time); fpsDisplay.Label = String.Format("FPS: {0:0.00}", fpsCalc.AvgFramesPerSecond); // setup the GLSL uniform for shader animation animateSecondsOffset += (float)e.Time; if (animateSecondsOffset > 1000.0f) { animateSecondsOffset -= 1000.0f; } mainShader.Activate(); mainShader.UniAnimateSecondsOffset = (float)animateSecondsOffset; instancingShader.Activate(); instancingShader.UniAnimateSecondsOffset = (float)animateSecondsOffset; ///////////////////////////////////////// // clear the render buffer.... GL.DepthMask(true); GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); // black GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); float fovy = (float)Math.PI / 4; float aspect = ClientRectangle.Width / (float)ClientRectangle.Height; float nearPlane = 1.0f; float farPlane = 5000.0f; // setup the inverse matrix of the active camera... Matrix4 mainSceneView = scene.ActiveCamera.worldMat.Inverted(); // setup the view projection. technically only need to do this on window resize.. Matrix4 mainSceneProj = Matrix4.CreatePerspectiveFieldOfView(fovy, aspect, nearPlane, farPlane); // create a matrix of just the camera rotation only (it needs to stay at the origin) Matrix4 rotationOnlyView = Matrix4.CreateFromQuaternion(mainSceneView.ExtractRotation()); // create an orthographic projection matrix looking down the +Z matrix; for hud scene and sun flare scene Matrix4 screenProj = Matrix4.CreateOrthographicOffCenter(0, ClientRectangle.Width, ClientRectangle.Height, 0, -1, 1); renderShadowmaps(fovy, aspect, nearPlane, farPlane, ref mainSceneView, ref mainSceneProj, ref rotationOnlyView, ref screenProj); renderScenes(fovy, aspect, nearPlane, farPlane, ref mainSceneView, ref mainSceneProj, ref rotationOnlyView, ref screenProj); // setup the view-bounds. SwapBuffers(); }
/// <summary> /// Called when it is time to render the next frame. Add your rendering code here. /// </summary> /// <param name="e">Contains timing information.</param> protected override void OnRenderFrame(FrameEventArgs e) { base.OnRenderFrame(e); // NOTE: this is a workaround for the fact that the ThirdPersonCamera is not parented to the target... // before we can remove this, we need to parent it properly, currently it's transform only follows // the target during Update() and input event processing. scene.Update((float)e.Time); fpsCalc.newFrame(e.Time); fpsDisplay.Label = String.Format("FPS: {0:0.00}", fpsCalc.AvgFramesPerSecond); // setup the GLSL uniform for shader animation animateSecondsOffset += (float)e.Time; if (animateSecondsOffset > 1000.0f) { animateSecondsOffset -= 1000.0f; } shaderPgm.Activate(); shaderPgm.u_AnimateSecondsOffset = (float)animateSecondsOffset; ///////////////////////////////////////// // clear the render buffer.... GL.Enable(EnableCap.DepthTest); GL.DepthMask(true); GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f); // black // GL.ClearColor (System.Drawing.Color.White); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); float fovy = (float)Math.PI / 4; float aspect = ClientRectangle.Width / (float)ClientRectangle.Height; ///////////////////////////////////////// // render the "environment" scene // // todo: should move this after the scene render, with a proper depth // test, because it's more efficient when it doesn't have to write every pixel { GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Front); GL.Disable(EnableCap.DepthClamp); // setup infinite projection for cubemap Matrix4 projMatrix = Matrix4.CreatePerspectiveFieldOfView(fovy, aspect, 0.1f, 2.0f); environmentScene.ProjectionMatrix = projMatrix; // create a matrix of just the camera rotation only (it needs to stay at the origin) environmentScene.InvCameraViewMatrix = Matrix4.CreateFromQuaternion( scene.ActiveCamera.worldMat.ExtractRotation() ).Inverted(); environmentScene.Render(); } ///////////////////////////////////////// // rendering the "main" 3d scene.... { GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.DepthClamp); GL.DepthMask(true); // setup the inverse matrix of the active camera... scene.InvCameraViewMatrix = scene.ActiveCamera.worldMat.Inverted(); // scene.renderConfig.renderBoundingSpheres = true; // setup the view projection. technically only need to do this on window resize.. Matrix4 projection = Matrix4.CreatePerspectiveFieldOfView(fovy, aspect, 1.0f, 500.0f); //projection = Matrix4.CreateTranslation (0, 0, -5) * projection; scene.ProjectionMatrix = projection; // render 3d content... scene.Render(); } //////////////////////////////////////// // render HUD scene { GL.Disable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); GL.DepthMask(false); // setup an orthographic projection looking down the +Z axis, same as: // GL.Ortho (0, ClientRectangle.Width, ClientRectangle.Height, 0, -1, 1); hudScene.InvCameraViewMatrix = Matrix4.CreateOrthographicOffCenter(0, ClientRectangle.Width, ClientRectangle.Height, 0, -1, 1); hudScene.Render(); } SwapBuffers(); }