Example #1
0
        public static void Create(FBO fbo, string lightMaskFileName)
        {
            if (Settings.DisableShadowMapping)
            {
                UseShadowMapping = false;
                return;
            }

            if (FBO.IsSupported == false)
            {
                Log.WriteLine("FBOs not supported so no shadow mapping.");
                UseShadowMapping = false;
                return;
            }

            ShadowMapping.fbo = fbo;
            UseShadowMapping = true;
            TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;
            try
            {
                lightMask = Texture.Load(lightMaskFileName);
            }
            catch (Exception) { } // skipataan valitukset jos tiedostoa ei löydy
            TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat;
            depthShader = GLSLShader.Load("depth.shader");
            depthShaderAlphaTest = GLSLShader.Load("depth.shader:ALPHATEST");
        }
Example #2
0
        public override void Init()
        {
            depthFBO = new FBO(0, 0, 1, true);
            ShadowMapping.Create(depthFBO, "lightmask.png");

            font = BitmapFont.Load("fonts/comic12.png");

            skybox = Sky.Load("sky/sky_", "jpg");
            world.Add(skybox);

            GLSLShader.SetShader("shadowmapping.shader", "SHADOWS");
            DotScene ds = DotScene.Load("scene1/scene1.scene", scene);

            world.Add(scene);

            actors[0] = AnimatedModel.Load("ugly/ukko.mesh");
            actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim");
            actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim");
            actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim");
            actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim");
            actors[0].SetAnimation("act2"); // idle anim
            actors[0].Scale = new Vector3(5, 5, 5);
            world.Add(actors[0]);

            lightImg = Billboard.Load("lightimg.png");

            Camera.Set3D();
            base.Init();
        }
Example #3
0
        public override void Init()
        {
            depthFBO = new FBO(0, 0, 1, true);
            ShadowMapping.Create(depthFBO, "lightmask.png");

            font = BitmapFont.Load("fonts/comic12.png");

            skybox = Sky.Load("sky/sky_", "jpg");
            world.Add(skybox);

            GLSLShader.SetShader("shadowmapping.shader", "SHADOWS");
            DotScene ds = DotScene.Load("scene1/scene1.scene", scene);
            world.Add(scene);

            actors[0] = AnimatedModel.Load("ugly/ukko.mesh");
            actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim");
            actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim");
            actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim");
            actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim");
            actors[0].SetAnimation("act2"); // idle anim
            actors[0].Scale = new Vector3(5, 5, 5);
            world.Add(actors[0]);

            lightImg = Billboard.Load("lightimg.png");

            Camera.Set3D();
            base.Init();
        }
Example #4
0
        public void RenderSceneWithParticles(FBO destination)
        {
            if (Particles.SoftParticles)
            {
                if (destination.ColorTextures.Length < 2)
                {
                    Log.Error("RenderSceneWithParticles: fbo must have at least 2 colorbuffers.");
                }

                // rendaa skenen depth colorbufferiin, ei textureita/materiaaleja
                destination.BindFBO();
                {
                    // TODO rendaa vain zbufferiin, tsekkaa miten se on tehty shadowmappingissa
                    //GL.Disable(EnableCap.Blend);
                    //GL.ColorMask(false, false, false, false);
                    //GL.Disable(EnableCap.CullFace);

                    GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
                    GL.DrawBuffer(DrawBufferMode.ColorAttachment1);

                    GL.ClearColor(float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue);
                    destination.Clear();
                    GL.ClearColor(0.0f, 0.0f, 0.1f, 0);
                    VBO.FastRenderPass = true;
                    Particles.SetDepthProgram();
                    Render();
                    VBO.FastRenderPass = false;

                    // TODO rendaa vain zbufferiin, tsekkaa miten se on tehty shadowmappingissa
                    //GL.Enable(EnableCap.Blend);
                    //GL.ColorMask(true, true, true, true);
                    //GL.Enable(EnableCap.CullFace);

                    // rendaa skene uudelleen textureineen
                    GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                    GL.DrawBuffer(DrawBufferMode.ColorAttachment0);

                    destination.Clear();
                    RenderAgain();

                    GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
                    destination.BindColorBuffer(1, Settings.DEPTH_TEXUNIT);
                    Particles.Render();
                    destination.UnBindColorBuffer(Settings.DEPTH_TEXUNIT);
                    GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                }
                destination.UnBindFBO();
            }
            else
            {
                // rendaa skene textureineen
                destination.BindFBO();
                {
                    destination.Clear();
                    Render();
                    Particles.Render();
                }
                destination.UnBindFBO();
            }
        }
Example #5
0
 public virtual void Dispose()
 {
     if (font != null)
     {
         font.Dispose();
     }
     if (colorFBO != null)
     {
         colorFBO.Dispose();
     }
     if (depthFBO != null)
     {
         depthFBO.Dispose();
     }
     if (skybox != null)
     {
         skybox.Dispose();
     }
     skybox           = null;
     colorFBO         = null;
     depthFBO         = null;
     font             = null;
     world            = null;
     Node.ObjectCount = 0;
     GLSLShader.UnBindShader();
     GLSLShader.SetShader("default.shader", "");
 }
