From 65ace3f4e3cf3fc7885d4254b82d6f05effd3c6d Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sun, 25 Jun 2023 15:40:48 -0400 Subject: [PATCH] Fix-up float literals in shaders OpenGL ES is particularly picky about this --- .../shaders/terrain_combined_classic.frag | 4 ++-- data/base/shaders/terrain_combined_high.frag | 24 +++++++++---------- .../base/shaders/terrain_combined_medium.frag | 6 ++--- data/base/shaders/terrain_water.vert | 8 +++---- data/base/shaders/terrain_water_classic.vert | 8 +++---- .../shaders/vk/terrain_combined_medium.frag | 6 ++--- data/base/shaders/vk/terrain_water.vert | 8 +++---- .../shaders/vk/terrain_water_classic.vert | 8 +++---- data/base/shaders/vk/water.frag | 12 +++++----- data/base/shaders/water.frag | 12 +++++----- 10 files changed, 48 insertions(+), 48 deletions(-) diff --git a/data/base/shaders/terrain_combined_classic.frag b/data/base/shaders/terrain_combined_classic.frag index fc19242379e..08130df5183 100644 --- a/data/base/shaders/terrain_combined_classic.frag +++ b/data/base/shaders/terrain_combined_classic.frag @@ -70,10 +70,10 @@ out vec4 FragColor; #endif vec4 main_classic() { - vec4 decal = tile >= 0 ? texture2DArray(decalTex, vec3(uvDecal, tile), WZ_MIP_LOAD_BIAS) : vec4(0); + vec4 decal = tile >= 0 ? texture2DArray(decalTex, vec3(uvDecal, tile), WZ_MIP_LOAD_BIAS) : vec4(0.f); vec3 L = normalize(groundLightDir); - vec3 N = vec3(0,0,1); + vec3 N = vec3(0.f,0.f,1.f); float lambertTerm = max(dot(N, L), 0.0); // diffuse lighting vec4 light = (diffuseLight*0.75*lambertTerm + ambientLight*0.25) * texture(lightmap_tex, uvLightmap, 0.f); light.a = 1.f; diff --git a/data/base/shaders/terrain_combined_high.frag b/data/base/shaders/terrain_combined_high.frag index 416d61795bb..d640c9bcbe6 100644 --- a/data/base/shaders/terrain_combined_high.frag +++ b/data/base/shaders/terrain_combined_high.frag @@ -89,10 +89,10 @@ void getGroundBM(int i, inout BumpData res) { float w = fgroundWeights[i]; res.color += texture2DArray(groundTex, uv, WZ_MIP_LOAD_BIAS) * w; vec3 N = texture2DArray(groundNormal, uv, WZ_MIP_LOAD_BIAS).xyz; - if (N == vec3(0)) { - N = vec3(0,0,1); + if (N == vec3(0.f)) { + N = vec3(0.f,0.f,1.f); } else { - N = normalize(N * 2 - 1); + N = normalize(N * 2.f - 1.f); } res.N += N * w; res.gloss += texture2DArray(groundSpecular, uv, WZ_MIP_LOAD_BIAS).r * w; @@ -113,9 +113,9 @@ vec4 doBumpMapping(BumpData b, vec3 lightDir, vec3 halfVec) { vec4 main_bumpMapping() { BumpData bump; - bump.color = vec4(0); - bump.N = vec3(0); - bump.gloss = 0; + bump.color = vec4(0.f); + bump.N = vec3(0.f); + bump.gloss = 0.f; getGroundBM(0, bump); getGroundBM(1, bump); getGroundBM(2, bump); @@ -126,16 +126,16 @@ vec4 main_bumpMapping() { vec4 decalColor = texture2DArray(decalTex, uv, WZ_MIP_LOAD_BIAS); float a = decalColor.a; // blend color, normal and gloss with ground ones based on alpha - bump.color = (1-a)*bump.color + a*vec4(decalColor.rgb, 1); + bump.color = (1.f - a)*bump.color + a*vec4(decalColor.rgb, 1.f); vec3 n = texture2DArray(decalNormal, uv, WZ_MIP_LOAD_BIAS).xyz; - if (n == vec3(0)) { - n = vec3(0,0,1); + if (n == vec3(0.f)) { + n = vec3(0.f,0.f,1.f); } else { - n = normalize(n * 2 - 1); + n = normalize(n * 2.f - 1.f); n = vec3(n.xy * decal2groundMat2, n.z); } - bump.N = (1-a)*bump.N + a*n; - bump.gloss = (1-a)*bump.gloss + a*texture2DArray(decalSpecular, uv, WZ_MIP_LOAD_BIAS).r; + bump.N = (1.f - a)*bump.N + a*n; + bump.gloss = (1.f - a)*bump.gloss + a*texture2DArray(decalSpecular, uv, WZ_MIP_LOAD_BIAS).r; } vec4 lightMask = texture(lightmap_tex, uvLightmap, 0.f); return lightMask * doBumpMapping(bump, groundLightDir, groundHalfVec); diff --git a/data/base/shaders/terrain_combined_medium.frag b/data/base/shaders/terrain_combined_medium.frag index 5446b637cdb..86773b91082 100644 --- a/data/base/shaders/terrain_combined_medium.frag +++ b/data/base/shaders/terrain_combined_medium.frag @@ -80,15 +80,15 @@ vec3 getGround(int i) { vec4 main_medium() { vec3 ground = getGround(0) + getGround(1) + getGround(2) + getGround(3); - vec4 decal = tile >= 0 ? texture2DArray(decalTex, vec3(uvDecal, tile), WZ_MIP_LOAD_BIAS) : vec4(0); + vec4 decal = tile >= 0 ? texture2DArray(decalTex, vec3(uvDecal, tile), WZ_MIP_LOAD_BIAS) : vec4(0.f); vec3 L = normalize(groundLightDir); - vec3 N = vec3(0,0,1); + vec3 N = vec3(0.f,0.f,1.f); float lambertTerm = max(dot(N, L), 0.0); // diffuse lighting vec4 light = (diffuseLight*0.75*lambertTerm + ambientLight*0.25) * texture(lightmap_tex, uvLightmap, 0.f); light.a = 1.f; - return light * vec4((1-decal.a) * ground + decal.a * decal.rgb, 1); + return light * vec4((1.f - decal.a) * ground + decal.a * decal.rgb, 1.f); } void main() diff --git a/data/base/shaders/terrain_water.vert b/data/base/shaders/terrain_water.vert index bdb30363676..3759c9fbaec 100644 --- a/data/base/shaders/terrain_water.vert +++ b/data/base/shaders/terrain_water.vert @@ -36,19 +36,19 @@ VERTEX_OUTPUT vec3 halfVec; void main() { - uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1)).xy; + uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; depth = vertex.w; depth2 = length(vertex.y - vertex.w); - vec2 uv1 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/4/128 + timeSec/40); // (ModelUV1Matrix * vertex).xy; - vec2 uv2 = vec2(vertex.x/4/128, -vertex.z/4/128 - timeSec/40); // (ModelUV2Matrix * vertex).xy; + vec2 uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; + vec2 uv2 = vec2(vertex.x/4.f/128.f, -vertex.z/4.f/128.f - timeSec/40.f); // (ModelUV2Matrix * vertex).xy; uv1_uv2 = vec4(uv1.x, uv1.y, uv2.x, uv2.y); vec3 eyeVec = normalize(cameraPos.xyz - vertex.xyz); lightDir = sunPos.xyz; halfVec = lightDir + eyeVec; - vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1); + vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); vertexDistance = position.z; gl_Position = position; } diff --git a/data/base/shaders/terrain_water_classic.vert b/data/base/shaders/terrain_water_classic.vert index c1627b1902b..b8388b89020 100644 --- a/data/base/shaders/terrain_water_classic.vert +++ b/data/base/shaders/terrain_water_classic.vert @@ -33,14 +33,14 @@ VERTEX_OUTPUT float vertexDistance; void main() { - uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1)).xy; + uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; depth = vertex.w; - vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1); + vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); gl_Position = position; vertexDistance = position.z; - uv1 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/2/128 + timeSec/40); // (ModelUV1Matrix * vertex).xy; - uv2 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/4/128 + timeSec/10); // (ModelUV2Matrix * vertex).xy; + uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/2.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; + uv2 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/10.f); // (ModelUV2Matrix * vertex).xy; } diff --git a/data/base/shaders/vk/terrain_combined_medium.frag b/data/base/shaders/vk/terrain_combined_medium.frag index 9dffdcc8c6e..ac7c13ba16a 100644 --- a/data/base/shaders/vk/terrain_combined_medium.frag +++ b/data/base/shaders/vk/terrain_combined_medium.frag @@ -34,15 +34,15 @@ vec3 getGround(int i) { vec4 main_medium() { vec3 ground = getGround(0) + getGround(1) + getGround(2) + getGround(3); - vec4 decal = fragf.tileNo >= 0 ? texture(decalTex, vec3(frag.uvDecal, fragf.tileNo), WZ_MIP_LOAD_BIAS) : vec4(0); + vec4 decal = fragf.tileNo >= 0 ? texture(decalTex, vec3(frag.uvDecal, fragf.tileNo), WZ_MIP_LOAD_BIAS) : vec4(0.f); vec3 L = normalize(frag.groundLightDir); - vec3 N = vec3(0,0,1); + vec3 N = vec3(0.f,0.f,1.f); float lambertTerm = max(dot(N, L), 0.0); // diffuse lighting vec4 light = (diffuseLight*0.75*lambertTerm + ambientLight*0.25) * texture(lightmap_tex, frag.uvLightmap); light.a = 1.f; - return light * vec4((1-decal.a) * ground + decal.a * decal.rgb, 1); + return light * vec4((1.f - decal.a) * ground + decal.a * decal.rgb, 1.f); } void main() diff --git a/data/base/shaders/vk/terrain_water.vert b/data/base/shaders/vk/terrain_water.vert index 8ee53eba04e..6d45230460c 100644 --- a/data/base/shaders/vk/terrain_water.vert +++ b/data/base/shaders/vk/terrain_water.vert @@ -31,19 +31,19 @@ layout(location = 7) out float depth2; void main() { - uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1)).xy; + uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; depth = vertex.w; depth2 = length(vertex.y - vertex.w); - vec2 uv1 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/4/128 + timeSec/40); // (ModelUV1Matrix * vertex).xy; - vec2 uv2 = vec2(vertex.x/4/128, -vertex.z/4/128 - timeSec/40); // (ModelUV2Matrix * vertex).xy; + vec2 uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; + vec2 uv2 = vec2(vertex.x/4.f/128.f, -vertex.z/4.f/128.f - timeSec/40.f); // (ModelUV2Matrix * vertex).xy; uv1_uv2 = vec4(uv1.x, uv1.y, uv2.x, uv2.y); vec3 eyeVec = normalize(cameraPos.xyz - vertex.xyz); lightDir = sunPos.xyz; halfVec = lightDir + eyeVec; - vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.0); + vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); vertexDistance = position.z; gl_Position = position; gl_Position.y *= -1.; diff --git a/data/base/shaders/vk/terrain_water_classic.vert b/data/base/shaders/vk/terrain_water_classic.vert index dcba5c0bd52..c1c0581c43d 100644 --- a/data/base/shaders/vk/terrain_water_classic.vert +++ b/data/base/shaders/vk/terrain_water_classic.vert @@ -24,13 +24,13 @@ layout(location = 5) out float depth; void main() { - uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1)).xy; + uvLightmap = (ModelUVLightmapMatrix * vec4(vertex.xyz, 1.f)).xy; depth = vertex.w; - uv1 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/4/128 + timeSec/40); // (ModelUV1Matrix * vertex).xy; - uv2 = vec2(vertex.x/4/128 + timeSec/80, -vertex.z/4/128 + timeSec/10); // (ModelUV2Matrix * vertex).xy; + uv1 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/40.f); // (ModelUV1Matrix * vertex).xy; + uv2 = vec2(vertex.x/4.f/128.f + timeSec/80.f, -vertex.z/4.f/128.f + timeSec/10.f); // (ModelUV2Matrix * vertex).xy; - vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1); + vec4 position = ModelViewProjectionMatrix * vec4(vertex.xyz, 1.f); vertexDistance = position.z; gl_Position = position; gl_Position.y *= -1.; diff --git a/data/base/shaders/vk/water.frag b/data/base/shaders/vk/water.frag index edb853c26ae..5f3161834d6 100644 --- a/data/base/shaders/vk/water.frag +++ b/data/base/shaders/vk/water.frag @@ -57,11 +57,11 @@ vec4 main_bumpMapping() vec3 N1 = texture(tex1_nm, uv2, WZ_MIP_LOAD_BIAS).xzy; // y is up in modelSpace vec3 N2 = texture(tex2_nm, uv1, WZ_MIP_LOAD_BIAS).xzy; vec3 N; //use overlay blending to mix normal maps properly - N.x = N1.x < 0.5 ? (2 * N1.x * N2.x) : (1 - 2 * (1 - N1.x) * (1 - N2.x)); - N.z = N1.z < 0.5 ? (2 * N1.z * N2.z) : (1 - 2 * (1 - N1.z) * (1 - N2.z)); - N.y = N1.y < 0.5 ? (2 * N1.y * N2.y) : (1 - 2 * (1 - N1.y) * (1 - N2.y)); - if (N == vec3(0,0,0)) { - N = vec3(0,1,0); + N.x = N1.x < 0.5 ? (2.0 * N1.x * N2.x) : (1.0 - 2.0 * (1.0 - N1.x) * (1.0 - N2.x)); + N.z = N1.z < 0.5 ? (2.0 * N1.z * N2.z) : (1.0 - 2.0 * (1.0 - N1.z) * (1.0 - N2.z)); + N.y = N1.y < 0.5 ? (2.0 * N1.y * N2.y) : (1.0 - 2.0 * (1.0 - N1.y) * (1.0 - N2.y)); + if (N == vec3(0.0,0.0,0.0)) { + N = vec3(0.0,1.0,0.0); } else { N = normalize(N * 2.0 - 1.0); } @@ -74,7 +74,7 @@ vec4 main_bumpMapping() float gaussianTerm = exp(-(exponent * exponent)); vec4 fragColor = (texture(tex1, uv1, WZ_MIP_LOAD_BIAS)+texture(tex2, uv2, WZ_MIP_LOAD_BIAS)) * (gloss+vec4(0.08,0.13,0.15,1.0)); - fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); + fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1.0-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); vec4 light = texture(lightmap_tex, uvLightmap, 0.f); return light * fragColor; } diff --git a/data/base/shaders/water.frag b/data/base/shaders/water.frag index 67ed0505861..641d7665588 100644 --- a/data/base/shaders/water.frag +++ b/data/base/shaders/water.frag @@ -67,11 +67,11 @@ vec4 main_bumpMapping() vec3 N1 = texture(tex1_nm, uv2, WZ_MIP_LOAD_BIAS).xzy; // y is up in modelSpace vec3 N2 = texture(tex2_nm, uv1, WZ_MIP_LOAD_BIAS).xzy; vec3 N; //use overlay blending to mix normal maps properly - N.x = N1.x < 0.5 ? (2 * N1.x * N2.x) : (1 - 2 * (1 - N1.x) * (1 - N2.x)); - N.z = N1.z < 0.5 ? (2 * N1.z * N2.z) : (1 - 2 * (1 - N1.z) * (1 - N2.z)); - N.y = N1.y < 0.5 ? (2 * N1.y * N2.y) : (1 - 2 * (1 - N1.y) * (1 - N2.y)); - if (N == vec3(0,0,0)) { - N = vec3(0,1,0); + N.x = N1.x < 0.5 ? (2.0 * N1.x * N2.x) : (1.0 - 2.0 * (1.0 - N1.x) * (1.0 - N2.x)); + N.z = N1.z < 0.5 ? (2.0 * N1.z * N2.z) : (1.0 - 2.0 * (1.0 - N1.z) * (1.0 - N2.z)); + N.y = N1.y < 0.5 ? (2.0 * N1.y * N2.y) : (1.0 - 2.0 * (1.0 - N1.y) * (1.0 - N2.y)); + if (N == vec3(0.0,0.0,0.0)) { + N = vec3(0.0,1.0,0.0); } else { N = normalize(N * 2.0 - 1.0); } @@ -85,7 +85,7 @@ vec4 main_bumpMapping() float gaussianTerm = exp(-(exponent * exponent)); vec4 fragColor = (texture(tex1, uv1, WZ_MIP_LOAD_BIAS)+texture(tex2, uv2, WZ_MIP_LOAD_BIAS)) * (gloss+vec4(0.08,0.13,0.15,1.0)); - fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); + fragColor = fragColor*(ambientLight+diffuseLight*lambertTerm) + specularLight*(1.0-gloss)*gaussianTerm*vec4(1.0,0.843,0.686,1.0); vec4 light = texture(lightmap_tex, uvLightmap, 0.f); return light * fragColor; }