示例#1
0
        public Player(Scene parent, Vector3 spawnPos, Vector3 viewDir, GameInput gameInput)
        {
            Parent = parent;
            this.gameInput = gameInput;

            //create hud renderer
            hud = new Hud(this);
            parent.guis.Add(hud);

            Position = spawnPos;
            PointingDirection = viewDir;

            upVector = new Vector3(0, 1, 0);
            zNear = 0.1f;
            zFar = 100;

            Shape boxShape = new BoxShape(new JVector(0.5f, 2, 0.5f));

            Body = new RigidBody(boxShape);
            Body.Position = new JVector(Position.X, Position.Y, Position.Z);
            Body.AllowDeactivation = false;

            JMatrix mMatrix = JMatrix.Identity;

            //mBody.SetMassProperties(mMatrix, 2,false);

            Jitter.Dynamics.Constraints.SingleBody.FixedAngle mConstraint = new Jitter.Dynamics.Constraints.SingleBody.FixedAngle(Body);

            parent.world.AddConstraint(mConstraint);
            parent.world.AddBody(Body);

            viewInfo = new ViewInfo(this);
            viewInfo.aspect = (float)gameWindow.Width / (float)gameWindow.Height;
            viewInfo.updateProjectionMatrix();

            tools.Add(new GameMenu(this, gameInput));
            tools.Add(new Spawner(this, gameInput));
            tools.Add(new Grabber(this, gameInput));
            tools.Add(new Remover(this, gameInput));
            tools.Add(new TerrainGun(this, gameInput));

            tool = tools[1];
        }
        public CubemapBufferSets(Scene parent, FramebufferCreator mFramebufferCreator, int size)
        {
            this.Scene = parent;
            Parent = parent;

            Vector2 vecSize = new Vector2(size,size);

            float fovy = (float)Math.PI/2;

            for (int i = 0; i < 6; i++)
            {
                outFrameBuffers[i] = mFramebufferCreator.createFrameBuffer(size, size, PixelInternalFormat.Rgba8, true);
                outTextures[i] = outFrameBuffers[i].ColorTexture;
                FrameBufferSets[i] = new FramebufferSet(mFramebufferCreator, vecSize, outFrameBuffers[i]);

                cubeView[i] = new ViewInfo(this);
                cubeView[i].PointingDirection = viewDirections[i];
                cubeView[i].upVec = upDirections[i];

                cubeView[i].aspect = 1f;
                cubeView[i].fovy = fovy;
                cubeView[i].updateProjectionMatrix();
            }
        }
