Ejemplo n.º 1
0
        public override void Render()
        {
            ShadowMapping.SetupShadows(world, 0, true);
            GL.Clear(ClearFlags);
            camera.SetFPSCamera();

            // render scene to colorFBO
            world.RenderSceneWithParticles(colorFBO);
            colorFBO.BindFBO();
            lightImg.RenderBillboard(Light.Lights[0].Position, 0, 100, true);
            colorFBO.UnBindFBO();

            Camera.Set2D();
            {
                PostEffect.Begin(colorFBO);
                if (Keyboard[Key.R])
                {
                    blurH.RenderEffect();
                    blurV.RenderEffect();
                }
                if (Keyboard[Key.T])
                {
                    bloom.RenderEffect();
                }

                PostEffect.End().DrawFullScreen(0, 0);
                font.Write("Soft particles + effects (press R / T)");
            }
            Camera.Set3D();

            base.Render();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
        public override void Render()
        {
            ShadowMapping.SetupShadows(world, 0, false);
            GL.Clear(ClearFlags);
            camera.SetCameraMatrix();
            world.Render();

            Camera.Set2D();
            font.Write(str);
            Camera.Set3D();

            base.Render();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// renderoi worldin valosta päin (pelkän depthin)
        /// </summary>
        public static void SetupShadows(Renderable world, int lightNo, bool withParticles)
        {
            if (UseShadowMapping == false)
            {
                return;
            }

            if (Light.Lights.Count == 0)
            {
                Log.WriteLine("SetupShadows requires at least one light source!", false);
                return;
            }
            GL.Disable(EnableCap.Blend);
            GL.ColorMask(false, false, false, false);
            GL.Disable(EnableCap.CullFace);
            GL.PolygonOffset(1, 1);
            GL.Enable(EnableCap.PolygonOffsetFill);

            fbo.BindDepth();
            fbo.BindFBO();
            fbo.Clear();

            // kuvakulma valosta päin
            GLExt.LoadMatrix(ref Light.Lights[lightNo].OrigOrientationMatrix);
            GLExt.Translate(-Light.Lights[lightNo].Position.X, -Light.Lights[lightNo].Position.Y, -Light.Lights[lightNo].Position.Z);

            SetTextureMatrix();
            Frustum.CalculateFrustum();

            VBO.FastRenderPass = true;
            depthShader.UseProgram();
            world.Render();
            if (withParticles)
            {
                depthShaderAlphaTest.UseProgram();
                Particles.Render();
                GLSLShader.UnBindShader();
            }
            VBO.FastRenderPass = false;
            fbo.UnBindFBO();

            GL.Disable(EnableCap.PolygonOffsetFill);
            GL.Enable(EnableCap.CullFace);
            GL.ColorMask(true, true, true, true);

            GLExt.LoadIdentity();
            GameClass.NumOfObjects = 0;

            ShadowMapping.UnBindLightMask();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
        public override void Render()
        {
            ShadowMapping.SetupShadows(world, 0, false);
            GL.Clear(ClearFlags);
            camera.SetFPSCamera();
            world.Render();

            if (Keyboard[Key.Space])
            {
                AnimatedModel self = actors[0] as AnimatedModel;
                self.RenderSkeleton(); // note: ei näy gl3:ssa
            }

            lightImg.RenderBillboard(Light.Lights[0].Position, 0, 50, true);
            Camera.Set2D();
            font.Write("Arrow keys: move the ugly.\n" + (Settings.UseGL3 == false ? "Space: show skeleton.\n" : "") + "A,D,W,S: move the camera.\nHold left mouse button to rotate the camera.", 0, 0);
            Camera.Set3D();

            base.Render();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        public void SetUniforms()
        {
            GL.UniformMatrix4(uniformLoc[(int)U.projMatrix], false, ref GLExt.ProjectionMatrix);
            GL.UniformMatrix4(uniformLoc[(int)U.modelMatrix], false, ref GLExt.ModelViewMatrix);

            if (VBO.FastRenderPass == true)
            {
                return;
            }

            if (uniformLoc[(int)U.normalMatrix] != -1)
            {
                Matrix4 normMatrix = GLExt.ModelViewMatrix;
                normMatrix.Row3 = new Vector4(0, 0, 0, 1);
                normMatrix      = Matrix4.Transpose(Matrix4.Invert(normMatrix));
                GL.UniformMatrix4(uniformLoc[(int)U.normalMatrix], false, ref normMatrix);
            }
            if (uniformLoc[(int)U.textureMatrix] != -1)
            {
                GL.UniformMatrix4(uniformLoc[(int)U.textureMatrix], false, ref GLExt.TextureMatrix);
            }
            if (uniformLoc[(int)U.texMap] != -1)
            {
                GL.Uniform1(uniformLoc[(int)U.texMap], Settings.COLOR_TEXUNIT);
            }
            if (uniformLoc[(int)U.matDiffuse] != -1)
            {
                GL.Uniform4(uniformLoc[(int)U.matDiffuse], GLExt.Color);
            }

            if (uniformLoc[(int)U.fogColor] != -1)
            {
                GL.Uniform3(uniformLoc[(int)U.fogColor], Fog.Color);
                GL.Uniform1(uniformLoc[(int)U.fogDensity], Fog.Density);
            }

            if (uniformLoc[(int)U.depthMap] != -1)
            {
                GL.Uniform1(uniformLoc[(int)U.depthMap], Settings.DEPTH_TEXUNIT);
            }
            if (uniformLoc[(int)U.lightmaskMap] != -1)
            {
                ShadowMapping.BindLightMask();
                GL.Uniform1(uniformLoc[(int)U.lightmaskMap], Settings.LIGHTMASK_TEXUNIT);
            }
            if (uniformLoc[(int)U.particlePower] != -1)
            {
                GL.Uniform1(uniformLoc[(int)U.particlePower], Particles.ParticlePower);
            }


            // TODO multiple lights
            if (uniformLoc[(int)U.light] != -1)
            {
                GL.Uniform3(uniformLoc[(int)U.light], Light.Lights[0].Matrix.Row3.Xyz);

                GL.Uniform4(uniformLoc[(int)U.lightDiffuse], Light.Lights[0].Diffuse);
                GL.Uniform4(uniformLoc[(int)U.lightAmb], Light.Lights[0].Ambient);

                if (uniformLoc[(int)U.lightShininess] != -1) // shininess (jos löytyy, käytä perpixel lightingiä)
                {
                    GL.Uniform4(uniformLoc[(int)U.matSpec], Material.CurrentMaterial.SpecularColor);
                    GL.Uniform4(uniformLoc[(int)U.matAmb], Material.CurrentMaterial.AmbientColor);

                    GL.Uniform4(uniformLoc[(int)U.lightSpec], Light.Lights[0].Specular);
                    GL.Uniform1(uniformLoc[(int)U.lightShininess], Light.Lights[0].Shininess);
                }
            }
        }