Przeglądaj źródła

Add MaterialHelper.PushAttributesForInstances

- Add MaterialHelper.PushAttributesForInstances
- Remove Array.isArray check (Performance)
Markus Billharz 6 lat temu
rodzic
commit
8a99935108

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

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

+ 1 - 1
src/Layers/effectLayer.ts

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

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

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

+ 17 - 9
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,21 +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 {
-        // Check if we are handling a MaterialDefine or an Array containing the #define
-        if (defines["INSTANCES"] || Array.isArray(defines)) {
-            attribs.push("world0");
-            attribs.push("world1");
-            attribs.push("world2");
-            attribs.push("world3");
+    public static PrepareAttributesForInstances(attribs: string[], defines: MaterialDefines): void {
+        if (defines["INSTANCES"]) {
+            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

+ 1 - 1
src/PostProcesses/volumetricLightScatteringPostProcess.ts

@@ -202,7 +202,7 @@ export class VolumetricLightScatteringPostProcess extends PostProcess {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            MaterialHelper.PrepareAttributesForInstances(attribs, defines);
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect

+ 1 - 1
src/Rendering/depthRenderer.ts

@@ -193,7 +193,7 @@ export class DepthRenderer {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            MaterialHelper.PrepareAttributesForInstances(attribs, defines);
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect

+ 1 - 1
src/Rendering/geometryBufferRenderer.ts

@@ -230,7 +230,7 @@ export class GeometryBufferRenderer {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            MaterialHelper.PrepareAttributesForInstances(attribs, defines);
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Setup textures count

+ 1 - 1
src/Rendering/outlineRenderer.ts

@@ -256,7 +256,7 @@ export class OutlineRenderer implements ISceneComponent {
         // Instances
         if (useInstances) {
             defines.push("#define INSTANCES");
-            MaterialHelper.PrepareAttributesForInstances(attribs, defines);
+            MaterialHelper.PushAttributesForInstances(attribs);
         }
 
         // Get correct effect