瀏覽代碼

Properly set if TerrainMaterial is ready for sub mesh

Julien MOREAU-MATHIS 6 年之前
父節點
當前提交
1a29f504d3

+ 1 - 0
dist/preview release/what's new.md

@@ -120,6 +120,7 @@
 - Added the `cameraOffset` vector property in the `SkyMaterial` to get an offset according to the horizon ([julien-moreau](https://github.com/julien-moreau))
 - Fixed `GradientMaterial` to consider disableLighting working as emissive ([julien-moreau](https://github.com/julien-moreau))
 - Fixed fresnel term computation in `WaterMaterial` ([julien-moreau](https://github.com/julien-moreau))
+- Fixed `TerrainMaterial.isReadyForSubMesh` to remove WebGL warnings ([julien-moreau](https://github.com/julien-moreau))
 
 ## Bug fixes
 - Fixed TransformNode.setDirection (orientation was wrong) ([Deltakosh](https://github.com/deltakosh))

+ 1 - 1
materialsLibrary/src/terrain/terrain.fragment.fx

@@ -79,7 +79,7 @@ mat3 cotangent_frame(vec3 normal, vec3 p, vec2 uv)
 }
 
 vec3 perturbNormal(vec3 viewDir, vec3 mixColor)
-{	
+{
 	vec3 bump1Color = texture2D(bump1Sampler, vTextureUV * diffuse1Infos).xyz;
 	vec3 bump2Color = texture2D(bump2Sampler, vTextureUV * diffuse2Infos).xyz;
 	vec3 bump3Color = texture2D(bump3Sampler, vTextureUV * diffuse3Infos).xyz;

+ 28 - 7
materialsLibrary/src/terrain/terrainMaterial.ts

@@ -144,16 +144,37 @@ export class TerrainMaterial extends PushMaterial {
 
         // Textures
         if (scene.texturesEnabled) {
-            if (this.mixTexture && MaterialFlags.DiffuseTextureEnabled) {
-                if (!this.mixTexture.isReady()) {
+            if (!this.mixTexture || !this.mixTexture.isReady()) {
+                return false;
+            }
+
+            defines._needUVs = true;
+
+            if (MaterialFlags.DiffuseTextureEnabled) {
+                if (!this.diffuseTexture1 || !this.diffuseTexture1.isReady()) {
+                    return false;
+                }
+                if (!this.diffuseTexture2 || !this.diffuseTexture2.isReady()) {
+                    return false;
+                }
+                if (!this.diffuseTexture3 || !this.diffuseTexture3.isReady()) {
                     return false;
-                } else {
-                    defines._needUVs = true;
-                    defines.DIFFUSE = true;
                 }
+
+                defines.DIFFUSE = true;
             }
-            if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && MaterialFlags.BumpTextureEnabled) {
-                defines._needUVs = true;
+
+            if (this.bumpTexture1 && this.bumpTexture2 && this.bumpTexture3 && MaterialFlags.BumpTextureEnabled) {
+                if (!this.bumpTexture1.isReady()) {
+                    return false;
+                }
+                if (!this.bumpTexture2.isReady()) {
+                    return false;
+                }
+                if (!this.bumpTexture3.isReady()) {
+                    return false;
+                }
+
                 defines._needNormals = true;
                 defines.BUMP = true;
             }