コード例 #1
0
ファイル: Program.cs プロジェクト: Metapyziks/ultraSandbox
        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;
                }

            }
        }
コード例 #2
0
ファイル: Scene.cs プロジェクト: Richy19/ultraSandbox
        public void init()
        {
            sunLight = new LightSun(new Vector3(0.1f, 0.125f, 0.2f) * 3f, this);
            sunLight.lightAmbient = new Vector3(0.1f, 0.125f, 0.2f) * 0.5f;//new Vector3(0.2f, 0.125f, 0.1f);//new Vector3(0.1f, 0.14f, 0.3f);
            sunLight.PointingDirection = Vector3.Normalize(new Vector3(674, -674, 1024));
            sunFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false);
            sunInnerFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false);

            mFilter2d = new Quad2d(this);

            mSkyModel = new Skybox(this, gameWindow);

            mGroundPlane = new GroundPlane(this);
            mGroundPlane.setMaterial("floor.xmf");

            mGroundPlane.setMesh("water_plane.obj");
            mGroundPlane.setMaterial("floor.xmf");

            //need to be fixed -- cant be executed after voxel Manager creation.

            if(Settings.Instance.video.Particles)
                generateParticleSys();

            voxelManager = new VoxelManager(this);

            compositeMod.X = Settings.Instance.video.gamma;

            particleAffectors.Add(new ParticleAffectorWind(new Vector3(1,-0.5f,0) * 0.01f));
            particleAffectors.Add(new ParticleAffectorFriction(0.1f));
            particleAffectors.Add(new ParticleAffectorFloorKiller(waterLevel));
            particleAffectors.Add(new ParticleAffectorLifeTimeKiller(this));

            /*
                waterModel.setTextures(mTextureLoader.fromMixed(new int[]{
                TextureGroup.TYPE_FRAMEBUFFER,
                TextureGroup.TYPE_FROMFILE},
                new string[] {
                    Convert.ToString(waterFramebuffer.ColorTexture),
                    "noise.png"}));
             */

            mGroundPlane.Position = new Vector3(0,waterLevel,0);
            //mGroundPlane.updateModelMatrix();

            Matrix4 translate = Matrix4.CreateTranslation(0, -waterLevel * 2, 0);
            Matrix4 invert = Matrix4.Scale(1, -1, 1);
            Matrix4.Mult(ref translate, ref invert, out mWaterMatrix);
        }
コード例 #3
0
ファイル: Scene.cs プロジェクト: Richy19/ultraSandbox
        internal void drawShadowBuffers(Framebuffer shadowFb)
        {
            shadowFb.enable(false);

            for (int i = 0; i < spotlights.Count; i++)
            {
                spotlights[i].lightId = i;

                bool needsUpdate = spotlights[i].viewInfo.checkForUpdates(drawables);
                currentLight = i;

                if (needsUpdate)
                {
                    Console.WriteLine(i + " -> updating Shadowbuffer");

                    GL.Disable(EnableCap.Blend);
                    GL.Enable(EnableCap.DepthTest);
                    GL.Disable(EnableCap.CullFace);
                    //GL.CullFace(CullFaceMode.Front);

                    GL.DepthFunc(DepthFunction.Always);
                    mFilter2d.draw(ShaderTypes.wipingShader, new int[] { spotlights[i].ProjectionTexture }, Shader.Uniform.in_vector, new Vector2(i, lightCount));
                    GL.DepthFunc(DepthFunction.Less);

                    GL.ColorMask(false, false, false, true);
                    drawSceene(Pass.shadow, spotlights[i].viewInfo);
                    GL.ColorMask(true, true, true, true);
                }
            }

            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            //GL.CullFace(CullFaceMode.Front);

            //"disable" writing to certain uv space
            int tmpLightCount = lightCount;
            lightCount = 1;
            currentLight = 0;

            if (sunLight.viewInfo.wasUpdated)
            {
                //generating wide range sun shadows
                sunFrameBuffer.enable(true);

                GL.ColorMask(false, false, false, false);
                drawSceene(Pass.shadow, sunLight.viewInfo);
                GL.ColorMask(true, true, true, true);
            }

            //generating short range sun shadows
            sunInnerFrameBuffer.enable(true);

            GL.ColorMask(false, false, false, false);
            drawSceene(Pass.shadow, sunLight.innerViewInfo);
            GL.ColorMask(true, true, true, true);

            //clean up
            lightCount = tmpLightCount;
        }
