فهرست منبع

re-commit after merge.

Should be ok now.
László Matuska 9 سال پیش
والد
کامیت
659dab7a04
2فایلهای تغییر یافته به همراه22 افزوده شده و 9 حذف شده
  1. 15 3
      materialsLibrary/materials/water/babylon.waterMaterial.ts
  2. 7 6
      materialsLibrary/materials/water/water.fragment.fx

+ 15 - 3
materialsLibrary/materials/water/babylon.waterMaterial.ts

@@ -70,16 +70,26 @@ module BABYLON {
         @serialize()
 		public bumpHeight: number = 0.4;
         /**
-        * @param {number}: The water color blended with the reflection and refraction samplers
+        * @param {number}: The water color blended with the refraction (near)
         */
         @serializeAsColor3()
 		public waterColor: Color3 = new Color3(0.1, 0.1, 0.6);
         /**
-        * @param {number}: The blend factor related to the water color
+        * @param {number}: The blend factor related to the water color (refraction, near)
         */
         @serialize()
 		public colorBlendFactor: number = 0.2;
         /**
+         * @param {number}: The water color blended with the reflection (far)
+         */
+        @serializeAsColor3()
+        public waterColor2: Color3 = new Color3(0.1, 0.1, 0.6);
+        /**
+         * @param {number}: The blend factor related to the water color (reflection, far)
+         */
+        @serialize()
+        public colorBlendFactor2: number = 0.2;
+        /**
         * @param {number}: Represents the maximum length of a wave
         */
         @serialize()
@@ -345,7 +355,7 @@ module BABYLON {
 
                     // Water
                     "worldReflectionViewProjection", "windDirection", "waveLength", "time", "windForce",
-                    "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "colorBlendFactor", "waveSpeed"
+                    "cameraPosition", "bumpHeight", "waveHeight", "waterColor", "waterColor2", "colorBlendFactor", "colorBlendFactor2", "waveSpeed"
                 ]
                 var samplers = ["normalSampler",
                     // Water
@@ -448,6 +458,8 @@ module BABYLON {
             this._effect.setFloat("bumpHeight", this.bumpHeight);
 			this._effect.setColor4("waterColor", this.waterColor, 1.0);
 			this._effect.setFloat("colorBlendFactor", this.colorBlendFactor);
+            this._effect.setColor4("waterColor2", this.waterColor2, 1.0);
+            this._effect.setFloat("colorBlendFactor2", this.colorBlendFactor2);
             this._effect.setFloat("waveSpeed", this.waveSpeed);
 
             super.bind(world, mesh);

+ 7 - 6
materialsLibrary/materials/water/water.fragment.fx

@@ -47,6 +47,9 @@ uniform vec3 cameraPosition;
 uniform vec4 waterColor;
 uniform float colorBlendFactor;
 
+uniform vec4 waterColor2;
+uniform float colorBlendFactor2;
+
 uniform float bumpHeight;
 
 // Water varyings
@@ -108,18 +111,16 @@ 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);
-	
+	reflectiveColor = colorBlendFactor2*waterColor2 + (1.0-colorBlendFactor2)*reflectiveColor;
+
 	vec3 upVector = vec3(0.0, 1.0, 0.0);
 
-	//physically correct water reflection by look angle
-	float fresnelTerm = min(0.95, pow(max(dot(eyeVector, upVector), 0.0),1.5));
-	
+	float fresnelTerm = min(0.95, pow(max(dot(eyeVector, upVector), 0.0),3.0));
+
 	vec4 combinedColor = refractiveColor * fresnelTerm + reflectiveColor * (1.0 - fresnelTerm);
 	
 	baseColor = combinedColor;