Exemple #1
0
        protected override void UseInternal(Matrix4x4 projView, MaterialUse use)
        {
            var program = GetProgram(use);

            program.Use();
            program.SetUniform("uTex", 0);
            program.SetUniform("uProjectionViewMat", projView);
            program.SetUniform("uTime", Globals.Time);
            GL.ActiveTexture(TextureUnit.Texture0);
            Texture.Use();
        }
Exemple #2
0
        public override void Use(Matrix4x4 projView, MaterialUse use)
        {
            var program = GetProgram(use);

            program.Use();
            program.SetUniform("uDiffuseTex", 0);
            program.SetUniform("uNormalTex", 1);
            program.SetUniform("uProjectionViewMat", projView);
            program.SetUniform("uModelMat", Matrix4x4.Identity);
            GL.ActiveTexture(TextureUnit.Texture0);
            Textures[0].Use();
            GL.ActiveTexture(TextureUnit.Texture1);
            Textures[1].Use();
        }
Exemple #3
0
        protected Program GetProgram(MaterialUse use)
        {
            switch (use)
            {
            case MaterialUse.Static:
                return(StaticProgram ?? (StaticProgram =
                                             new Program(GenerateVertexShader(MaterialUse.Static), FragmentShader)));

            case MaterialUse.Animated:
                return(AnimatedProgram ?? (AnimatedProgram =
                                               new Program(GenerateVertexShader(MaterialUse.Animated), FragmentShader)));
            }
            return(null);
        }
        public override void Use(Matrix4x4 projView, MaterialUse use)
        {
            var program = GetProgram(use);

            program.Use();
            program.SetUniform("uTex", 0);
            program.SetUniform("uProjectionViewMat", projView);
            program.SetUniform("uModelMat", Matrix4x4.Identity);
            GL.ActiveTexture(TextureUnit.Texture0);
            if (AnimationSpeed == 0)
            {
                Textures[0].Use();
            }
            else
            {
                Textures[(int)(Globals.Time / AnimationSpeed) % Textures.Length].Use();
            }
        }
Exemple #5
0
        string GenerateVertexShader(MaterialUse use)
        {
            switch (use)
            {
            case MaterialUse.Static: {
                var ret = @"
#version 410
precision highp float;
layout (location = 0) in vec4 aPosition;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoord;
uniform mat4 uModelMat;
uniform mat4 uProjectionViewMat;
out vec2 vTexCoord;
out vec4 vPosition;
					"                    ;
                if (WantNormals)
                {
                    ret += @"
out vec3 vNormal;
						"                        ;
                }
                ret += @"
void main() {
	gl_Position = vPosition = uProjectionViewMat * uModelMat * aPosition;
	vTexCoord = aTexCoord;
					"                    ;
                if (WantNormals)
                {
                    ret += @"
	mat3 nmat = transpose(inverse(mat3(uModelMat)));
	vNormal = normalize(nmat * aNormal);
						"                        ;
                }
                ret += @"
}
					"                    ;
                return(ret);
            }

            case MaterialUse.Animated: {
                var ret = @"
#version 410
precision highp float;
layout (location = 0) in vec4 aPosition1;
layout (location = 1) in vec3 aNormal1;
layout (location = 2) in vec2 aTexCoord1;
layout (location = 3) in vec4 aPosition2;
layout (location = 4) in vec3 aNormal2;
layout (location = 5) in vec2 aTexCoord2;
uniform mat4 uModelMat;
uniform mat4 uProjectionViewMat;
uniform float uInterp;
out vec2 vTexCoord;
out vec4 vPosition;
					"                    ;
                if (WantNormals)
                {
                    ret += @"
out vec3 vNormal;
						"                        ;
                }
                ret += @"
void main() {
	gl_Position = vPosition = uProjectionViewMat * uModelMat * mix(aPosition1, aPosition2, uInterp);
	vTexCoord = mix(aTexCoord1, aTexCoord2, uInterp);
					"                    ;
                if (WantNormals)
                {
                    ret += @"
	mat3 nmat = transpose(inverse(mat3(uModelMat)));
	vNormal = normalize(nmat * mix(aNormal1, aNormal2, uInterp));
						"                        ;
                }
                ret += @"
}
					"                    ;
                return(ret);
            }
            }
            return(null);
        }
Exemple #6
0
 protected Program GetProgram(MaterialUse use) => use switch
 {
Exemple #7
0
 public abstract void Use(Matrix4x4 projView, MaterialUse use);