Skip to content

Commit

Permalink
Fix-up float literals in shaders
Browse files Browse the repository at this point in the history
OpenGL ES is particularly picky about this
  • Loading branch information
past-due committed Jun 25, 2023
1 parent f56eb23 commit 65ace3f
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions data/base/shaders/terrain_combined_classic.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions data/base/shaders/terrain_combined_high.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions data/base/shaders/terrain_combined_medium.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions data/base/shaders/terrain_water.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions data/base/shaders/terrain_water_classic.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
6 changes: 3 additions & 3 deletions data/base/shaders/vk/terrain_combined_medium.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions data/base/shaders/vk/terrain_water.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand Down
8 changes: 4 additions & 4 deletions data/base/shaders/vk/terrain_water_classic.vert
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand Down
12 changes: 6 additions & 6 deletions data/base/shaders/vk/water.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions data/base/shaders/water.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 65ace3f

Please sign in to comment.