Example #1
0
        internal void draw(FramebufferSet curFramebuffers, ViewInfo curView)
        {
            gameWindow.checkGlError("--uncaught ERROR entering Scene draw--");

            RenderOptions renderOptions = curFramebuffers.renderOptions;

            GL.Enable(EnableCap.Blend);

            curFramebuffers.sceeneFramebuffer.enable(true);
            curFramebuffers.sceeneFramebuffer.Multisampeling = false;

            GL.Enable(EnableCap.Blend);

            drawSceene(Pass.normal, curView);

            GL.Disable(EnableCap.Blend);

            if (renderOptions.ssAmbientOccluison)
            {
                curFramebuffers.aoPreFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.ssaoPreShader, new int[] { curFramebuffers.sceeneFramebuffer.ColorTexture, curFramebuffers.sceeneFramebuffer.DepthTexture }, Shader.Uniform.modelview_matrix, curView.modelviewMatrix);

                curFramebuffers.aoFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.ssaoShader, new int[] { curFramebuffers.aoPreFramebuffer.ColorTexture, getTextureId(Material.WorldTexture.noise) });

                curFramebuffers.aoBlurFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.ssaoBlrShaderA, new int[] { curFramebuffers.aoFramebuffer.ColorTexture, curFramebuffers.aoBlurFramebuffer2.ColorTexture });

                curFramebuffers.aoBlurFramebuffer2.enable(false);
                mFilter2d.draw(ShaderTypes.ssaoBlrShader, new int[] { curFramebuffers.aoBlurFramebuffer.ColorTexture });
            }

            //reder defered information

            /*
             * curFramebuffers.sceeneDefInfoFb.enable(true);
             * drawSceene(Pass.defInfo, curView);
             */

            //render defferd reflections
            curFramebuffers.reflectionFramebuffer.enable(true);
            mFilter2d.draw(ShaderTypes.reflectionShader, new int[] {
                Scene.envTextures[0],
                Scene.envTextures[1],
                Scene.envTextures[2],
                Scene.envTextures[3],
                Scene.envTextures[4],
                Scene.envTextures[5],
                curFramebuffers.sceeneFramebuffer.ColorTexture,
            },
                           Shader.Uniform.invMVPMatrix,
                           curView.invModelviewProjectionMatrix);

            setTextureId(Material.WorldTexture.reflectionMap, curFramebuffers.reflectionFramebuffer.ColorTexture);

            //render defferedLight
            curFramebuffers.lightFramebuffer.enable(true);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One);

            sunLight.drawable.draw(new int[] {
                curFramebuffers.sceeneFramebuffer.ColorTexture,
                sunFrameBuffer.DepthTexture,
                sunInnerFrameBuffer.DepthTexture,
                getTextureId(Material.WorldTexture.noise),
                curFramebuffers.sceeneFramebuffer.DepthTexture
            }, ref curView);

            GL.Enable(EnableCap.CullFace);

            foreach (var light in spotlights)
            {
                light.drawable.draw(new int[] {
                    curFramebuffers.sceeneFramebuffer.ColorTexture,
                    gameWindow.shadowFramebuffer.ColorTexture,
                    0,
                    getTextureId(Material.WorldTexture.noise),
                    curFramebuffers.sceeneFramebuffer.DepthTexture
                }, ref curView);
            }

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.CullFace);

            if (Settings.Instance.video.lightmapSmoothing)
            {
                setTextureId(Material.WorldTexture.lightMap, curFramebuffers.lightBlurFramebuffer.ColorTexture);

                curFramebuffers.lightBlurFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.lightBlurShader, new int[] { curFramebuffers.sceeneFramebuffer.ColorTexture, curFramebuffers.lightFramebuffer.ColorTexture });
            }
            else
            {
                setTextureId(Material.WorldTexture.lightMap, curFramebuffers.lightFramebuffer.ColorTexture);
            }


            curFramebuffers.sceeneFramebuffer.enable(false);

            drawSceene(Pass.diffuse, curView);

            GL.Enable(EnableCap.Blend);

            // copy scene to transparent fb -- we can do lookups
            curFramebuffers.sceeneBackdropFb.enable(true);
            mFilter2d.draw(ShaderTypes.copycatShader, new int[] { curFramebuffers.sceeneFramebuffer.ColorTexture });

            // switch back to scene fb
            curFramebuffers.sceeneFramebuffer.enable(false);

            backdropTextures = new int[] {
                curFramebuffers.sceeneBackdropFb.ColorTexture,
                curFramebuffers.sceeneBackdropFb.DepthTexture
            };

            if (renderOptions.ssAmbientOccluison)
            {
                mFilter2d.draw(ShaderTypes.ssaoBlendShader, new int[] { curFramebuffers.aoBlurFramebuffer2.ColorTexture, curFramebuffers.sceeneBackdropFb.ColorTexture });
            }

            drawSceene(Pass.transparent, curView);

            curFramebuffers.selectionFb.enable(true);

            bool hasSelection = drawSceene(Pass.selection, curView);

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);

            Vector2 bloomSize = new Vector2(5, 2);

            if (hasSelection)
            {
                curFramebuffers.selectionblurFb.enable(false);
                mFilter2d.draw(ShaderTypes.bloomShader, new int[] { curFramebuffers.selectionFb.ColorTexture }, Shader.Uniform.in_vector, bloomSize);
            }

            curFramebuffers.selectionblurFb2.enable(true);

            if (hasSelection)
            {
                mFilter2d.draw(ShaderTypes.bloomShader, new int[] { curFramebuffers.selectionblurFb.ColorTexture }, Shader.Uniform.in_vector, bloomSize);
            }


            curFramebuffers.bloomFramebuffer2.Multisampeling = false;
            if (renderOptions.bloom)
            {
                curFramebuffers.bloomFramebuffer2.enable(false);
                mFilter2d.draw(ShaderTypes.bloomCurveShader, new int[] { curFramebuffers.sceeneFramebuffer.ColorTexture });

                for (int i = 0; i < 2; i++)
                {
                    curFramebuffers.bloomFramebuffer.enable(false);
                    mFilter2d.draw(ShaderTypes.bloomShader, new int[] { curFramebuffers.bloomFramebuffer2.ColorTexture }, Shader.Uniform.in_vector, bloomSize);

                    curFramebuffers.bloomFramebuffer2.enable(false);
                    mFilter2d.draw(ShaderTypes.bloomShader, new int[] { curFramebuffers.bloomFramebuffer.ColorTexture }, Shader.Uniform.in_vector, bloomSize);
                }
            }
            curFramebuffers.bloomFramebuffer2.Multisampeling = true;

            if (renderOptions.depthOfField)
            {
                curFramebuffers.dofPreFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.dofpreShader, new int[] {
                    curFramebuffers.screenNormalFb.ColorTexture,
                    curFramebuffers.sceeneBackdropFb.ColorTexture
                }, Shader.Uniform.in_vector, new Vector2(curView.getFocus(0.9f), 0.01f));

                curFramebuffers.dofFramebuffer.enable(false);
                mFilter2d.draw(ShaderTypes.dofShader, new int[] { curFramebuffers.dofPreFramebuffer.ColorTexture, getTextureId(Material.WorldTexture.noise) });

                curFramebuffers.dofFramebuffer2.enable(false);
                mFilter2d.draw(ShaderTypes.dofShader, new int[] { curFramebuffers.dofFramebuffer.ColorTexture, getTextureId(Material.WorldTexture.noise) });
            }

            curFramebuffers.outputFb.enable(false);
            curFramebuffers.sceeneFramebuffer.Multisampeling = true;

            int texture = curFramebuffers.sceeneFramebuffer.ColorTexture;

            if (curFramebuffers.aoPreFramebuffer != null)
            {
                texture = curFramebuffers.lightBlurFramebuffer.ColorTexture;
            }


            mFilter2d.draw(ShaderTypes.composite, new int[] {
                curFramebuffers.sceeneFramebuffer.ColorTexture,
                curFramebuffers.bloomFramebuffer2.ColorTexture,
                curFramebuffers.selectionFb.ColorTexture,
                curFramebuffers.selectionblurFb2.ColorTexture,
                curFramebuffers.dofFramebuffer2.ColorTexture,
                texture
            },
                           Shader.Uniform.in_vector,
                           compositeMod);

            gameWindow.checkGlError("--uncaught ERROR leaving Scene--");
        }