Exemplo n.º 1
0
        public void DebugRenderShadowMap(ShadowMap shadowMap)
        {
            PrepareRender(depthDebugShader);

            depthDebugShader.LoadBool("linearize", false);
            //depthDebugShader.LoadFloat("nearPlane", 10);
            //depthDebugShader.LoadFloat("farPlane", 4000);

            // Bind the FBO texture
            GL.ActiveTexture(TextureUnit.Texture0);
            shadowMap.BindTex();
            // Set transformation matrix
            depthDebugShader.LoadMatrix4("transformationMatrix",
                                         Maths.CreateTransformationMatrix(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f)));
            // Draw
            GL.DrawArrays(BeginMode.TriangleStrip, 0, 4);

            // Ubind the FBO texture
            GL.BindTexture(TextureTarget.Texture2D, 0);
            EndRender(depthDebugShader);
        }
        void RenderObjects()
        {
            // Enable global wireframe if needed
            if (Renderer.GlobalWireframe)
            {
                StateManager.EnableWireframe();
            }

            // Ensure back-face culling is enabled
            StateManager.Enable(EnableCap.CullFace);
            StateManager.Enable(EnableCap.DepthTest);
            StateManager.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            forwardShader.Start();
            forwardShader.LoadColor4("colorOverlay", Color.White);
            forwardShader.LoadFloat("entityLighting", 1f);

            // Load global shader variables
            Camera camera = Camera.Active;

            forwardShader.LoadBool("fogEnabled", Renderer.FogEnabled);
            if (Renderer.FogEnabled)
            {
                forwardShader.LoadInt("fogQuality", (int)GFXSettings.FogQuality);
                forwardShader.LoadFloat("fogDensity", Renderer.FogDensity);
                forwardShader.LoadFloat("fogGradient", Renderer.FogGradient);
                forwardShader.LoadFloat("fogMin", Renderer.FogMin);
                forwardShader.LoadFloat("fogMax", Renderer.FogMax);

                GL.ActiveTexture(TextureUnit.Texture1);
                if (GFXSettings.FogQuality == FogQuality.High)
                {
                    skyRenderTarg.Texture.Bind();
                }
                else if (GFXSettings.FogQuality == FogQuality.Medium)
                {
                    Renderer.Sky.skyMap.Bind();
                    forwardShader.LoadFloat("skyMapOffset", Renderer.Sky.skyMapOffset);
                }
                else
                {
                    forwardShader.LoadColor3("fogColor", Renderer.FogColor);
                }
            }
            forwardShader.LoadLights(Renderer.Lights);
            forwardShader.LoadMatrix4("projectionMatrix", camera.ProjectionMatrix);
            forwardShader.LoadMatrix4("viewMatrix", camera.ViewMatrix);
            forwardShader.LoadVector3("cameraPosition", camera.Position);
            forwardShader.LoadFloat("ambientIntensity", Renderer.AmbientIntensity);
            forwardShader.LoadBool("renderShadows", GFXSettings.RenderShadows);
            forwardShader.LoadFloat("lightFalloff", Renderer.LightFalloff);

            if (GFXSettings.RenderShadows)
            {
                forwardShader.LoadMatrix4("lightSpaceMatrix", shadowCamera.LightSpaceMatrix);
                forwardShader.LoadInt("pcfSamples", GFXSettings.ShadowPCFSamples);
                forwardShader.LoadFloat("shadowTexelMultiplier", shadow_texelMultiplier);
                forwardShader.LoadFloat("shadowBias", Renderer.ShadowBias);
                forwardShader.LoadFloat("shadowVisibility", Renderer.ShadowVisibility);

                GL.ActiveTexture(TextureUnit.Texture0);
                shadowMap.BindTex();
            }

            // Render normal geometry
            foreach (Renderer3D renderer in Renderer.Renderer3Ds.Values)
            {
                renderer.Prepare();
                renderer.Render(forwardShader, RenderPass.Normal, false);
            }

            shadowMap.UnbindTex();

            // Render front geometry
            if (GFXSettings.RenderShadows)
            {
                GL.ActiveTexture(TextureUnit.Texture0);
                shadowMap.BindTex();
            }

            GL.Clear(ClearBufferMask.DepthBufferBit);
            foreach (Renderer3D renderer in Renderer.Renderer3Ds.Values)
            {
                renderer.Prepare();
                renderer.Render(forwardShader, RenderPass.Normal, true);
            }

            forwardShader.Stop();
            shadowMap.UnbindTex();

            // Reset wireframe
            StateManager.DisableWireframe(true);
        }