Example #6
0
        public static void Create(FBO fbo, string lightMaskFileName)
        {
            if (Settings.DisableShadowMapping)
            {
                UseShadowMapping = false;
                return;
            }

            if (FBO.IsSupported == false)
            {
                Log.WriteLine("FBOs not supported so no shadow mapping.");
                UseShadowMapping = false;
                return;
            }

            ShadowMapping.fbo = fbo;
            UseShadowMapping  = true;
            TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;
            try
            {
                lightMask = Texture.Load(lightMaskFileName);
            }
            catch (Exception) { } // skipataan valitukset jos tiedostoa ei löydy
            TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat;
            TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat;
            depthShader          = GLSLShader.Load("depth.shader");
            depthShaderAlphaTest = GLSLShader.Load("depth.shader:ALPHATEST");
        }
Example #7
0
 /// <summary>
 /// screen fbo:ssa pitää olla vähintään 2 colorbufferia,
 /// ja 1. colorbufferissa pitää olla rendattu skene johon efektit halutaan.
 /// </summary>
 public static void Begin(FBO screen)
 {
     if (screen.ColorTextures.Length < 2) Log.Error("PostEffect: fbo must have at least 2 colorbuffers.");
     VBO.FastRenderPass = true;
     effCount = 0;
     destinationFbo = screen;
     screen.BindFBO();
 }
Example #8
0
        public void RenderSceneWithParticles(FBO destination)
        {
            if (Particles.SoftParticles)
            {
                if (destination.ColorTextures.Length < 2) Log.Error("RenderSceneWithParticles: fbo must have at least 2 colorbuffers.");

                // rendaa skenen depth colorbufferiin, ei textureita/materiaaleja
                destination.BindFBO();
                {
                    // TODO rendaa vain zbufferiin, tsekkaa miten se on tehty shadowmappingissa
                    //GL.Disable(EnableCap.Blend);
                    //GL.ColorMask(false, false, false, false);
                    //GL.Disable(EnableCap.CullFace);

                    GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
                    GL.DrawBuffer(DrawBufferMode.ColorAttachment1);

                    GL.ClearColor(float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue);
                    destination.Clear();
                    GL.ClearColor(0.0f, 0.0f, 0.1f, 0);
                    VBO.FastRenderPass = true;
                    Particles.SetDepthProgram();
                    Render();
                    VBO.FastRenderPass = false;

                    // TODO rendaa vain zbufferiin, tsekkaa miten se on tehty shadowmappingissa
                    //GL.Enable(EnableCap.Blend);
                    //GL.ColorMask(true, true, true, true);
                    //GL.Enable(EnableCap.CullFace);

                    // rendaa skene uudelleen textureineen
                    GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                    GL.DrawBuffer(DrawBufferMode.ColorAttachment0);

                    destination.Clear();
                    RenderAgain();

                    GL.ReadBuffer(ReadBufferMode.ColorAttachment1);
                    destination.BindColorBuffer(1, Settings.DEPTH_TEXUNIT);
                    Particles.Render();
                    destination.UnBindColorBuffer(Settings.DEPTH_TEXUNIT);
                    GL.ReadBuffer(ReadBufferMode.ColorAttachment0);
                }
                destination.UnBindFBO();
            }
            else
            {
                // rendaa skene textureineen
                destination.BindFBO();
                {
                    destination.Clear();
                    Render();
                    Particles.Render();
                }
                destination.UnBindFBO();
            }
        }
Example #9
0
 /// <summary>
 /// screen fbo:ssa pitää olla vähintään 2 colorbufferia,
 /// ja 1. colorbufferissa pitää olla rendattu skene johon efektit halutaan.
 /// </summary>
 public static void Begin(FBO screen)
 {
     if (screen.ColorTextures.Length < 2)
     {
         Log.Error("PostEffect: fbo must have at least 2 colorbuffers.");
     }
     VBO.FastRenderPass = true;
     effCount           = 0;
     destinationFbo     = screen;
     screen.BindFBO();
 }
Example #10
0
 public virtual void Dispose()
 {
     if (font != null) font.Dispose();
     if (colorFBO != null) colorFBO.Dispose();
     if (depthFBO != null) depthFBO.Dispose();
     if (skybox != null) skybox.Dispose();
     skybox = null;
     colorFBO = null;
     depthFBO = null;
     font = null;
     world = null;
     Node.ObjectCount = 0;
     GLSLShader.UnBindShader();
     GLSLShader.SetShader("default.shader", "");
 }