示例#3
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (state == GameState.Playing || state == GameState.Menu)
            {
                // calculate mouse movement
                //gameInput.calcDelta();

                // calculate frame Times
                frameTime += (float)e.Time;
                lastFrameDuration = (float)e.Time;

                // exit game?
                bool ESC = Keyboard[Key.Escape];
                if (ESC && !prevESC)
                {
                    if (state == GameState.Menu)
                    {
                        exitGame();
                    }
                    if (state == GameState.Playing)
                    {
                        enterMenu();
                    }
                }
                prevESC = ESC;

                bool F5 = Keyboard[Key.F5];
                if (F5 && !prevF5)
                {
                    if (state == GameState.Playing)
                    {
                        textureLoader.GrabScreenshot();
                    }
                }
                prevF5 = F5;

                // call scene tree to update
                mScene.update();
            }
            else if (state == GameState.Started)
            {
                //search for related files
                FileSeeker mFileSeeker = new FileSeeker(this);

                //create framebufferset for waterreflections
                waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5));

                RenderOptions mOptionsWater = new RenderOptions(virtual_size);
                mOptionsWater.postProcessing = true;
                mOptionsWater.ssAmbientOccluison = false;
                mOptionsWater.bloom = false;
                mOptionsWater.depthOfField = false;

                waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater);

                //crate shadow framebuffer
                shadowFramebuffer = framebufferCreator.createFrameBuffer("shadowFramebuffer", mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false);

                //create main framebufferset
                RenderOptions mOptions = new RenderOptions(virtual_size);
                mOptions.postProcessing = true;
                mOptions.ssAmbientOccluison = true;
                mOptions.bloom = true;
                //mOptions.depthOfField = true;

                mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions);

                state = GameState.InitLoading;

            }
            else if (state == GameState.InitLoading)
            {
                //loading rutine - loads one object each time its called
                float percentageA = 0;
                float percentageB = 0;
                float percentageC = 0;
                float percentageD = 0;
                float percentageE = 0;

                percentageA = meshLoader.loadSingleMeshes();
                if (percentageA == 1)
                {
                    percentageB = shaderLoader.loadSingleShaders();
                }
                if (percentageB == 1)
                {
                    percentageC = textureLoader.loadSingleTextures();
                }
                if (percentageC == 1)
                {
                    percentageD = materialLoader.loadSingleMaterials();
                }
                if (percentageD == 1)
                {
                    percentageE = templateLoader.loadSingleTemplates();
                }

                loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f;

                //loadingPercentage = (float)Math.Sqrt(loadingPercentage);

                if (loadingPercentage == 1)
                {
                    //create cubemap buffers
                    mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128);
                    mScene.envTextures = mCubemapBufferSets.outTextures;

                    // create viewInfo for reflection
                    waterViewInfo = new ViewInfo();
                    waterViewInfo.aspect = (float)Width / (float)Height;
                    waterViewInfo.updateProjectionMatrix();

                    //set noise texture
                    mScene.noiseTexture = textureLoader.getTexture("noise_pixel.png");

                    //set shaders for postprocessing
                    mScene.ssaoShader = shaderLoader.getShader("ssao.xsp");
                    mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp");
                    mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp");
                    mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp");
                    mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp");
                    mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp");
                    mScene.dofShader = shaderLoader.getShader("dof_shader.xsp");
                    mScene.compositeShader = shaderLoader.getShader("composite.xsp");
                    mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp");
                    mScene.normalShader = shaderLoader.getShader("ssnormals.xsp");
                    mScene.selectionShader = shaderLoader.getShader("selection.xsp");
                    mScene.copycatShader = shaderLoader.getShader("backdrop.xsp");
                    mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp");

                    // spawn the player
                    player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput);
                    mScene.sunLight.Parent = player;
                    //player.setInput(gameInput);

                    mScene.init();

                    // load objects saved in database
                    mScene.loadObjects();

                    mScene.selectionShader = shaderLoader.getShader("selection.xsp");
                    mScene.ssNormalShader = shaderLoader.getShader("ssnormals.xsp");
                    mScene.ssNormalShaderNoTex = shaderLoader.getShader("ssnormals_notex.xsp");

                    state = GameState.Playing;
                }

            }
        }
示例#4
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--");
        }
示例#5
0
        public bool drawSceene(Pass currentPass, ViewInfo curView)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            if (currentPass == Pass.diffuse)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    if ((curDrawable.renderlayer == RenderLayer.Solid) ||
                        (curDrawable.renderlayer == RenderLayer.Both))
                    {
                        curDrawable.draw(curView, false);
                    }
                }
            }

            if (currentPass == Pass.transparent)
            {
                GL.Enable(EnableCap.Blend);
                /*
                for (int i = drawables.Count - 1; i >= 0; i--)
                {
                    if ((drawables[i].renderlayer == RenderLayer.Transparent)||
                        (drawables[i].renderlayer == RenderLayer.Both))
                    {
                        drawables[i].draw(curView, true);
                    }
                }
                 * */
                foreach (Drawable curDrawable in drawables)
                {
                    if ((curDrawable.renderlayer == RenderLayer.Transparent) ||
                        (curDrawable.renderlayer == RenderLayer.Both))
                    {
                        curDrawable.draw(curView, true);
                    }
                }
                GL.Disable(EnableCap.Blend);
            }

            if (currentPass == Pass.shadow)
            {
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawShadow(curView);
                }
            }

            if (currentPass == Pass.selection)
            {
                bool hasSelection = false;
                foreach (Drawable curDrawable in drawables)
                {
                    if (curDrawable.selectedSmooth > 0.01)
                    {
                        curDrawable.drawSelection(curView);
                        hasSelection = true;
                    }
                }
                return hasSelection;
            }

            if (currentPass == Pass.normal)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawNormal(curView);
                }
            }

            if (currentPass == Pass.defInfo)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawDefInfo(curView);
                }
            }

            GL.DepthMask(true);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            return false;
        }
