소스 검색

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

David Catuhe 6 년 전
부모
커밋
90482ad5ec

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

@@ -6,7 +6,8 @@
 
 ## Updates
 - Support Vive Focus 3Dof controller ([TrevorDev](https://github.com/TrevorDev))
-
+- Unify preparation of instance attributes. Added `MaterialHelper.PushAttributesForInstances` ([MarkusBillharz](https://github.com/MarkusBillharz))
+ 
 ### Inspector
 - Added support for `ShadowGenerator` ([Deltakosh](https://github.com/deltakosh/))
 - Added support for scene normalization ([Deltakosh](https://github.com/deltakosh/))

+ 1 - 4
src/Layers/effectLayer.ts

@@ -496,10 +496,7 @@ export abstract class EffectLayer {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         this._addCustomEffectDefines(defines);

+ 1 - 4
src/Lights/Shadows/shadowGenerator.ts

@@ -1221,10 +1221,7 @@ export class ShadowGenerator implements IShadowGenerator {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         if (this.customShaderOptions) {

+ 16 - 7
src/Materials/materialHelper.ts

@@ -14,6 +14,7 @@ import { UniformBuffer } from "./uniformBuffer";
 import { Effect, EffectFallbacks, EffectCreationOptions } from "./effect";
 import { BaseTexture } from "../Materials/Textures/baseTexture";
 import { WebVRFreeCamera } from '../Cameras/VR/webVRCamera';
+import { MaterialDefines } from "./materialDefines";
 
 /**
  * "Static Class" containing the most commonly used helper while dealing with material for
@@ -572,20 +573,28 @@ export class MaterialHelper {
     }
 
     /**
-     * Prepares the list of attributes required for instances according to the effect defines.
+     * Check and prepare the list of attributes required for instances according to the effect defines.
      * @param attribs The current list of supported attribs
-     * @param defines The current Defines of the effect
+     * @param defines The current MaterialDefines of the effect
      */
-    public static PrepareAttributesForInstances(attribs: string[], defines: any): void {
+    public static PrepareAttributesForInstances(attribs: string[], defines: MaterialDefines): void {
         if (defines["INSTANCES"]) {
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            this.PushAttributesForInstances(attribs);
         }
     }
 
     /**
+     * Add the list of attributes required for instances to the attribs array.
+     * @param attribs The current list of supported attribs
+     */
+    public static PushAttributesForInstances(attribs: string[]): void {
+        attribs.push("world0");
+        attribs.push("world1");
+        attribs.push("world2");
+        attribs.push("world3");
+    }
+
+    /**
      * Binds the light shadow information to the effect for the given mesh.
      * @param light The light containing the generator
      * @param scene The scene the lights belongs to

+ 1 - 1
src/Materials/shaderMaterial.ts

@@ -428,7 +428,7 @@ export class ShaderMaterial extends Material {
 
         if (useInstances) {
             defines.push("#define INSTANCES");
-            MaterialHelper.PrepareAttributesForInstances(attribs, defines);
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Bones

+ 2 - 4
src/PostProcesses/volumetricLightScatteringPostProcess.ts

@@ -9,6 +9,7 @@ import { Mesh } from "../Meshes/mesh";
 import { Camera } from "../Cameras/camera";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
+import { MaterialHelper } from "../Materials/materialHelper";
 import { StandardMaterial } from "../Materials/standardMaterial";
 import { Texture } from "../Materials/Textures/texture";
 import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
@@ -201,10 +202,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect

+ 2 - 4
src/Rendering/depthRenderer.ts

@@ -8,6 +8,7 @@ import { Texture } from "../Materials/Textures/texture";
 import { RenderTargetTexture } from "../Materials/Textures/renderTargetTexture";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
+import { MaterialHelper } from "../Materials/materialHelper";
 import { Camera } from "../Cameras/camera";
 import { Constants } from "../Engines/constants";
 
@@ -192,10 +193,7 @@ export class DepthRenderer {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect

+ 2 - 4
src/Rendering/geometryBufferRenderer.ts

@@ -8,6 +8,7 @@ import { Texture } from "../Materials/Textures/texture";
 import { MultiRenderTarget } from "../Materials/Textures/multiRenderTarget";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
+import { MaterialHelper } from "../Materials/materialHelper";
 import { Scene } from "../scene";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 
@@ -229,10 +230,7 @@ export class GeometryBufferRenderer {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Setup textures count

+ 2 - 4
src/Rendering/outlineRenderer.ts

@@ -8,6 +8,7 @@ import { Constants } from "../Engines/constants";
 import { ISceneComponent, SceneComponentConstants } from "../sceneComponent";
 import { Effect } from "../Materials/effect";
 import { Material } from "../Materials/material";
+import { MaterialHelper } from "../Materials/materialHelper";
 
 import "../Shaders/outline.fragment";
 import "../Shaders/outline.vertex";
@@ -255,10 +256,7 @@ export class OutlineRenderer implements ISceneComponent {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect