示例#1
0
 public FullScreenQuad()
 {
     vao = new GLVertexArray();
     ebo = new GLElementBuffer(BufferUsageHint.StaticDraw);
     vbo = new GLArrayBuffer(BufferUsageHint.StaticDraw);
     Setup();
 }
示例#2
0
        public MeshRenderer(Mesh model)
        {
            Tiling = new Vector2(1, 1);

            vbo = new GLArrayBuffer(BufferUsageHint.StaticDraw);
            ebo = new GLElementBuffer(BufferUsageHint.StaticDraw);
            vao = new GLVertexArray();

            vao.Bind();
            vbo.Bind();
            ebo.Bind();

            vbo.SetData(model.Compact());
            ebo.SetData(model.indices.ToArray());
            indicesCount = model.indices.Count;

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 12 * sizeof(float), 0);
            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, 12 * sizeof(float), (3 * 4) + (2 * 4));
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, 12 * sizeof(float), 3 * 4);
            GL.VertexAttribPointer(3, 4, VertexAttribPointerType.Float, false, 12 * sizeof(float), (3 * 4) + (2 * 4) + (3 * 4));
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);
            GL.EnableVertexAttribArray(3);

            GLArrayBuffer.Unbind();

            GLVertexArray.Unbind();

            GLElementBuffer.Unbind();
        }
示例#3
0
        public virtual void DrawForDepth()
        {
            if (Mat != null && Mat.Shader != null)
            {
                GLShaderProgram shader = Mat.Shader;

                //use shader
                shader.Use();

                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                Vector2 tiling = Tiling;

                shader.SetUniform2("tiling", ref tiling);

                ///draw
                vao.Bind();
                GL.DrawElements(BeginMode.Triangles, indicesCount, DrawElementsType.UnsignedInt, 0);
                GLVertexArray.Unbind();
            }
        }