コード例 #4
0
 public FramebufferSet(FramebufferCreator mFramebufferCreator, Framebuffer outputFb, RenderOptions mOptions)
 {
     createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
 }
コード例 #5
0
        public Framebuffer createFrameBuffer(string name, int FboWidth, int FboHeight, PixelInternalFormat precision, bool multisampling)
        {
            int FboHandle;
            int ColorTexture;
            int DepthTexture;

            int sampling = 0;

            if (multisampling)
            {
                sampling = (int)TextureMinFilter.Linear;
            }
            else
            {
                sampling = (int)TextureMinFilter.Nearest;
            }

            // Create Color Tex
            GL.GenTextures(1, out ColorTexture);
            GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, precision, FboWidth, FboHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            // GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );


            // Create Depth Tex
            GL.GenTextures(1, out DepthTexture);
            GL.BindTexture(TextureTarget.Texture2D, DepthTexture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.DepthComponent32, FboWidth, FboHeight, 0, PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);
            // things go horribly wrong if DepthComponent's Bitcount does not match the main Framebuffer's Depth
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            // GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );

            // Create a FBO and attach the textures
            GL.Ext.GenFramebuffers(1, out FboHandle);

            #region Test for Error

            switch (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt))
            {
            case FramebufferErrorCode.FramebufferCompleteExt:
            {
                gameWindow.log("FBO: The framebuffer is complete and valid for rendering.");
                break;
            }

            case FramebufferErrorCode.FramebufferIncompleteAttachmentExt:
            {
                gameWindow.log("FBO: One or more attachment points are not framebuffer attachment complete. This could mean there’s no texture attached or the format isn’t renderable. For color textures this means the base format must be RGB or RGBA and for depth textures it must be a DEPTH_COMPONENT format. Other causes of this error are that the width or height is zero or the z-offset is out of range in case of render to volume.");
                break;
            }

            case FramebufferErrorCode.FramebufferIncompleteMissingAttachmentExt:
            {
                gameWindow.log("FBO: There are no attachments.");
                break;
            }

            /* case  FramebufferErrorCode.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
             *   {
             *       Console.WriteLine("FBO: An object has been attached to more than one attachment point.");
             *       break;
             *   }*/
            case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
            {
                gameWindow.log("FBO: Attachments are of different size. All attachments must have the same width and height.");
                break;
            }

            case FramebufferErrorCode.FramebufferIncompleteFormatsExt:
            {
                gameWindow.log("FBO: The color attachments have different format. All color attachments must have the same format.");
                break;
            }

            case FramebufferErrorCode.FramebufferIncompleteDrawBufferExt:
            {
                gameWindow.log("FBO: An attachment point referenced by GL.DrawBuffers() doesn’t have an attachment.");
                break;
            }

            case FramebufferErrorCode.FramebufferIncompleteReadBufferExt:
            {
                gameWindow.log("FBO: The attachment point referenced by GL.ReadBuffers() doesn’t have an attachment.");
                break;
            }

            case FramebufferErrorCode.FramebufferUnsupportedExt:
            {
                gameWindow.log("FBO: This particular FBO configuration is not supported by the implementation.");
                break;
            }

            default:
            {
                gameWindow.log("FBO: Status unknown. (yes, this is really bad.)");
                break;
            }
            }

            // using FBO might have changed states, e.g. the FBO might not support stereoscopic views or double buffering
            int[] queryinfo = new int[6];
            GL.GetInteger(GetPName.MaxColorAttachmentsExt, out queryinfo[0]);
            GL.GetInteger(GetPName.AuxBuffers, out queryinfo[1]);
            GL.GetInteger(GetPName.MaxDrawBuffers, out queryinfo[2]);
            GL.GetInteger(GetPName.Stereo, out queryinfo[3]);
            GL.GetInteger(GetPName.Samples, out queryinfo[4]);
            GL.GetInteger(GetPName.Doublebuffer, out queryinfo[5]);
            //Console.WriteLine("max. ColorBuffers: " + queryinfo[0] + " max. AuxBuffers: " + queryinfo[1] + " max. DrawBuffers: " + queryinfo[2] + "\nStereo: " + queryinfo[3] + " Samples: " + queryinfo[4] + " DoubleBuffer: " + queryinfo[5]);

            Console.WriteLine("Last GL Error: " + GL.GetError());

            #endregion Test for Error

            gameWindow.checkGlError("createFrameBuffer");

            Framebuffer myFramebuffer = new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(FboWidth, FboHeight), this);
            myFramebuffer.Name = name;

            if (name != null)
            {
                registerFramebuffer(myFramebuffer);
            }

            return(myFramebuffer);
        }
