Exemplo n.º 1
0
        private void renderGrass()
        {
            int l = grassData.Length;

            sp.use();
            GL.Disable(EnableCap.CullFace);
            GL.Uniform3(sp.Uniforms["lightdir"], sunLightDir);
            GL.Uniform1(sp.Uniforms["lightstr"], 1f);
            GL.Uniform3(sp.Uniforms["slices"], slices);
            GL.Uniform4(sp.Uniforms["ambient"], new Vector4(0.1f, 0.1f, 0.1f, 1f));

            GL.ActiveTexture(TextureUnit.Texture0);
            grassTexture.bind();
            GL.Uniform1(sp.Uniforms["modelTexture"], 0);

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2DArray, depthTextureArray);
            GL.Uniform1(sp.Uniforms["shadowmap"], 1);

            for (int i = 0; i < l; i++)
            {
                Matrix4 m   = Matrix4.CreateTranslation(grassData[i]);
                Matrix4 mvp = m * view * projection;
                GL.UniformMatrix4(sp.Uniforms["modelViewProjection"], false, ref mvp);
                GL.UniformMatrix4(sp.Uniforms["model"], false, ref m);
                Matrix4 shadowMat0 = (m * depthView * depthProjection) * bias;
                GL.UniformMatrix4(sp.Uniforms["shadowMat0"], false, ref shadowMat0);
                grassModel.draw();
            }

            GL.UseProgram(0);
            GL.Enable(EnableCap.CullFace);
        }
Exemplo n.º 2
0
        public Scene(int wdh, int hgt)
        {
            width  = wdh;
            height = hgt;

            initGL();

            load();
            initObjects();

            //init matrices
            view       = Matrix4.LookAt(new Vector3(0, 1.75f, 1.75f), new Vector3(0, 1.5f, 0), Vector3.UnitY);
            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), wdh / hgt, 0.1f, 300.0f);

            depthProjection = Matrix4.CreateOrthographicOffCenter(-30, 30, -30, 30, -30, 100);
            depthView       = Matrix4.LookAt(sunLightSrc, sunLightSrc + sunLightDir, Vector3.UnitY);

            psvp = Matrix4.CreateOrthographic(1, 1, -5, 5);

            //load shader
            sp = BasicShader.create("Data/Shader/basic.v", "Data/Shader/basic.f");
            sp.addUniform("modelTexture");
            sp.addUniform("shadowmap");
            sp.addUniform("lightdir");
            sp.addUniform("lightstr");
            sp.addUniform("ambient");
            sp.addUniform("modelViewProjection");
            sp.addUniform("model");
            //sp.addUniform("view");
            sp.addUniform("bias");
            //sp.addUniform("projection");
            sp.addUniform("shadowMat0");
            sp.addUniform("shadowMat1");
            sp.addUniform("shadowMat2");
            sp.addUniform("slices");

            sp.use();
            GL.UniformMatrix4(sp.Uniforms["bias"], false, ref bias);
            GL.UseProgram(0);

            depthShader = BasicShader.create("Data/Shader/depthShader.v", "Data/Shader/depthShader.f");
            depthShader.addUniform("model");
            depthShader.addUniform("view");
            depthShader.addUniform("projection");
            depthShader.addUniform("modelTexture");

            ps = BasicShader.create("Data/Shader/ps.v", "Data/Shader/ps.f");
            ps.addUniform("tex");
            ps.addUniform("texZ");

            bs = BasicShader.create("Data/Shader/basicShader.v", "Data/Shader/basicShader.f");
            bs.addUniform("mvp");
        }
Exemplo n.º 3
0
        private void renderGrassDepth()
        {
            int l = grassData.Length;

            depthShader.use();
            GL.FramebufferTextureLayer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, depthTextureArray, 0, 0);
            //Matrix4 mvp = (projection * view * so.ObjectMatrix);
            //GL.UniformMatrix4(depthShader.Uniforms["modelViewProjection"], false, ref mvp);

            GL.ActiveTexture(TextureUnit.Texture0);
            grassTexture.bind();

            for (int i = 0; i < l; i++)
            {
                Matrix4 m = Matrix4.CreateTranslation(grassData[i]);
                GL.UniformMatrix4(depthShader.Uniforms["model"], false, ref m);
                GL.UniformMatrix4(depthShader.Uniforms["view"], false, ref depthView);
                GL.UniformMatrix4(depthShader.Uniforms["projection"], false, ref depthProjection);
                grassModel.draw();
            }

            GL.UseProgram(0);
        }
