Skip to content

Commit

Permalink
Shader fixes for OpenGL ES compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due authored and pull[bot] committed May 16, 2024
1 parent 6e668d8 commit 1155892
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions data/base/shaders/pointlights.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ float pointLightEnergyAtPosition(vec3 position, vec3 pointLightWorldPosition, fl
vec3 pointLightVector = position - pointLightWorldPosition;
float normalizedDistance = length(pointLightVector) / range;

float sqNormDist = normalizedDistance * normalizedDistance;
float numerator = max(1 - sqNormDist, 0);
return numerator * numerator / ( 1 + 2 * sqNormDist);
float sqNormDist = normalizedDistance * normalizedDistance;
float numerator = max(1.f - sqNormDist, 0.f);
return numerator * numerator / ( 1.f + 2.f * sqNormDist);
}

vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4 albedo, float gloss, vec3 pointLightWorldPosition, float pointLightEnergy, vec3 pointLightColor, mat3 normalWorldSpaceToLocalSpace)
Expand All @@ -27,9 +27,9 @@ vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4
vec3 pointLightDir = -normalize(pointLightVector * normalWorldSpaceToLocalSpace);

float energy = pointLightEnergyAtPosition(WorldFragPos, pointLightWorldPosition, pointLightEnergy);
vec4 lightColor = vec4(pointLightColor * energy, 1);
vec4 lightColor = vec4(pointLightColor * energy, 1.f);

float pointLightLambert = max(dot(fragNormal, pointLightDir), 0.0);
float pointLightLambert = max(dot(fragNormal, pointLightDir), 0.f);

vec3 pointLightHalfVec = normalize(viewVector + pointLightDir);

Expand All @@ -52,8 +52,8 @@ vec4 iterateOverAllPointLights(
float gloss,
mat3 normalWorldSpaceToLocalSpace
) {
vec4 light = vec4(0);
ivec2 bucket = ivec2(WZ_BUCKET_DIMENSION * clipSpaceCoord);
vec4 light = vec4(0.f);
ivec2 bucket = ivec2(float(WZ_BUCKET_DIMENSION) * clipSpaceCoord);
int bucketId = min(bucket.y + bucket.x * WZ_BUCKET_DIMENSION, WZ_BUCKET_DIMENSION * WZ_BUCKET_DIMENSION - 1);

for (int i = 0; i < bucketOffsetAndSize[bucketId].y; i++)
Expand All @@ -62,7 +62,7 @@ vec4 iterateOverAllPointLights(
int lightIndex = PointLightsIndex[entryInLightList / 4][entryInLightList % 4];
vec4 position = PointLightsPosition[lightIndex];
vec4 colorAndEnergy = PointLightsColorAndEnergy[lightIndex];
vec3 tmp = position.xyz * vec3(1., 1., -1.);
vec3 tmp = position.xyz * vec3(1.f, 1.f, -1.f);
light += processPointLight(WorldFragPos, fragNormal, viewVector, albedo, gloss, tmp, colorAndEnergy.w, colorAndEnergy.xyz, normalWorldSpaceToLocalSpace);
}
return light;
Expand Down
4 changes: 2 additions & 2 deletions data/base/shaders/tcmask_instanced.frag
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void main()
float distanceAboveTerrain = uvLightmap.z;
float lightmapFactor = 1.0f - (clamp(distanceAboveTerrain, 0.f, 300.f) / 300.f);

float specularMapValue = 0;
float specularMapValue = 0.f;

if (lambertTerm > 0.0)
{
Expand All @@ -369,7 +369,7 @@ void main()
light += vec4(blendAddEffectLighting(ambient.rgb, ((lightmap_vec4.rgb * lightmapFactor) / 3.f)), ambient.a) * diffuseMap * (1.0 + (1.0 - float(specularmap)));

#if WZ_POINT_LIGHT_ENABLED == 1
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight);
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(float(viewportWidth), float(viewportHeight));

mat3 identityMat = mat3(
1., 0., 0.,
Expand Down
2 changes: 1 addition & 1 deletion data/base/shaders/terrain_combined_high.frag
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ vec4 doBumpMapping(BumpData b, vec3 lightDir, vec3 halfVec) {

#if WZ_POINT_LIGHT_ENABLED == 1
// point lights
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(viewportWidth, viewportHeight);
vec2 clipSpaceCoord = gl_FragCoord.xy / vec2(float(viewportWidth), float(viewportHeight));
res += iterateOverAllPointLights(clipSpaceCoord, fragPos, b.N, normalize(halfVec - lightDir), b.color, b.gloss, ModelTangentMatrix);
#endif

Expand Down

0 comments on commit 1155892

Please sign in to comment.