示例#6
0
        protected override void OnUpdateFrame(FrameEventArgs e)
        {
            if (state == GameState.Playing || state == GameState.Menu)
            {
                // calculate mouse movement
                //gameInput.calcDelta();

                // calculate frame Times
                frameTime        += (float)e.Time;
                lastFrameDuration = (float)e.Time;

                // exit game?
                bool ESC = Keyboard[Key.Escape];
                if (ESC && !prevESC)
                {
                    if (state == GameState.Menu)
                    {
                        exitGame();
                    }
                    if (state == GameState.Playing)
                    {
                        enterMenu();
                    }
                }
                prevESC = ESC;

                bool F5 = Keyboard[Key.F5];
                if (F5 && !prevF5)
                {
                    if (state == GameState.Playing)
                    {
                        textureLoader.GrabScreenshot();
                    }
                }
                prevF5 = F5;



                // call scene tree to update
                mScene.update();
            }
            else if (state == GameState.Started)
            {
                //search for related files
                FileSeeker mFileSeeker = new FileSeeker(this);

                //create framebufferset for waterreflections
                waterFramebuffer = framebufferCreator.createFrameBuffer("waterFramebuffer", (int)(virtual_size.X * 0.5), (int)(virtual_size.Y * 0.5));

                RenderOptions mOptionsWater = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.water);

                waterFramebufferSet = new FramebufferSet(framebufferCreator, waterFramebuffer, mOptionsWater);

                //crate shadow framebuffer
                shadowFramebuffer = framebufferCreator.createFrameBuffer(mScene.ShadowRes, mScene.ShadowRes, PixelInternalFormat.Rgba16f, false);

                //create main framebufferset
                RenderOptions mOptions = Settings.Instance.video.CreateRenderOptions(VideoSettings.Target.main);

                mainFramebufferSet = new FramebufferSet(framebufferCreator, framebufferCreator.defaultFb, mOptions);

                state = GameState.InitLoading;
            }
            else if (state == GameState.InitLoading)
            {
                //loading rutine - loads one object each time its called
                float percentageA = 0;
                float percentageB = 0;
                float percentageC = 0;
                float percentageD = 0;
                float percentageE = 0;

                percentageA = meshLoader.loadSingleMeshes();
                if (percentageA == 1)
                {
                    percentageB = shaderLoader.loadSingleShaders();
                }
                if (percentageB == 1)
                {
                    percentageC = textureLoader.loadSingleTextures();
                }
                if (percentageC == 1)
                {
                    percentageD = materialLoader.loadSingleMaterials();
                }
                if (percentageD == 1)
                {
                    percentageE = templateLoader.loadSingleTemplates();
                }

                loadingPercentage = (percentageA + percentageB + percentageC + percentageD + percentageE) / 5f;

                //loadingPercentage = (float)Math.Sqrt(loadingPercentage);

                if (loadingPercentage == 1)
                {
                    //cache results
                    if (Settings.Instance.game.generateCache)
                    {
                        meshLoader.writeCacheFile();
                        shaderLoader.writeCacheFile();
                        //textureLoader.writeCacheFile();
                        materialLoader.writeCacheFile();
                        templateLoader.writeCacheFile();
                    }

                    //create cubemap buffers
                    mCubemapBufferSets = new CubemapBufferSets(mScene, framebufferCreator, 128);
                    mScene.envTextures = mCubemapBufferSets.outTextures;

                    // create viewInfo for reflection
                    waterViewInfo        = new ViewInfo();
                    waterViewInfo.aspect = (float)Width / (float)Height;
                    waterViewInfo.updateProjectionMatrix();

                    //set noise texture
                    mScene.setTextureId(Material.WorldTexture.noise, textureLoader.getTextureId("noise_pixel.png"));

                    //set shaders for postprocessing

                    /* now managed
                     * mScene.ssaoPreShader = shaderLoader.getShader("ssMaker.xsp");
                     * mScene.ssaoShader = shaderLoader.getShader("ssao.xsp");
                     * mScene.ssaoBlrShader = shaderLoader.getShader("ao_blur.xsp");
                     * mScene.ssaoBlrShaderA = shaderLoader.getShader("ao_blur_a.xsp");
                     * mScene.bloomCurveShader = shaderLoader.getShader("bloom_curve.xsp");
                     * mScene.bloomShader = shaderLoader.getShader("bloom_shader.xsp");
                     * mScene.dofpreShader = shaderLoader.getShader("dof_preshader.xsp");
                     * mScene.dofShader = shaderLoader.getShader("dof_shader.xsp");
                     * mScene.compositeShader = shaderLoader.getShader("composite.xsp");
                     * mScene.ssaoBlendShader = shaderLoader.getShader("ssao_blend.xsp");
                     * mScene.copycatShader = shaderLoader.getShader("backdrop.xsp");
                     * mScene.wipingShader = shaderLoader.getShader("sMapWipe.xsp");
                     * mScene.reflectionShader = shaderLoader.getShader("defReflections.xsp");
                     * mScene.lightBlurShader = shaderLoader.getShader("lightBlur.xsp");
                     */

                    // managed setup of shaders
                    mScene.setupShaders();

                    // spawn the player
                    player = new Player(mScene, new Vector3(0, 3, 10), new Vector3(0, 0, -1), gameInput);

                    mScene.init();
                    mScene.sunLight.Parent = player;

                    // load objects saved in database
                    mScene.loadObjects();

                    state = GameState.Playing;
                }
            }
        }
