예제 #1
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();
            }
        }
예제 #2
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();
            }
        }