Пример #1
0
        void Initialise(ShaderType_BL type, ShaderFlags flags)
        {
            shader = ShaderManager.get(type, flags);
            GL.BindVertexArray(VertexArrayObject);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
            GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw);
            GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.StaticDraw);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
            GL.EnableVertexAttribArray(0);
            int texCoordLocation = shader.GetAttribLocation("aTexCoord");

            GL.EnableVertexAttribArray(texCoordLocation);

            GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
        }
Пример #2
0
        public Material(string diffuseTexture, string normalTexture, string specularTexture)
        {
            if (diffuseTexture != "")
            {
                UseDiffuse = true;
            }

            if (normalTexture != "")
            {
                UseNormal = true;
            }

            if (specularTexture != "")
            {
                UseSpecular = true;
            }

            if (UseDiffuse)
            {
                DiffuseMap = new Texture(diffuseTexture);
                flags     |= ShaderManager.ShaderFlags.USE_DIFFUSE_TEXTURE;
            }

            if (UseNormal)
            {
                NormalMap = new Texture(normalTexture);
                flags    |= ShaderManager.ShaderFlags.USE_NORMAL_TEXTURE;
            }

            if (UseSpecular)
            {
                SpecularMap = new Texture(specularTexture);
                flags      |= ShaderManager.ShaderFlags.USE_SPECULAR_TEXTURE;
            }

            shader = ShaderManager.get(ShaderManager.ShaderType_BL.Default, flags);
        }
Пример #3
0
        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();
        }
Пример #4
0
 void setShaderFlags(ShaderManager.ShaderFlags flags)
 {
     _shader = ShaderManager.get(ShaderManager.ShaderType_BL.ImGui, flags);
 }
Пример #5
0
 public void SetShader(ShaderType_BL type)
 {
     shader = ShaderManager.get(type, flags);
 }