Skip to content

Commit

Permalink
Fixed issue with some UVs being missing in shaders.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Nov 28, 2024
1 parent 54fc4ba commit a3a106e
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public void Print(
for (var i = 0; i < usedColors.Length; ++i) {
if (usedColors[i]) {
AppendLineBetweenUniformsAndIns();
sb.AppendLine($"in vec4 vertexColor{i};");
sb.AppendLine($"in vec4 {GlslConstants.IN_VERTEX_COLOR_NAME}{i};");
}
}

var usedUvs = shaderRequirements.UsedUvs;
for (var i = 0; i < usedUvs.Length; ++i) {
if (usedUvs[i]) {
AppendLineBetweenUniformsAndIns();
sb.AppendLine($"in vec2 uv{i};");
sb.AppendLine($"in vec2 {GlslConstants.IN_UV_NAME}{i};");
}
}

Expand Down Expand Up @@ -568,8 +568,8 @@ private string GetScalarIdentifiedValue_(

FixedFunctionSource.LIGHT_AMBIENT_ALPHA => "ambientLightColor.a",

FixedFunctionSource.VERTEX_ALPHA_0 => "vertexColor0.a",
FixedFunctionSource.VERTEX_ALPHA_1 => "vertexColor1.a",
FixedFunctionSource.VERTEX_ALPHA_0 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}0.a",
FixedFunctionSource.VERTEX_ALPHA_1 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}1.a",

FixedFunctionSource.UNDEFINED => "1",
_ => throw new ArgumentOutOfRangeException()
Expand Down Expand Up @@ -799,11 +799,11 @@ private string GetColorNamedValue_(
FixedFunctionSource.LIGHT_AMBIENT_COLOR => "ambientLightColor.rgb",
FixedFunctionSource.LIGHT_AMBIENT_ALPHA => "ambientLightColor.aaa",

FixedFunctionSource.VERTEX_COLOR_0 => "vertexColor0.rgb",
FixedFunctionSource.VERTEX_COLOR_1 => "vertexColor1.rgb",
FixedFunctionSource.VERTEX_COLOR_0 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}0.rgb",
FixedFunctionSource.VERTEX_COLOR_1 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}1.rgb",

FixedFunctionSource.VERTEX_ALPHA_0 => "vertexColor0.aaa",
FixedFunctionSource.VERTEX_ALPHA_1 => "vertexColor1.aaa",
FixedFunctionSource.VERTEX_ALPHA_0 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}0.aaa",
FixedFunctionSource.VERTEX_ALPHA_1 => $"{GlslConstants.IN_VERTEX_COLOR_NAME}1.aaa",

FixedFunctionSource.UNDEFINED => "vec3(1)",
_ => throw new ArgumentOutOfRangeException()
Expand All @@ -825,7 +825,7 @@ private string GetTextureValue_(int textureIndex,
return texture.UvType switch {
UvType.STANDARD
=> GlslUtil.ReadColorFromTexture(textureName,
$"uv{texture.UvIndex}",
$"{GlslConstants.IN_UV_NAME}{texture.UvIndex}",
texture,
this.animations_),
UvType.SPHERICAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ or IStandardMaterial
break;
}
case IFixedFunctionMaterial fixedFunctionMaterial: {
foreach (var texture in fixedFunctionMaterial.TextureSources) {
if (texture != null) {
this.UsedUvs[texture.UvIndex] = true;
}
}

var equations = fixedFunctionMaterial.Equations;
for (var i = 0; i < this.UsedColors.Length; ++i) {
this.UsedColors[i] = equations.DoOutputsDependOn([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D texture1;

in vec4 vertexColor0;
in vec2 uv0;
in vec2 uv1;

out vec4 fragColor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ out vec3 vertexNormal;
out vec3 tangent;
out vec3 binormal;
out vec2 uv0;
out vec2 uv1;
out vec4 vertexColor0;

void main() {
Expand All @@ -29,5 +30,6 @@ void main() {
tangent = normalize(modelMatrix * vec4(in_Tangent)).xyz;
binormal = cross(vertexNormal, tangent);
uv0 = in_Uvs[0];
uv1 = in_Uvs[1];
vertexColor0 = in_Colors[0];
}

0 comments on commit a3a106e

Please sign in to comment.