Example #11
0
        public override void Init()
        {
            colorFBO = new FBO(0, 0, 2, true); // 2 colorbufferia
            depthFBO = new FBO(0, 0, 0, true);
            blurH    = PostEffect.Load("blur.shader", "HORIZ");
            blurH.SetParameter("size", 1f / (float)colorFBO.Width);
            blurV = PostEffect.Load("blur.shader", "VERT");
            blurV.SetParameter("size", 1f / (float)colorFBO.Width);
            bloom = PostEffect.Load("bloom.shader", "");
            bloom.SetParameter("size", 0.001f);

            Particles.EnableSoftParticles();
            ShadowMapping.Create(depthFBO, "lightmask.png");

            font = BitmapFont.Load("fonts/comic12.png");

            skybox = Sky.Load("sky/sky2_", "jpg");
            world.Add(skybox);

            lightImg = Billboard.Load("lightimg.png");

            GLSLShader.SetShader("shadowmapping.shader", "SHADOWS");
            DotScene ds = DotScene.Load("scene1/scene1.scene", scene);

            world.Add(scene);

            actors[0] = AnimatedModel.Load("ugly/ukko.mesh");
            actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim");
            actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim");
            actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim");
            actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim");
            actors[0].SetAnimation("act2"); // idle anim
            actors[0].Position.Y = -0.5f;
            actors[0].Scale      = new Vector3(5, 5, 5);
            world.Add(actors[0]);

            explosion = Particles.Load("explosion.particles.xml", new ParticleCallback(RenderParticleCallback));
            smoke     = Particles.Load("smoke.particles.xml", null);
            actors[0].Add(smoke);

            Camera.Set3D();
            base.Init();
        }
Example #12
0
        public override void Init()
        {
            colorFBO = new FBO(0, 0, 2, true); // 2 colorbufferia
            depthFBO = new FBO(0, 0, 0, true);
            blurH = PostEffect.Load("blur.shader", "HORIZ");
            blurH.SetParameter("size", 1f / (float)colorFBO.Width);
            blurV = PostEffect.Load("blur.shader", "VERT");
            blurV.SetParameter("size", 1f / (float)colorFBO.Width);
            bloom = PostEffect.Load("bloom.shader", "");
            bloom.SetParameter("size", 0.001f);

            Particles.EnableSoftParticles();
            ShadowMapping.Create(depthFBO, "lightmask.png");

            font = BitmapFont.Load("fonts/comic12.png");

            skybox = Sky.Load("sky/sky2_", "jpg");
            world.Add(skybox);

            lightImg = Billboard.Load("lightimg.png");

            GLSLShader.SetShader("shadowmapping.shader", "SHADOWS");
            DotScene ds = DotScene.Load("scene1/scene1.scene", scene);
            world.Add(scene);

            actors[0] = AnimatedModel.Load("ugly/ukko.mesh");
            actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim");
            actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim");
            actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim");
            actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim");
            actors[0].SetAnimation("act2"); // idle anim
            actors[0].Position.Y = -0.5f;
            actors[0].Scale = new Vector3(5, 5, 5);
            world.Add(actors[0]);

            explosion = Particles.Load("explosion.particles.xml", new ParticleCallback(RenderParticleCallback));
            smoke = Particles.Load("smoke.particles.xml", null);
            actors[0].Add(smoke);

            Camera.Set3D();
            base.Init();
        }
Example #13
0
        public override void Init()
        {
            depthFBO = new FBO(0, 0, 1, true);
            ShadowMapping.Create(depthFBO, "lightmask.png");

            Fog.CreateFog(0.005f, Fog.Color);
            GLSLShader.SetShader("default.shader", "FOG");
            skybox = Sky.Load("sky/sky2_", "jpg");
            world.Add(skybox);

            GLSLShader.SetShader("default.shader", "LIGHTING:PERPIXEL:FOG");
            Model scene = new Model();
            DotScene ds = DotScene.Load("scene1/scene1.scene", scene);
            world.Add(scene);

            camPath = Path.GetPath("Path_camera");
            camPath.Attach(camera, true, true);

            font = BitmapFont.Load("fonts/comic12.png");

            Camera.Set3D();
            base.Init();
        }
Example #14
0
        public override void Init()
        {
            depthFBO = new FBO(0, 0, 1, true);
            ShadowMapping.Create(depthFBO, "lightmask.png");

            Fog.CreateFog(0.005f, Fog.Color);
            GLSLShader.SetShader("default.shader", "FOG");
            skybox = Sky.Load("sky/sky2_", "jpg");
            world.Add(skybox);

            GLSLShader.SetShader("default.shader", "LIGHTING:PERPIXEL:FOG");
            Model    scene = new Model();
            DotScene ds    = DotScene.Load("scene1/scene1.scene", scene);

            world.Add(scene);

            camPath = Path.GetPath("Path_camera");
            camPath.Attach(camera, true, true);

            font = BitmapFont.Load("fonts/comic12.png");

            Camera.Set3D();
            base.Init();
        }