Bladeren bron

waterMaterial more physically realistc

- better bump waves
- physically correct water color + reflection combination
- more specular glare for hard lights (sun/moon)

Before/after pictures:

https://www.dropbox.com/sh/4t4r5d0l69v8jsq/AAC30ZOsiq_4_eBhjdk0w09ma?dl=0
László Matuska 9 jaren geleden
bovenliggende
commit
5d7322dfc5
1 gewijzigde bestanden met toevoegingen van 15 en 8 verwijderingen
  1. 15 8
      materialsLibrary/materials/water/water.fragment.fx

+ 15 - 8
materialsLibrary/materials/water/water.fragment.fx

@@ -74,7 +74,8 @@ void main(void) {
 	float alpha = vDiffuseColor.a;
 
 #ifdef BUMP
-	baseColor = texture2D(normalSampler, vNormalUV);
+    //smaller bumps superimposed (better moving waves, no "conveyor belt" look):
+	baseColor = (texture2D(normalSampler, vNormalUV) + texture2D(normalSampler,vec2(-vNormalUV.y*0.33,vNormalUV.x*0.33)))/2.0;
 	vec3 bumpColor = baseColor.rgb;
 
 #ifdef ALPHATEST
@@ -93,8 +94,9 @@ void main(void) {
 
 	// Bump
 #ifdef NORMAL
-	vec3 normalW = normalize(vNormalW);
+    //reflection angle is also perturbed
 	vec2 perturbation = bumpHeight * (baseColor.rg - 0.5);
+	vec3 normalW = normalize(vNormalW + vec3(perturbation.x*3.0,perturbation.y*3.0,0.0));
 #else
 	vec3 normalW = vec3(1.0, 1.0, 1.0);
 	vec2 perturbation = bumpHeight * (vec2(1.0, 1.0) - 0.5);
@@ -106,17 +108,21 @@ void main(void) {
 	
 	vec2 projectedRefractionTexCoords = clamp(vRefractionMapTexCoord.xy / vRefractionMapTexCoord.z + perturbation, 0.0, 1.0);
 	vec4 refractiveColor = texture2D(refractionSampler, projectedRefractionTexCoords);
-	
+
+    //refraction (sea bed) combined with the water color: TODO: fog-like shallow underwater
+    refractiveColor = colorBlendFactor*waterColor + (1.0-colorBlendFactor)*refractiveColor;
+
 	vec2 projectedReflectionTexCoords = clamp(vReflectionMapTexCoord.xy / vReflectionMapTexCoord.z + perturbation, 0.0, 1.0);
 	vec4 reflectiveColor = texture2D(reflectionSampler, projectedReflectionTexCoords);
 	
 	vec3 upVector = vec3(0.0, 1.0, 0.0);
-	
-	float fresnelTerm = max(dot(eyeVector, upVector), 0.0);
+
+	//physically correct water reflection by look angle
+	float fresnelTerm = min(0.95, pow(max(dot(eyeVector, upVector), 0.0),1.5));
 	
 	vec4 combinedColor = refractiveColor * fresnelTerm + reflectiveColor * (1.0 - fresnelTerm);
 	
-	baseColor = colorBlendFactor * waterColor + (1.0 - colorBlendFactor) * combinedColor;
+	baseColor = combinedColor;
 #endif
 
 	// Lighting
@@ -139,12 +145,13 @@ void main(void) {
 #endif
 
 #ifdef SPECULARTERM
-	vec3 finalSpecular = specularBase * specularColor;
+    //specular glare: more concentrated (no flat surface, specular is only for hard lights)
+	vec3 finalSpecular = specularBase * 2.0 * specularColor * specularColor;
 #else
 	vec3 finalSpecular = vec3(0.0);
 #endif
 
-	vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;
+	vec3 finalDiffuse = clamp(baseColor.rgb, 0.0, 1.0);
 
 	// Composition
 	vec4 color = vec4(finalDiffuse + finalSpecular, alpha);