示例#4
0
        public virtual void DrawAsLight()
        {
            if (Mat != null && Mat.Shader != null)
            {
                IGLProgram shader = Mat.Shader;

                shader.Use();

                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                Vector2 tiling = Tiling;

                Vector4 lightColor = new Vector4(LightColor * LightPower, 1);

                shader.SetUniform2("tiling", ref tiling);

                shader.SetUniform4F("color", ref lightColor);

                ///draw
                vao.Bind();
                IGL.Primary.DrawElements((int)BeginMode.Triangles, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                GLVertexArray.Unbind();
            }
        }
示例#5
0
 public override void Release()
 {
     if (vao != null)
     {
         vao.Release();
         vao = null;
     }
     if (ebo != null)
     {
         ebo.Release();
         ebo = null;
     }
     if (vbo != null)
     {
         vbo.Release();
         vbo = null;
     }
 }
示例#6
0
        void Setup()
        {
            vao.Bind();

            vbo.Bind();
            vbo.SetData(buffer);

            ebo.Bind();
            ebo.SetData(indices);

            IGL.Primary.VertexAttribPointer(0, 3, (int)VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
            IGL.Primary.VertexAttribPointer(1, 2, (int)VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * 4);
            IGL.Primary.EnableVertexAttribArray(0);
            IGL.Primary.EnableVertexAttribArray(1);
            GLVertexArray.Unbind();
            GLElementBuffer.Unbind();
            GLArrayBuffer.Unbind();
        }
示例#7
0
        public override void Draw()
        {
            if (shader != null && renderer != null)
            {
                shader.Use();
                Matrix4 view  = View;
                Matrix4 proj  = Projection;
                Matrix4 model = Model;
                shader.SetUniformMatrix4("modelMatrix", ref model);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("projectionMatrix", ref proj);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
                renderer.Bind();
                GL.DrawElements(BeginMode.Triangles, indicesCount, DrawElementsType.UnsignedInt, 0);
                GLVertexArray.Unbind();

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            }
        }
示例#8
0
        public override void Draw()
        {
            if (Mat != null && Mat.Shader != null)
            {
                GLShaderProgram shader = Mat.Shader;

                GL.ActiveTexture(TextureUnit.Texture0);
                if (Mat.Albedo != null)
                {
                    Mat.Albedo.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture1);
                if (Mat.Metallic != null)
                {
                    Mat.Metallic.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture2);
                if (Mat.Roughness != null)
                {
                    Mat.Roughness.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture3);
                if (Mat.Occlusion != null)
                {
                    Mat.Occlusion.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture4);
                if (Mat.Normal != null)
                {
                    Mat.Normal.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture5);
                if (Mat.Height != null)
                {
                    Mat.Height.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture6);
                PBRMaterial.BRDFLut.Bind();

                GL.ActiveTexture(TextureUnit.Texture7);
                if (IrradianceMap != null)
                {
                    IrradianceMap.Bind();
                }

                GL.ActiveTexture(TextureUnit.Texture8);
                if (PrefilterMap != null)
                {
                    PrefilterMap.Bind();
                }

                //use shader
                shader.Use();

                //set texture bind points
                shader.SetUniform("albedo", 0);
                shader.SetUniform("metallicMap", 1);
                shader.SetUniform("roughnessMap", 2);
                shader.SetUniform("occlusionMap", 3);
                shader.SetUniform("normalMap", 4);
                shader.SetUniform("heightMap", 5);
                shader.SetUniform("brdfLUT", 6);
                shader.SetUniform("irradianceMap", 7);
                shader.SetUniform("prefilterMap", 8);

                Vector3 lpos = LightPosition;
                Vector3 lc   = LightColor;

                Vector3 cam = CameraPosition;

                //set camera and light stuff
                shader.SetUniform3("cameraPosition", ref cam);
                shader.SetUniform3("lightPosition", ref lpos);
                shader.SetUniform3("lightColor", ref lc);

                //setup MVP and N matrices
                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                Vector2 tiling = Tiling;

                shader.SetUniform2("tiling", ref tiling);

                ///draw
                vao.Bind();
                GL.DrawElements(BeginMode.Triangles, indicesCount, DrawElementsType.UnsignedInt, 0);
                GLVertexArray.Unbind();
                GLTextuer2D.Unbind();
            }
        }
示例#9
0
 public override void Draw()
 {
     vao.Bind();
     IGL.Primary.DrawElements((int)BeginMode.Triangles, 6, (int)DrawElementsType.UnsignedInt, 0);
     GLVertexArray.Unbind();
 }
示例#10
0
 public override void Draw()
 {
     vao.Bind();
     GL.DrawElements(BeginMode.Triangles, 6, DrawElementsType.UnsignedInt, 0);
     GLVertexArray.Unbind();
 }
示例#11
0
        public virtual void DrawFull()
        {
            if (Mat != null && Mat.Shader != null)
            {
                IGLProgram shader = Mat.Shader;

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture0);
                if (Mat.Albedo != null)
                {
                    Mat.Albedo.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture1);
                if (Mat.Metallic != null)
                {
                    Mat.Metallic.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture2);
                if (Mat.Roughness != null)
                {
                    Mat.Roughness.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture3);
                if (Mat.Occlusion != null)
                {
                    Mat.Occlusion.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture4);
                if (Mat.Normal != null)
                {
                    Mat.Normal.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture5);
                if (Mat.Height != null)
                {
                    Mat.Height.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture6);
                PBRMaterial.BRDFLut.Bind();

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture7);
                if (IrradianceMap != null)
                {
                    IrradianceMap.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture8);
                if (PrefilterMap != null)
                {
                    PrefilterMap.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture9);
                if (Mat.Thickness != null)
                {
                    Mat.Thickness.Bind();
                }

                IGL.Primary.ActiveTexture((int)TextureUnit.Texture10);
                if (Mat.Emission != null)
                {
                    Mat.Emission.Bind();
                }

                //use shader
                shader.Use();

                //set texture bind points
                shader.SetUniform("albedo", 0);
                shader.SetUniform("metallicMap", 1);
                shader.SetUniform("roughnessMap", 2);
                shader.SetUniform("occlusionMap", 3);
                shader.SetUniform("normalMap", 4);
                shader.SetUniform("heightMap", 5);
                shader.SetUniform("brdfLUT", 6);
                shader.SetUniform("irradianceMap", 7);
                shader.SetUniform("prefilterMap", 8);
                shader.SetUniform("thicknessMap", 9);
                shader.SetUniform("emissionMap", 10);

                Vector3 lpos = LightPosition;
                Vector3 lc   = LightColor;

                Vector3 cam = CameraPosition;

                //set camera and light stuff
                shader.SetUniform3("cameraPosition", ref cam);
                shader.SetUniform3("lightPosition", ref lpos);
                shader.SetUniform3("lightColor", ref lc);
                shader.SetUniform("lightPower", LightPower);

                //setup MVP and N matrices
                Matrix4 proj = Projection;
                Matrix4 view = View;
                Matrix4 m    = Model;
                Matrix4 norm = Matrix4.Invert(m);
                norm.Transpose();

                shader.SetUniformMatrix4("projectionMatrix", ref proj);
                shader.SetUniformMatrix4("viewMatrix", ref view);
                shader.SetUniformMatrix4("modelMatrix", ref m);
                shader.SetUniformMatrix4("normalMatrix", ref norm);

                shader.SetUniform("far", Far);
                shader.SetUniform("near", Near);

                shader.SetUniform("heightScale", Mat.HeightScale);
                shader.SetUniform("refraction", Mat.IOR);

                ///SSS Related
                shader.SetUniform("SSS_Distortion", Mat.SSSDistortion);
                shader.SetUniform("SSS_Ambient", Mat.SSSAmbient);
                shader.SetUniform("SSS_Power", Mat.SSSPower);

                if (Mat.ClipHeight)
                {
                    shader.SetUniform("occlusionClipBias", Mat.ClipHeightBias);
                }
                else
                {
                    shader.SetUniform("occlusionClipBias", -1.0f);
                }

                shader.SetUniform("displace", Mat.UseDisplacement);

                Vector2 tiling = Tiling;

                shader.SetUniform2("tiling", ref tiling);

                ///draw
                vao.Bind();

                if (Mat.UseDisplacement)
                {
                    IGL.Primary.DrawElements((int)BeginMode.Patches, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                }
                else
                {
                    IGL.Primary.DrawElements((int)BeginMode.Triangles, indicesCount, (int)DrawElementsType.UnsignedInt, 0);
                }

                GLVertexArray.Unbind();
                GLTextuer2D.Unbind();
            }
        }