Skip to content

Commit

Permalink
Switched to OpenGL ES compatible fragment shaders so we can use the A…
Browse files Browse the repository at this point in the history
…ngle renderer soon (which can run at 120 FPS!)
  • Loading branch information
MeltyPlayer committed Dec 4, 2024
1 parent 8616435 commit eb0abe2
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,69 @@ public void TestWithoutNormalsNotMasked()
=> AssertGlsl_(
false,
false,
"""
#version 430
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
uniform vec4 diffuseColor;
out vec4 fragColor;
uniform vec4 diffuseColor;
out vec4 fragColor;
in vec4 vertexColor0;
in vec4 vertexColor0;
void main() {
fragColor = diffuseColor * vertexColor0;
}
""");
void main() {
fragColor = diffuseColor * vertexColor0;
}
""");

[Test]
public void TestWithoutNormalsMasked()
=> AssertGlsl_(
false,
true,
"""
#version 430
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
uniform vec4 diffuseColor;
uniform vec4 diffuseColor;
out vec4 fragColor;
out vec4 fragColor;
in vec4 vertexColor0;
in vec4 vertexColor0;
void main() {
fragColor = diffuseColor * vertexColor0;
if (fragColor.a < .95) {
discard;
void main() {
fragColor = diffuseColor * vertexColor0;
if (fragColor.a < .95) {
discard;
}
}
}
""");
""");

[Test]
public void TestWithNormals()
=> AssertGlsl_(
true,
true,
$$"""
#version 430
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
{{GlslUtil.GetLightHeader(true)}}
uniform vec4 diffuseColor;
uniform float shininess;
out vec4 fragColor;
in vec4 vertexColor0;
in vec3 vertexPosition;
in vec3 vertexNormal;
{{GlslUtil.GetGetIndividualLightColorsFunction()}}
{{GlslUtil.GetGetMergedLightColorsFunction()}}
{{GlslUtil.GetApplyMergedLightColorsFunction(false)}}
void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,69 +21,72 @@ public void TestWithNothing()
false,
false,
(m, t) => CreateFixedFunctionMaterial_(m, t, false, false, false),
"""
#version 430
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
out vec4 fragColor;
out vec4 fragColor;
void main() {
vec3 colorComponent = vec3(1);
float alphaComponent = 1;
fragColor = vec4(colorComponent, alphaComponent);
}
""");
void main() {
vec3 colorComponent = vec3(1.0);
float alphaComponent = 1.0;
fragColor = vec4(colorComponent, alphaComponent);
}
""");

[Test]
public void TestWithVertexColorOnly()
=> AssertGlsl_(
false,
false,
(m, t) => CreateFixedFunctionMaterial_(m, t, false, false, true),
"""
#version 430
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
in vec4 vertexColor0;
in vec4 vertexColor0;
out vec4 fragColor;
out vec4 fragColor;
void main() {
vec3 colorComponent = vertexColor0.rgb;
float alphaComponent = vertexColor0.a;
fragColor = vec4(colorComponent, alphaComponent);
}
""");
void main() {
vec3 colorComponent = vertexColor0.rgb;
float alphaComponent = vertexColor0.a;
fragColor = vec4(colorComponent, alphaComponent);
}
""");

[Test]
public void TestWithTextureOnly()
=> AssertGlsl_(
false,
true,
(m, t) => CreateFixedFunctionMaterial_(m, t, false, true, false),
"""
#version 430
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
uniform sampler2D texture0;
uniform sampler2D texture0;
in vec2 uv0;
in vec2 uv0;
out vec4 fragColor;
out vec4 fragColor;
void main() {
vec3 colorComponent = texture(texture0, uv0).rgb;
float alphaComponent = texture(texture0, uv0).a;
fragColor = vec4(colorComponent, alphaComponent);
if (!(alphaComponent > 0.95)) {
discard;
void main() {
vec3 colorComponent = texture(texture0, uv0).rgb;
float alphaComponent = texture(texture0, uv0).a;
fragColor = vec4(colorComponent, alphaComponent);
if (!(alphaComponent > 0.95)) {
discard;
}
}
}
""");
""");

[Test]
public void TestWithLightingAndTextureAndVertexColor()
Expand All @@ -92,7 +95,8 @@ public void TestWithLightingAndTextureAndVertexColor()
true,
(m, t) => CreateFixedFunctionMaterial_(m, t, true, true, true),
$$"""
#version 430
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
{{GlslUtil.GetLightHeader(true)}}
uniform float shininess;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Drawing;

using fin.image;
using fin.model.impl;
using fin.model.impl;
using fin.model.util;
using fin.util.image;

Expand All @@ -17,51 +14,54 @@ public void TestWithoutNormalsNotMasked()
=> AssertGlsl_(
false,
false,
"""
#version 430
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");

[Test]
public void TestWithoutNormalsMasked()
=> AssertGlsl_(
false,
true,
"""
#version 430
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");

[Test]
public void TestWithNormals()
=> AssertGlsl_(
true,
true,
"""
#version 430
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");
$$"""
#version {{GlslConstants.FRAGMENT_SHADER_VERSION}}
{{GlslConstants.FLOAT_PRECISION}}
out vec4 fragColor;
in vec4 vertexColor0;
void main() {
fragColor = vertexColor0;
}
""");

private static void AssertGlsl_(
bool withNormals,
Expand Down
Loading

0 comments on commit eb0abe2

Please sign in to comment.