コード例 #6
0
 public FramebufferCreator(OpenTkProjectWindow gameWindow)
 {
     this.gameWindow = gameWindow;
     //defaultFb = createFrameBuffer( mGameWindow.Width, mGameWindow.Height);
     defaultFb = new DefaultFramebuffer(new Vector2(gameWindow.Width, gameWindow.Height), this);
 }
コード例 #7
0
        public FramebufferSet(FramebufferCreator mFramebufferCreator, Vector2 size, Framebuffer outputFb)
        {
            RenderOptions mOptions = new RenderOptions(size);

            createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
        }
コード例 #8
0
ファイル: Scene.cs プロジェクト: Metapyziks/ultraSandbox
        /*
        public Model
            BloomViewboard,
            BloomViewboard2,
            CompositeViewboard,
            AoViewboard,
            AoBlrViewboard;
         */
        public Scene(OpenTkProjectWindow mGameWindow)
        {
            this.gameWindow = mGameWindow;
            Scene = this;

            sunLight = new LightSun(new Vector3(0.1f, 0.125f, 0.2f) * 3f, this);
            sunLight.lightAmbient = new Vector3(0.1f, 0.125f, 0.2f) * 0.5f;//new Vector3(0.2f, 0.125f, 0.1f);//new Vector3(0.1f, 0.14f, 0.3f);
            sunLight.PointingDirection = Vector3.Normalize(new Vector3(674, -674, 1024));
            sunFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false);
            sunInnerFrameBuffer = gameWindow.framebufferCreator.createFrameBuffer("shadowFramebuffer", shadowRes * 2, shadowRes * 2, PixelInternalFormat.Rgba8, false);

            //sunLight.pointingDirection = Vector3.Normalize(new Vector3(674, 674, 1024));

            // creating a new collision system and adding it to the new world
            CollisionSystem collisionSystem = new CollisionSystemSAP();
            world = new World(collisionSystem);

            // Create the groundShape and the body.
            Shape groundShape = new BoxShape(new JVector(100, waterLevel * 2, 100));
            RigidBody groundBody = new RigidBody(groundShape);

            // make the body static, so it can't be moved
            groundBody.IsStatic = true;

            // add the ground to the world.
            world.AddBody(groundBody);
        }
コード例 #9
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;
                }
            }
        }
コード例 #10
0
        private void createFramebufferSet(FramebufferCreator mFramebufferCreator, Framebuffer outputFb, RenderOptions mOptions)
        {
            Vector2 size = mOptions.size;
            Vector2 size2 = size * mOptions.quality;
            Vector2 size3 = size2 * 0.3f;

            //sceeneFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y);
            sceeneFramebufferTrans = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba8, false);

            if (mOptions.postProcessing)
            {
                sceeneFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba16f, false);
                sceeneFramebuffer.clearColor = new Color4(0f, 0f, 0f, 100f);

                selectionFb = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba8, false);

                //screenNormalFb = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba16f, false);
                //screenNormalFb.clearColor = new Color4(0f, 0f, 0f, 100f);
                //lightFramebuffer = mFramebufferCreator.createFrameBuffer((int)size.X, (int)size.Y, PixelInternalFormat.Rgba16f, false);

                if (mOptions.depthOfField)
                {
                    // depth of field buffers
                    dofPreFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
                    dofFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
                }

                dofFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, true);

                aoBlurFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, true);
                aoBlurFramebuffer2.clearColor = new Color4(0f, 0f, 0f, 0.5f);

                if (mOptions.ssAmbientOccluison)
                {
                    aoFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
                    aoBlurFramebuffer = mFramebufferCreator.createFrameBuffer((int)size2.X, (int)size2.Y, PixelInternalFormat.Rgba8, false);
                } else {
                    // if ao is set of make the buffer grey
                    //aoBlurFramebuffer2.enable();
                }

                selectionblurFb = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
                selectionblurFb2 = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, true);
                bloomFramebuffer = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
                bloomFramebuffer2 = mFramebufferCreator.createFrameBuffer((int)size3.X, (int)size3.Y, PixelInternalFormat.Rgba8, false);
            }
            renderOptions = mOptions;
            this.outputFb = outputFb;
        }
