public void Render() { Q.shader.UseShader(); Q.shader.BindVector3("lightColour", lightColour); Q.shader.BindVector3("lightPosition", lightPosition); Q.shader.BindFloat("lightIntensity", lightIntensity); Q.shader.BindFloat("lightRadius", lightRadius); Q.shader.BindVector3("cameraPosition", CameraManager.GetActiveCamera().Position); Q.Render(); }
protected override void OnRenderFrame(FrameEventArgs e) { Util.TotalTime += (float)e.Time; //TotalTime += deltaTime fps = 1.0 / e.Time; base.Title = "Legend286 and Boomer678's Rendering Engine" + ": OpenGL Version: " + GL.GetString(StringName.Version) + ": frametime: " + (int)fps; base.OnRenderFrame(e); _controller.Update(this, (float)e.Time); GL.ClearColor(new Color4(0.0f, 0.0f, 0.0f, 0.0f)); //pretty colors :^) GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); #region Render Editor UI ImGui.SetNextWindowPos(new System.Numerics.Vector2(0.0f, 0.0f)); ImGui.Begin("Editor UI"); ImGui.SetWindowSize(new System.Numerics.Vector2(380, Window._Height)); ImGui.ColorEdit3("Light 1 Colour", ref lightColour1); ImGui.DragFloat("Light 1 Intensity", ref light1Intensity); ImGui.DragFloat("Light 1 Radius", ref lightRadius); ImGui.ColorEdit3("Light 2 Colour", ref lightColour2); ImGui.DragFloat("Light 2 Intensity", ref light2Intensity); ImGui.ColorEdit3("Light 3 Colour", ref lightColour3); ImGui.DragFloat("Light 3 Intensity", ref light3Intensity); ImGui.End(); #endregion // move this to editorlayer or something :) light.setColour(lightColour1); light2.setColour(lightColour2); light3.setColour(lightColour3); light.setIntensity(light1Intensity); light2.setIntensity(light2Intensity); light3.setIntensity(light3Intensity); light.setRadius(lightRadius); bool isOpenMenu = true; #region Render Debug ImGUI ImGui.SetNextWindowPos(new System.Numerics.Vector2(Width - 450, 0.0f)); ImGui.Begin("Render Debug", ref isOpenMenu, ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.None); ImGui.SetWindowSize(new System.Numerics.Vector2(450, 365), ImGuiCond.Once); ImGui.Text("Shaders: " + ShaderManager.GetShaderCount()); ImGui.Text("Camera Pos: " + player.GetCamera().Position); ImGui.SliderFloat("Fog End Distance", ref RenderingParameters.FogEndDistance, 10.0f, 10000.0f); if (ImGui.Button("Quit", new System.Numerics.Vector2(100, 32))) { Exit(); } ImGui.End(); #endregion #region Shader Live Coding ImGui.Begin("Shader Live Coding"); ImGui.SetWindowSize(new System.Numerics.Vector2(530, 475), ImGuiCond.Once); if (ImGui.Button("Compile", new System.Numerics.Vector2(400, 32))) { foreach (var mesh in MeshManager.Meshes) { Shader shader = new Shader(mesh.mat.shader.SourceCode_frag, mesh.mat.shader.SourceCode_vert); ShaderManager.put(ShaderType_BL.GBuffer, mesh.mat.flags, shader); } } if (ImGui.CollapsingHeader("Fragment")) { ImGui.InputTextMultiline("Fragment Shader", ref Meshes[0].mat.shader.SourceCode_frag, 4096, new System.Numerics.Vector2(800, 600)); } if (ImGui.CollapsingHeader("Vertex")) { ImGui.InputTextMultiline("Vertex Shader", ref Meshes[0].mat.shader.SourceCode_vert, 4096, new System.Numerics.Vector2(800, 600)); } ImGui.End(); #endregion tex.UseTexture(TextureUnit.Texture0); tex2.UseTexture(TextureUnit.Texture1); player.GetCamera().ProcessInput(); var mouse = Mouse.GetState(); var keyboard = Keyboard.GetState(); DeferredRenderer.Render(); if (keyboard.IsKeyDown(Key.F1)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_LIT; } if (keyboard.IsKeyDown(Key.F2)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_NORMAL_ONLY; } if (keyboard.IsKeyDown(Key.F3)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_SPECULAR_ONLY; } if (keyboard.IsKeyDown(Key.F4)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_DEPTH_ONLY; } if (keyboard.IsKeyDown(Key.F5)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_WORLD_POSITION_ONLY; } if (keyboard.IsKeyDown(Key.F6)) { DeferredRenderer.mode = DeferredRenderer.RenderingMode.RENDER_DEBUG; } // render debug mode if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_DIFFUSE_ONLY) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.DEBUG_DIFFUSE_ONLY); Q.Render(); } if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_NORMAL_ONLY) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.DEBUG_NORMAL_ONLY); Q.Render(); } if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_SPECULAR_ONLY) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.DEBUG_SPECULAR_ONLY); Q.Render(); } if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_DEPTH_ONLY) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.DEBUG_DEPTH_ONLY); Q.Render(); } if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_WORLD_POSITION_ONLY) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.DEBUG_WORLD_POSITION); Q.Render(); } if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_DEBUG) { DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.DebugGBuffer, ShaderFlags.NONE); Q.Render(); } // render light texture if (DeferredRenderer.mode == DeferredRenderer.RenderingMode.RENDER_LIT) { // DeferredRenderer.BindLightingTexture(); DeferredRenderer.BindGBufferTextures(); Q.shader = ShaderManager.get(ShaderType_BL.Lighting, ShaderFlags.LIT); Q.Render(); } DeferredRenderer.UnbindGBufferTextures(); _controller.Render(); Util.CheckGLError("End of frame"); q.Render(); SwapBuffers(); }