Exemplo n.º 4
0
        private void renderGui()
        {
            bs.use();

            GL.ActiveTexture(TextureUnit.Texture0);
            textures.get("tachometer").bind();
            Matrix4 mvp = Matrix4.Identity *
                          Matrix4.Scale(0.2f) *
                          Matrix4.CreateTranslation(-0.8f, -0.8f, 0f) *
                          Matrix4.LookAt(Vector3.UnitZ, -Vector3.UnitZ, Vector3.UnitY) *
                          Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, 0.01f, 10.0f);

            GL.UniformMatrix4(bs.Uniforms["mvp"], false, ref mvp);
            models.get("tachometer").draw();

            GL.ActiveTexture(TextureUnit.Texture0);
            textures.get("tachometer|").bind();
            mvp = Matrix4.Identity *
                  Matrix4.Scale(0.2f) *
                  Matrix4.CreateRotationZ(MathHelper.DegreesToRadians(((270 / 120) * -(v * 3.6f)) + 135)) *
                  Matrix4.CreateTranslation(-0.8f, -0.8f, 0f) *
                  Matrix4.LookAt(Vector3.UnitZ, -Vector3.UnitZ, Vector3.UnitY) *
                  Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, 0.01f, 10.0f);
            GL.UniformMatrix4(bs.Uniforms["mvp"], false, ref mvp);
            models.get("tachometer|").draw();

            GL.UseProgram(0);

            //Debug---------------------------------------------------------------------------------------------------------------
#if DEBUG
            ps.use();
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2DArray, depthTextureArray);
            GL.Uniform1(ps.Uniforms["tex"], 0);
            GL.Uniform1(ps.Uniforms["texZ"], depthMode);
            models.get("plane").draw();
            GL.UseProgram(0);
#endif
        }
Exemplo n.º 5
0
        public Scene(int wdh, int hgt)
        {
            width = wdh;
            height = hgt;

            initGL();

            load();
            initObjects();

            //init matrices
            view = Matrix4.LookAt(new Vector3(0, 1.75f, 1.75f), new Vector3(0, 1.5f, 0), Vector3.UnitY);
            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75), wdh / hgt, 0.1f, 300.0f);

            depthProjection = Matrix4.CreateOrthographicOffCenter(-30, 30, -30, 30, -30, 100);
            depthView = Matrix4.LookAt(sunLightSrc, sunLightSrc + sunLightDir, Vector3.UnitY);

            psvp = Matrix4.CreateOrthographic(1, 1, -5, 5);

            //load shader
            sp = BasicShader.create("Data/Shader/basic.v", "Data/Shader/basic.f");
            sp.addUniform("modelTexture");
            sp.addUniform("shadowmap");
            sp.addUniform("lightdir");
            sp.addUniform("lightstr");
            sp.addUniform("ambient");
            sp.addUniform("modelViewProjection");
            sp.addUniform("model");
            //sp.addUniform("view");
            sp.addUniform("bias");
            //sp.addUniform("projection");
            sp.addUniform("shadowMat0");
            sp.addUniform("shadowMat1");
            sp.addUniform("shadowMat2");
            sp.addUniform("slices");

            sp.use();
            GL.UniformMatrix4(sp.Uniforms["bias"], false, ref bias);
            GL.UseProgram(0);

            depthShader = BasicShader.create("Data/Shader/depthShader.v", "Data/Shader/depthShader.f");
            depthShader.addUniform("model");
            depthShader.addUniform("view");
            depthShader.addUniform("projection");
            depthShader.addUniform("modelTexture");

            ps = BasicShader.create("Data/Shader/ps.v", "Data/Shader/ps.f");
            ps.addUniform("tex");
            ps.addUniform("texZ");

            bs = BasicShader.create("Data/Shader/basicShader.v", "Data/Shader/basicShader.f");
            bs.addUniform("mvp");
        }