示例#7
0
        internal void draw(FramebufferSet curFramebuffers, ViewInfo curView)
        {
            gameWindow.checkGlError("--uncaught ERROR entering Scene--");

            RenderOptions renderOptions = curFramebuffers.renderOptions;

            if (renderOptions.postProcessing)
            {
                GL.Enable(EnableCap.Blend);

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

                GL.Enable(EnableCap.Blend);

                drawSceene(Scene.NORMALPASS, curView);

                GL.Disable(EnableCap.Blend);

                if (renderOptions.ssAmbientOccluison)
                {
                    curFramebuffers.aoFramebuffer.enable(false);
                    mFilter2d.draw(ssaoShader, new int[] { curFramebuffers.sceeneFramebuffer.ColorTexture, noiseTexture });

                    GL.Disable(EnableCap.Blend);
                    curFramebuffers.aoBlurFramebuffer.enable(false);
                    mFilter2d.draw(ssaoBlrShaderA, new int[] { curFramebuffers.aoFramebuffer.ColorTexture, noiseTexture, curFramebuffers.aoBlurFramebuffer2.ColorTexture});

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

                curFramebuffers.sceeneFramebuffer.enable(false);

                GL.Disable(EnableCap.Blend);

                drawSceene(Scene.NULLPASS, curView);

                GL.Enable(EnableCap.Blend);

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

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

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

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

                drawSceene(Scene.TRANSPARENTPASS, curView);

                curFramebuffers.selectionFb.enable(true);

                bool hasSelection = drawSceene(Scene.SELECTIONPASS, curView);

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

                Vector2 bloomSize = new Vector2(80, 20);

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

                curFramebuffers.selectionblurFb2.enable(true);

                if (hasSelection)
                    mFilter2d.draw(bloomShader, new int[] { curFramebuffers.selectionblurFb.ColorTexture }, bloomSize*0.2f);

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

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

                        curFramebuffers.bloomFramebuffer2.enable(false);
                        mFilter2d.draw(bloomShader, new int[] { curFramebuffers.bloomFramebuffer.ColorTexture }, bloomSize * 0.2f);

                        bloomSize *= 2f;
                    }
                }
                curFramebuffers.bloomFramebuffer2.Multisampeling = true;

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

                    curFramebuffers.dofFramebuffer.enable(false);
                    mFilter2d.draw(dofShader, new int[] { curFramebuffers.dofPreFramebuffer.ColorTexture, noiseTexture });

                    curFramebuffers.dofFramebuffer2.enable(false);
                    mFilter2d.draw(dofShader, new int[] { curFramebuffers.dofFramebuffer.ColorTexture, noiseTexture });
                }

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

                mFilter2d.draw(compositeShader, new int[] {
                curFramebuffers.sceeneFramebuffer.ColorTexture,
                curFramebuffers.bloomFramebuffer2.ColorTexture,
                curFramebuffers.selectionFb.ColorTexture,
                curFramebuffers.selectionblurFb2.ColorTexture,
                curFramebuffers.dofFramebuffer2.ColorTexture,
                curFramebuffers.aoBlurFramebuffer2.ColorTexture});

                gameWindow.checkGlError("--uncaught ERROR leaving Scene--");
            }
            else
            {
                gameWindow.checkGlError("--uncaught ERROR entering Scene--");
                curFramebuffers.outputFb.enable(true);

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

                drawSceene(Scene.NULLPASS, curView);

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

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

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

                drawSceene(Scene.TRANSPARENTPASS, curView);

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

                gameWindow.checkGlError("--uncaught ERROR leaving Scene--");
            }
        }
