From 611b1b2863e74fbeaa441aebf88f8f7f951db6e1 Mon Sep 17 00:00:00 2001 From: MeltyPlayer Date: Tue, 3 Dec 2024 05:58:42 -0600 Subject: [PATCH] Fixed one more issue with an extra line in some GLSL files. --- .../glsl/StandardShaderSourceGlslTests.cs | 123 +++++++++++------- .../shaders/glsl/StandardShaderSourceGlsl.cs | 6 +- .../at1/output/material18.fragment.glsl | 1 - .../chuck/output/material0.fragment.glsl | 1 - .../joff/output/material4.fragment.glsl | 1 - 5 files changed, 79 insertions(+), 53 deletions(-) diff --git a/FinModelUtility/Fin/Fin Tests/shaders/glsl/StandardShaderSourceGlslTests.cs b/FinModelUtility/Fin/Fin Tests/shaders/glsl/StandardShaderSourceGlslTests.cs index eac4c747e..35f96357d 100644 --- a/FinModelUtility/Fin/Fin Tests/shaders/glsl/StandardShaderSourceGlslTests.cs +++ b/FinModelUtility/Fin/Fin Tests/shaders/glsl/StandardShaderSourceGlslTests.cs @@ -5,6 +5,7 @@ using fin.model; using fin.model.impl; using fin.model.util; +using fin.util.image; using NUnit.Framework; @@ -13,10 +14,29 @@ namespace fin.shaders.glsl; public class StandardShaderSourceGlslTests { + [Test] + public void TestWithoutNormalsNoMask() + => AssertGlsl_( + false, + false, + (m, t) => { }, + """ + #version 430 + + out vec4 fragColor; + + in vec4 vertexColor0; + + void main() { + fragColor = vertexColor0; + } + """); + [Test] public void TestWithoutNormalsNoTextures() => AssertGlsl_( false, + true, (m, t) => { }, """ #version 430 @@ -38,6 +58,7 @@ void main() { public void TestWithoutNormalsDiffuseOnly() => AssertGlsl_( false, + true, (m, t) => m.DiffuseTexture = t, """ #version 430 @@ -63,6 +84,7 @@ void main() { public void TestWithoutNormalsEmissiveOnly() => AssertGlsl_( false, + true, (m, t) => m.EmissiveTexture = t, """ #version 430 @@ -90,29 +112,30 @@ void main() { [Test] public void TestWithNormalsNoTextures() => AssertGlsl_( + true, true, (m, t) => { }, $$""" #version 430 - + {{GlslUtil.GetLightHeader(true)}} - + uniform float shininess; - + out vec4 fragColor; - + in vec4 vertexColor0; in vec3 vertexPosition; in vec3 vertexNormal; in vec3 tangent; in vec3 binormal; - + {{GlslUtil.GetGetIndividualLightColorsFunction()}} - + {{GlslUtil.GetGetMergedLightColorsFunction()}} - + {{GlslUtil.GetApplyMergedLightColorsFunction(false)}} - + void main() { fragColor = vertexColor0; @@ -129,73 +152,75 @@ void main() { [Test] public void TestWithNormalsDiffuseOnly() => AssertGlsl_( + true, true, (m, t) => m.DiffuseTexture = t, $$""" - #version 430 - - {{GlslUtil.GetLightHeader(true)}} + #version 430 - uniform sampler2D diffuseTexture; - uniform float shininess; - - out vec4 fragColor; + {{GlslUtil.GetLightHeader(true)}} - in vec4 vertexColor0; - in vec3 vertexPosition; - in vec3 vertexNormal; - in vec3 tangent; - in vec3 binormal; - in vec2 uv0; + uniform sampler2D diffuseTexture; + uniform float shininess; - {{GlslUtil.GetGetIndividualLightColorsFunction()}} - - {{GlslUtil.GetGetMergedLightColorsFunction()}} - - {{GlslUtil.GetApplyMergedLightColorsFunction(false)}} - - void main() { - vec4 diffuseColor = texture(diffuseTexture, uv0); - fragColor = diffuseColor * vertexColor0; - - // Have to renormalize because the vertex normals can become distorted when interpolated. - vec3 fragNormal = normalize(vertexNormal); - fragColor.rgb = mix(fragColor.rgb, applyMergedLightingColors(vertexPosition, fragNormal, shininess, fragColor, vec4(1)).rgb, useLighting); - - if (fragColor.a < .95) { - discard; + out vec4 fragColor; + + in vec4 vertexColor0; + in vec3 vertexPosition; + in vec3 vertexNormal; + in vec3 tangent; + in vec3 binormal; + in vec2 uv0; + + {{GlslUtil.GetGetIndividualLightColorsFunction()}} + + {{GlslUtil.GetGetMergedLightColorsFunction()}} + + {{GlslUtil.GetApplyMergedLightColorsFunction(false)}} + + void main() { + vec4 diffuseColor = texture(diffuseTexture, uv0); + fragColor = diffuseColor * vertexColor0; + + // Have to renormalize because the vertex normals can become distorted when interpolated. + vec3 fragNormal = normalize(vertexNormal); + fragColor.rgb = mix(fragColor.rgb, applyMergedLightingColors(vertexPosition, fragNormal, shininess, fragColor, vec4(1)).rgb, useLighting); + + if (fragColor.a < .95) { + discard; + } } - } - """); + """); [Test] public void TestWithNormalsEmissiveOnly() => AssertGlsl_( + true, true, (m, t) => m.EmissiveTexture = t, $$""" #version 430 - + {{GlslUtil.GetLightHeader(true)}} - + uniform sampler2D emissiveTexture; uniform float shininess; - + out vec4 fragColor; - + in vec4 vertexColor0; in vec3 vertexPosition; in vec3 vertexNormal; in vec3 tangent; in vec3 binormal; in vec2 uv0; - + {{GlslUtil.GetGetIndividualLightColorsFunction()}} - + {{GlslUtil.GetGetMergedLightColorsFunction()}} - + {{GlslUtil.GetApplyMergedLightColorsFunction(false)}} - + void main() { fragColor = vertexColor0; @@ -215,6 +240,7 @@ void main() { private static void AssertGlsl_( bool withNormals, + bool masked, Action createMaterial, string expectedSource) { var model = ModelImpl.CreateForViewer(); @@ -234,6 +260,9 @@ private static void AssertGlsl_( skin.AddMesh().AddPoints(v).SetMaterial(material); } + material.TransparencyType + = masked ? TransparencyType.MASK : TransparencyType.OPAQUE; + var actualSource = new StandardShaderSourceGlsl( model, material, diff --git a/FinModelUtility/Fin/Fin/src/shaders/glsl/StandardShaderSourceGlsl.cs b/FinModelUtility/Fin/Fin/src/shaders/glsl/StandardShaderSourceGlsl.cs index 7aef9ccff..099b82054 100644 --- a/FinModelUtility/Fin/Fin/src/shaders/glsl/StandardShaderSourceGlsl.cs +++ b/FinModelUtility/Fin/Fin/src/shaders/glsl/StandardShaderSourceGlsl.cs @@ -141,9 +141,9 @@ void main() { fragmentShaderSrc.AppendLine( $" fragColor = {(hasDiffuseTexture ? "diffuseColor * " : "")}{GlslConstants.IN_VERTEX_COLOR_NAME}0;"); - fragmentShaderSrc.AppendLine(); if (hasNormals) { + fragmentShaderSrc.AppendLine(); if (hasAmbientOcclusionTexture) { fragmentShaderSrc.AppendLine( $" vec4 ambientOcclusionColor = {GlslUtil.ReadColorFromTexture("ambientOcclusionTexture", $"{GlslConstants.IN_UV_NAME}{ambientOcclusionTexture?.UvIndex ?? 0}", ambientOcclusionTexture, animations)};"); @@ -168,10 +168,10 @@ void main() { // TODO: Is this right? fragmentShaderSrc.AppendLine( $" fragColor.rgb = mix(fragColor.rgb, applyMergedLightingColors(vertexPosition, fragNormal, {GlslConstants.UNIFORM_SHININESS_NAME}, fragColor, {(hasSpecularTexture ? $"{GlslUtil.ReadColorFromTexture("specularTexture", "uv0", specularTexture, animations)}" : "vec4(1)")}{(hasAmbientOcclusionTexture ? ", ambientOcclusionColor.r" : "")}).rgb, {GlslConstants.UNIFORM_USE_LIGHTING_NAME});"); - fragmentShaderSrc.AppendLine(); } if (hasEmissiveTexture) { + fragmentShaderSrc.AppendLine(); fragmentShaderSrc.AppendLine( $" vec4 emissiveColor = {GlslUtil.ReadColorFromTexture("emissiveTexture", $"{GlslConstants.IN_UV_NAME}{emissiveTexture?.UvIndex ?? 0}", emissiveTexture, animations)};"); fragmentShaderSrc.AppendLine( @@ -179,10 +179,10 @@ void main() { fragColor.rgb += emissiveColor.rgb; fragColor.rgb = min(fragColor.rgb, 1); """); - fragmentShaderSrc.AppendLine(); } if (material.TransparencyType == TransparencyType.MASK) { + fragmentShaderSrc.AppendLine(); fragmentShaderSrc.AppendLine( $$""" if (fragColor.a < {{GlslConstants.MIN_ALPHA_BEFORE_DISCARD_TEXT}}) { diff --git a/FinModelUtility/Formats/Glo/Glo Tests/goldens/at1/output/material18.fragment.glsl b/FinModelUtility/Formats/Glo/Glo Tests/goldens/at1/output/material18.fragment.glsl index b69347888..044cde1e9 100644 --- a/FinModelUtility/Formats/Glo/Glo Tests/goldens/at1/output/material18.fragment.glsl +++ b/FinModelUtility/Formats/Glo/Glo Tests/goldens/at1/output/material18.fragment.glsl @@ -6,5 +6,4 @@ in vec4 vertexColor0; void main() { fragColor = vertexColor0; - } \ No newline at end of file diff --git a/FinModelUtility/Formats/Glo/Glo Tests/goldens/chuck/output/material0.fragment.glsl b/FinModelUtility/Formats/Glo/Glo Tests/goldens/chuck/output/material0.fragment.glsl index b69347888..044cde1e9 100644 --- a/FinModelUtility/Formats/Glo/Glo Tests/goldens/chuck/output/material0.fragment.glsl +++ b/FinModelUtility/Formats/Glo/Glo Tests/goldens/chuck/output/material0.fragment.glsl @@ -6,5 +6,4 @@ in vec4 vertexColor0; void main() { fragColor = vertexColor0; - } \ No newline at end of file diff --git a/FinModelUtility/Formats/Glo/Glo Tests/goldens/joff/output/material4.fragment.glsl b/FinModelUtility/Formats/Glo/Glo Tests/goldens/joff/output/material4.fragment.glsl index b69347888..044cde1e9 100644 --- a/FinModelUtility/Formats/Glo/Glo Tests/goldens/joff/output/material4.fragment.glsl +++ b/FinModelUtility/Formats/Glo/Glo Tests/goldens/joff/output/material4.fragment.glsl @@ -6,5 +6,4 @@ in vec4 vertexColor0; void main() { fragColor = vertexColor0; - } \ No newline at end of file