Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix water shader compatability with glsl 1.10 #28

Merged
merged 1 commit into from
May 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions commons/src/main/com/mbrlabs/mundus/commons/shaders/water.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
precision mediump float;
#endif

in vec2 v_texCoord0;
in vec4 v_clipSpace;
in vec3 v_toCameraVector;
in vec3 v_fromLightVector;
varying vec2 v_texCoord0;
varying vec4 v_clipSpace;
varying vec3 v_toCameraVector;
varying vec3 v_fromLightVector;

uniform vec3 u_color;
uniform float u_alpha;
Expand All @@ -29,9 +29,9 @@ void main() {
vec2 reflectTexCoords = vec2(ndc.x, 1.0-ndc.y);

// Dudv distortion
vec2 distortedTexCoords = texture(u_dudvTexture, vec2(v_texCoord0.x + u_moveFactor, v_texCoord0.y)).rg*0.1;
vec2 distortedTexCoords = texture2D(u_dudvTexture, vec2(v_texCoord0.x + u_moveFactor, v_texCoord0.y)).rg*0.1;
distortedTexCoords = v_texCoord0 + vec2(distortedTexCoords.x, distortedTexCoords.y+u_moveFactor);
vec2 totalDistortion = (texture(u_dudvTexture, distortedTexCoords).rg * 2.0 - 1.0) * u_waveStrength * clamp(5/20.0,0.0,1.0);
vec2 totalDistortion = (texture2D(u_dudvTexture, distortedTexCoords).rg * 2.0 - 1.0) * u_waveStrength * clamp(5.0/20.0,0.0,1.0);

float minTexCoord = 0.005;
float maxTexCoord = 1.0 - minTexCoord;
Expand All @@ -45,12 +45,12 @@ void main() {
reflectTexCoords.y = clamp(reflectTexCoords.y, 0.001, 0.999);

// Sample textures with distortion
vec4 reflectColor = texture(u_texture, reflectTexCoords);
vec4 refractColor = texture(u_refractionTexture, refractTexCoords);
vec4 reflectColor = texture2D(u_texture, reflectTexCoords);
vec4 refractColor = texture2D(u_refractionTexture, refractTexCoords);

// Normal map
vec4 normalMapColor = texture(u_normalMapTexture, distortedTexCoords);
vec3 normal = vec3(normalMapColor.r * 2.0 - 1.0, normalMapColor.b * 3, normalMapColor.g * 2.0 - 1.0);
vec4 normalMapColor = texture2D(u_normalMapTexture, distortedTexCoords);
vec3 normal = vec3(normalMapColor.r * 2.0 - 1.0, normalMapColor.b * 3.0, normalMapColor.g * 2.0 - 1.0);
normal = normalize(normal);

// Fresnel Effect
Expand All @@ -64,7 +64,7 @@ void main() {
vec3 specularHighlights = u_lightColor * specular * reflectivity;

vec4 color = mix(reflectColor, refractColor, refractiveFactor);
color = mix(color, COLOR_TURQUOISE, 0.2f) + vec4(specularHighlights, 0.0);
color = mix(color, COLOR_TURQUOISE, 0.2) + vec4(specularHighlights, 0.0);

gl_FragColor = color;
}