示例#8
0
        public bool drawSceene(int currentPass, ViewInfo curView)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            if (currentPass == NULLPASS)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.draw(curView,false);
                }
            }

            if (currentPass == TRANSPARENTPASS)
            {
                GL.Enable(EnableCap.Blend);

                for (int i = drawables.Count - 1; i >= 0; i--)
                {
                    drawables[i].draw(curView, true);
                }
            }

            if (currentPass == SHADOWPASS)
            {
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawShadow(curView);
                }
            }

            if (currentPass == SELECTIONPASS)
            {
                bool hasSelection = false;
                foreach (Drawable curDrawable in drawables)
                {
                    if (curDrawable.selectedSmooth > 0.01)
                    {
                        curDrawable.drawSelection(curView);
                        hasSelection = true;
                    }
                }
                return hasSelection;
            }

            if (currentPass == NORMALPASS)
            {
                GL.Disable(EnableCap.Blend);
                Shader SSNormalShader = ssNormalShader;

                mGroundPlane.draw(curView,ssNormalShaderNoTex);

                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawNormal(curView);
                }
            }

            GL.DepthMask(true);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            return false;
        }
示例#9
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--");
        }
示例#10
0
        public bool drawSceene(Pass currentPass, ViewInfo curView)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            if (currentPass == Pass.diffuse)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    if ((curDrawable.renderlayer == RenderLayer.Solid) ||
                        (curDrawable.renderlayer == RenderLayer.Both))
                    {
                        curDrawable.draw(curView, false);
                    }
                }
            }

            if (currentPass == Pass.transparent)
            {
                GL.Enable(EnableCap.Blend);

                /*
                 * for (int i = drawables.Count - 1; i >= 0; i--)
                 * {
                 *  if ((drawables[i].renderlayer == RenderLayer.Transparent)||
                 *      (drawables[i].renderlayer == RenderLayer.Both))
                 *  {
                 *      drawables[i].draw(curView, true);
                 *  }
                 * }
                 * */
                foreach (Drawable curDrawable in drawables)
                {
                    if ((curDrawable.renderlayer == RenderLayer.Transparent) ||
                        (curDrawable.renderlayer == RenderLayer.Both))
                    {
                        curDrawable.draw(curView, true);
                    }
                }
                GL.Disable(EnableCap.Blend);
            }

            if (currentPass == Pass.shadow)
            {
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawShadow(curView);
                }
            }

            if (currentPass == Pass.selection)
            {
                bool hasSelection = false;
                foreach (Drawable curDrawable in drawables)
                {
                    if (curDrawable.selectedSmooth > 0.01)
                    {
                        curDrawable.drawSelection(curView);
                        hasSelection = true;
                    }
                }
                return(hasSelection);
            }

            if (currentPass == Pass.normal)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawNormal(curView);
                }
            }

            if (currentPass == Pass.defInfo)
            {
                GL.Disable(EnableCap.Blend);
                foreach (Drawable curDrawable in drawables)
                {
                    curDrawable.drawDefInfo(curView);
                }
            }

            GL.DepthMask(true);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            return(false);
        }