Browse Source

Unify preparation of instance attributes.

- Add Array definition support to MaterialHelper.PrepareAttributesForInstances in order to avoid redundancies when pushing the required attributes where the defines are not of type MaterialDefines.
- Remove redundancies.
Markus Billharz 6 years ago
parent
commit
0866ffaeb9

+ 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. MaterialHelper.PrepareAttributesForInstances now supports Array definitions. ([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.PrepareAttributesForInstances(attribs, defines);
         }
 
         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.PrepareAttributesForInstances(attribs, defines);
         }
 
         if (this.customShaderOptions) {

+ 2 - 1
src/Materials/materialHelper.ts

@@ -577,7 +577,8 @@ export class MaterialHelper {
      * @param defines The current Defines of the effect
      */
     public static PrepareAttributesForInstances(attribs: string[], defines: any): void {
-        if (defines["INSTANCES"]) {
+        // Check if we are handling a MaterialDefine or an Array containing the #define
+        if (defines["INSTANCES"] || (defines instanceof Array && defines.indexOf("#define INSTANCES") > -1)) {
             attribs.push("world0");
             attribs.push("world1");
             attribs.push("world2");

+ 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.PrepareAttributesForInstances(attribs, defines);
         }
 
         // 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.PrepareAttributesForInstances(attribs, defines);
         }
 
         // 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.PrepareAttributesForInstances(attribs, defines);
         }
 
         // 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.PrepareAttributesForInstances(attribs, defines);
         }
 
         // Get correct effect