コード例 #11
0
ファイル: Scene.cs プロジェクト: scifiboi/ultraSandbox
        internal void drawShadowBuffers(Framebuffer shadowFb)
        {
            shadowFb.enable(false);

            for (int i = 0; i < spotlights.Count; i++)
            {
                spotlights[i].lightId = i;

                bool needsUpdate = spotlights[i].viewInfo.checkForUpdates(drawables);
                currentLight = i;

                if (needsUpdate)
                {
                    Console.WriteLine(i + " -> updating Shadowbuffer");

                    GL.Disable(EnableCap.Blend);
                    GL.Enable(EnableCap.DepthTest);
                    GL.Disable(EnableCap.CullFace);
                    //GL.CullFace(CullFaceMode.Front);

                    GL.DepthFunc(DepthFunction.Always);
                    mFilter2d.draw(ShaderTypes.wipingShader, new int[] { spotlights[i].ProjectionTexture }, Shader.Uniform.in_vector, new Vector2(i, lightCount));
                    GL.DepthFunc(DepthFunction.Less);

                    GL.ColorMask(false, false, false, true);
                    drawSceene(Pass.shadow, spotlights[i].viewInfo);
                    GL.ColorMask(true, true, true, true);
                }
            }

            GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.CullFace);
            //GL.CullFace(CullFaceMode.Front);

            //"disable" writing to certain uv space
            int tmpLightCount = lightCount;

            lightCount   = 1;
            currentLight = 0;

            if (sunLight.viewInfo.wasUpdated)
            {
                //generating wide range sun shadows
                sunFrameBuffer.enable(true);

                GL.ColorMask(false, false, false, false);
                drawSceene(Pass.shadow, sunLight.viewInfo);
                GL.ColorMask(true, true, true, true);
            }


            //generating short range sun shadows
            sunInnerFrameBuffer.enable(true);

            GL.ColorMask(false, false, false, false);
            drawSceene(Pass.shadow, sunLight.innerViewInfo);
            GL.ColorMask(true, true, true, true);


            //clean up
            lightCount = tmpLightCount;
        }
コード例 #12
0
 public FramebufferSet(FramebufferCreator mFramebufferCreator, Framebuffer outputFb, RenderOptions mOptions)
 {
     createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
 }
コード例 #13
0
 public FramebufferSet(FramebufferCreator mFramebufferCreator, Vector2 size, Framebuffer outputFb)
 {
     RenderOptions mOptions = new RenderOptions(size);
     createFramebufferSet(mFramebufferCreator, outputFb, mOptions);
 }
コード例 #14
0
        private void registerFramebuffer(Framebuffer newFb)
        {
            Framebuffers.Add(newFb);

            int identifier = Framebuffers.Count;
            if (FramebufferNames.ContainsKey(newFb.name))
                FramebufferNames.Remove(newFb.name);

            FramebufferNames.Add(newFb.name, identifier);

            gameWindow.textureLoader.fromFramebuffer(newFb.name + "color", newFb.ColorTexture);
        }
