Exemple #1
0
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        protected override void Startup()
        {
            Demo that = this;

            /*initial libraries*/
            this.Engine.Library.LoadLibrary("/Data/JSON/mech.json").Finished.Subscribe(MechLibraryComplete, false);
            this.Engine.Library.LoadLibrary("/Data/JSON/scene.json").Finished.Subscribe(InitLibraryComplete, false);

            //this.Engine.Graphics.Camera.Rotate((float) (Math.PI) + 0.5f, new Vector3(new float[] { 0.0f, 1.0f, 0.0f }));
            //this.Engine.Graphics.Camera.Translate(new Vector3(new float[] { 0.0f, 25.0f, 0.0f }));
            //this.Engine.Graphics.Camera.RotateY((float) (Math.PI / 2));
            //this.Engine.Graphics.Camera.RotateX(-0.5f);

            /*register update function*/
            this._updateHandle = SystemCore.Timer.Start(delegate { that.Update(); }, 1000 / 20, true);

            /*change view occluder to a faster region occluder*/
            this.Engine.Graphics.ViewOccluder = new RegionOccluder(25, 20);

            /*add post process effects*/
            this.Engine.Graphics.QueuePostProcess(this._bloomEffect = new BloomEffect());
            this.Engine.Graphics.QueuePostProcess(this._ssaoEffect = new SsaoEffect());
            this.Engine.Graphics.QueuePostProcess(this._depthEffect = new DepthEffect());
            this.Engine.Graphics.QueuePostProcess(this._motionEffect = new MotionBlurEffect());
        }
Exemple #2
0
        public IPostProcessEffect GetEffect(int key)
        {
            IPostProcessEffect effect = null;

            _ActiveEffects.TryGetValue(key, out effect);
            return(effect);
        }
Exemple #3
0
        public void RemoveEffect(IPostProcessEffect effect)
        {
            int key = -1;

            foreach (KeyValuePair <int, IPostProcessEffect> pair in _ActiveEffects)
            {
                if (ReferenceEquals(pair.Value, effect))
                {
                    key = pair.Key;
                    break;
                }
            }

            if (key != -1)
            {
                _EffectsToRemove.Enqueue(key);
            }
        }
Exemple #4
0
        public void BindForPostProcessEffects(IPostProcessEffect postProcess)
        {
            var shader          = postProcess.Shader;
            var generateMipMaps = postProcess.RequiresGBufferMipMaps;

            // generate mip maps for final texture, so it can be used in post processing effects, many post processing effects require blurred texture
            if (generateMipMaps)
            {
                /*GL.ActiveTexture(TextureUnit.Texture0);
                 * GL.BindTexture(TextureTarget.Texture2D, finalTextureToWriteTo.GetNativeTextureID()); My.Check();
                 * GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); My.Check();*/

                GL.ActiveTexture(TextureUnit.Texture0); MyGL.Check();
                GL.BindTexture(TextureTarget.Texture2D, FinalTextureToRead.GetNativeTextureID()); MyGL.Check();
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); MyGL.Check();
            }

            GL.Disable(EnableCap.DepthTest); MyGL.Check();
            GL.DepthMask(false); MyGL.Check();
            GL.CullFace(CullFaceMode.Back); MyGL.Check();

            GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, frameBufferObjectHandle); MyGL.Check();

            // draw to the one we are not reading
            if (readFirstFinalTexture == false)
            {
                GL.DrawBuffer(DrawBufferMode.ColorAttachment4); MyGL.Check();
            }
            else
            {
                GL.DrawBuffer(DrawBufferMode.ColorAttachment5); MyGL.Check();
            }

            shader.Uniforms.Set("gBufferUniform.depth", depthTexture);
            shader.Uniforms.Set("gBufferUniform.final", FinalTextureToRead);

            for (int i = 0; i < textures.Length - 2; i++)
            {
                shader.Uniforms.Set("gBufferUniform." + ((GBufferTextures)i).ToString().ToLower(), textures[i]);
            }

            readFirstFinalTexture = !readFirstFinalTexture;
        }
        //------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------
        public void QueuePostProcess(IPostProcessEffect effect)
        {
            int index = 0;

            if((index = this._effects.IndexOf(effect)) != -1)
                this._effects.RemoveAt(index);

            this._effects.Add(effect);

            effect.Init(this._diffuseGroup.RenderTexture, this._normalGroup.RenderTexture, this._positionGroup.RenderTexture,
                this._accumulationGroup.RenderTexture);

            effect.Reset(this);
        }
Exemple #6
0
 public void AddPostProcessEffect(IPostProcessEffect shader)
 {
     postProcessEffects.Add(shader);
 }
Exemple #7
0
 public void AddEffect(IPostProcessEffect effect, int priority)
 {
     _ActiveEffects.Add(priority, effect);
 }
Exemple #8
0
 public void AddEffect(IPostProcessEffect effect, PostProcessEffectType type)
 {
     _ActiveEffects.Add((int)type, effect);
 }