Example #1
0
        public virtual void Init()
        {
            Program.Settings.GetLightRange(out float near, out float far);
            Program.Window.GetSize(out int windowWidth, out int windowHeight);

            Program.Window.OnButton      += OnButton;
            Program.Window.OnMouseButton += OnMouseButton;

            DefaultShader = ShaderRepository.GetShader("Default/default");
            DefaultShader.SetFloat("material.shininess", 32.0f);
            DefaultShader.SetFloat("lightNearPlane", near);
            DefaultShader.SetFloat("lightFarPlane", far);

            _lightingShaderOrtho = ShaderRepository.GetShader("Lighting/lightingShader", "Lighting/lightingShaderOrtho");
            _lightingShaderPersp = ShaderRepository.GetShader("Lighting/lightingShader", "Lighting/lightingShaderPersp");
            _lightingShaderPersp.SetFloat("farPlane", far);
            _lightingShaderOrtho.LightingShader = true;
            _lightingShaderPersp.LightingShader = true;

            _lightingFrameBuffer = new FrameBuffer();
            _lightingFrameBuffer.Use();
            Gl.DrawBuffer(DrawBufferMode.None);
            Gl.ReadBuffer(ReadBufferMode.None);
            FrameBuffer.UseDefault();

            CurrentCamera = new Camera();
            Entities.Add(CurrentCamera);

            UI = new UILayer();
        }
Example #2
0
        public FrameBuffer Render(FrameBuffer renderFrameBuffer)
        {
            Texture renderTexture = renderFrameBuffer.BoundTexture;

            if (postProcessShaders.Count <= 0)
            {
                return(renderFrameBuffer);
            }


            var destination = texture2;
            var source      = renderTexture;

            for (int i = 0; i < postProcessShaders.Count; i++)
            {
                Shader shader     = postProcessShaders[i];
                bool   lastShader = i >= postProcessShaders.Count - 1;

                if (!lastShader)
                {
                    postProBuffer.Use();
                    postProBuffer.BindTexture(destination);
                }
                else
                {
                    renderFrameBuffer.Use();
                }

                //Util.GLClear();
                source.BindToUnit(0);
                QuadMesh.ScreenQuad.Draw(shader);

                if (lastShader)
                {
                    break;
                }

                if (i == 0)
                {
                    source = texture1;
                }

                var temp = destination;
                destination = source;
                source      = temp;
            }

            return(renderFrameBuffer);
        }
Example #3
0
        private void LightingPass()
        {
            if (!Lights.Exists(x => x.ShadowsEnabled))
            {
                return;
            }

            Gl.CullFace(CullFaceMode.Front);

            Program.Settings.GetShadowMapSize(out int width, out int height);
            Gl.Viewport(0, 0, (uint)width, (uint)height);
            _lightingFrameBuffer.Use();

            foreach (Light l in Lights.FindAll(x => x.ShadowsEnabled))
            {
                l.CalculateShadows(_lightingFrameBuffer, l is PointLight ? _lightingShaderPersp : _lightingShaderOrtho, RenderScene);
            }
        }
Example #4
0
        public void RenderPipeline()
        {
            FrameBuffer buffer = RenderFrameBuffer;

            buffer.Use();
            GL.GetApi().ClearFramebuffer();

            for (int i = 0; i < Pipeline.Count; i++)
            {
                buffer = Pipeline[i].Render(buffer);
            }

            buffer.BoundTexture.BindToUnit(0);
            FrameBuffer.UseDefault();
            Util.GLClear();
            _finalShader.SetInt("screen", 0);
            QuadMesh.ScreenQuad.Draw(_finalShader);
        }
Example #5
0
        public FrameBuffer Render(FrameBuffer renderFrameBuffer)
        {
            LightingPass();

            Program.Window.GetSize(out int windowWidth, out int windowHeight);
            Gl.Viewport(0, 0, (uint)windowWidth, (uint)windowHeight);

            renderFrameBuffer.Use();
            Gl.CullFace(CullFaceMode.Back);

            DefaultShader.Use();
            CurrentCamera.SetData(DefaultShader);
            SetLightingData();
            RenderScene(DefaultShader);
            RenderExtras(renderFrameBuffer);


            return(renderFrameBuffer);
        }