コード例 #15
0
        public void createLightBuffer(string name, int size, bool multisampling)
        {
            int FboHandle;
            int ColorTexture;
            int DepthTexture;

            int sampling = 0;
            if (multisampling)
            {
                sampling = (int)TextureMinFilter.Linear;
            }
            else
            {
                sampling = (int)TextureMinFilter.Nearest;
            }
              /*
            // Create Color Tex
            GL.GenTextures(1, out ColorTexture);
            GL.BindTexture(TextureTarget.Texture2D, ColorTexture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, precision, size, size, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
            // GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );
            */

            // Create Depth Tex
            GL.GenTextures(1, out DepthTexture);
            GL.BindTexture(TextureTarget.Texture2D, DepthTexture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)All.DepthComponent32, size, size, 0, PixelFormat.DepthComponent, PixelType.UnsignedInt, IntPtr.Zero);
            // things go horribly wrong if DepthComponent's Bitcount does not match the main Framebuffer's Depth
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, sampling);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder);
            // GL.Ext.GenerateMipmap( GenerateMipmapTarget.Texture2D );

            // Create a FBO and attach the textures
            GL.Ext.GenFramebuffers(1, out FboHandle);

            #region Test for Error

            switch (GL.Ext.CheckFramebufferStatus(FramebufferTarget.FramebufferExt))
            {
                case FramebufferErrorCode.FramebufferCompleteExt:
                    {
                        gameWindow.log("FBO: The framebuffer is complete and valid for rendering.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferIncompleteAttachmentExt:
                    {
                        gameWindow.log("FBO: One or more attachment points are not framebuffer attachment complete. This could mean there’s no texture attached or the format isn’t renderable. For color textures this means the base format must be RGB or RGBA and for depth textures it must be a DEPTH_COMPONENT format. Other causes of this error are that the width or height is zero or the z-offset is out of range in case of render to volume.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferIncompleteMissingAttachmentExt:
                    {
                        gameWindow.log("FBO: There are no attachments.");
                        break;
                    }
                /* case  FramebufferErrorCode.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT:
                     {
                         Console.WriteLine("FBO: An object has been attached to more than one attachment point.");
                         break;
                     }*/
                case FramebufferErrorCode.FramebufferIncompleteDimensionsExt:
                    {
                        gameWindow.log("FBO: Attachments are of different size. All attachments must have the same width and height.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferIncompleteFormatsExt:
                    {
                        gameWindow.log("FBO: The color attachments have different format. All color attachments must have the same format.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferIncompleteDrawBufferExt:
                    {
                        gameWindow.log("FBO: An attachment point referenced by GL.DrawBuffers() doesn’t have an attachment.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferIncompleteReadBufferExt:
                    {
                        gameWindow.log("FBO: The attachment point referenced by GL.ReadBuffers() doesn’t have an attachment.");
                        break;
                    }
                case FramebufferErrorCode.FramebufferUnsupportedExt:
                    {
                        gameWindow.log("FBO: This particular FBO configuration is not supported by the implementation.");
                        break;
                    }
                default:
                    {
                        gameWindow.log("FBO: Status unknown. (yes, this is really bad.)");
                        break;
                    }
            }

            // using FBO might have changed states, e.g. the FBO might not support stereoscopic views or double buffering
            int[] queryinfo = new int[6];
            GL.GetInteger(GetPName.MaxColorAttachmentsExt, out queryinfo[0]);
            GL.GetInteger(GetPName.AuxBuffers, out queryinfo[1]);
            GL.GetInteger(GetPName.MaxDrawBuffers, out queryinfo[2]);
            GL.GetInteger(GetPName.Stereo, out queryinfo[3]);
            GL.GetInteger(GetPName.Samples, out queryinfo[4]);
            GL.GetInteger(GetPName.Doublebuffer, out queryinfo[5]);
            //Console.WriteLine("max. ColorBuffers: " + queryinfo[0] + " max. AuxBuffers: " + queryinfo[1] + " max. DrawBuffers: " + queryinfo[2] + "\nStereo: " + queryinfo[3] + " Samples: " + queryinfo[4] + " DoubleBuffer: " + queryinfo[5]);

            Console.WriteLine("Last GL Error: " + GL.GetError());

            #endregion Test for Error

            gameWindow.checkGlError("createFrameBuffer");

            int identifier = Framebuffers.Count;

            ColorTexture = 0;

            Framebuffer myFramebuffer = new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(size, size), this);

            gameWindow.textureLoader.fromFramebuffer(name + "light", myFramebuffer.DepthTexture);

            Framebuffers.Add(myFramebuffer);
            FramebufferNames.Add(name, identifier);

            //return new Framebuffer(FboHandle, ColorTexture, DepthTexture, new Vector2(FboWidth, FboHeight), mGameWindow);
        }
コード例 #16
0
 public FramebufferCreator(OpenTkProjectWindow gameWindow)
 {
     this.gameWindow = gameWindow;
     //defaultFb = createFrameBuffer( mGameWindow.Width, mGameWindow.Height);
     defaultFb = new DefaultFramebuffer(new Vector2(gameWindow.Width, gameWindow.Height), this);
 }