Przeglądaj źródła

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

David Catuhe 6 lat temu
rodzic
commit
2a0a0d3064
1 zmienionych plików z 19 dodań i 2 usunięć
  1. 19 2
      src/Materials/effectRenderer.ts

+ 19 - 2
src/Materials/effectRenderer.ts

@@ -100,6 +100,14 @@ export class EffectRenderer {
     }
 
     /**
+     * Binds the embedded attributes buffer to the effect.
+     * @param effect Defines the effect to bind the attributes for
+     */
+    public bindBuffers(effect: Effect): void {
+        this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effect);
+    }
+
+    /**
      * Sets the current effect wrapper to use during draw.
      * The effect needs to be ready before calling this api.
      * This also sets the default full screen position attribute.
@@ -107,7 +115,7 @@ export class EffectRenderer {
      */
     public applyEffectWrapper(effectWrapper: EffectWrapper): void {
         this.engine.enableEffect(effectWrapper.effect);
-        this.engine.bindBuffers(this._vertexBuffers, this._indexBuffer, effectWrapper.effect);
+        this.bindBuffers(effectWrapper.effect);
         effectWrapper.onApplyObservable.notifyObservers({});
     }
 
@@ -244,6 +252,7 @@ export class EffectWrapper {
      */
     constructor(creationOptions: EffectWrapperCreationOptions) {
         let effectCreationOptions: any;
+        const uniformNames = creationOptions.uniformNames || [];
         if (creationOptions.vertexShader) {
             effectCreationOptions = {
                 fragmentSource: creationOptions.fragmentShader,
@@ -252,16 +261,24 @@ export class EffectWrapper {
             };
         }
         else {
+            // Default scale to use in post process vertex shader.
+            uniformNames.push("scale");
+
             effectCreationOptions = {
                 fragmentSource: creationOptions.fragmentShader,
                 vertex: "postprocess",
                 spectorName: creationOptions.name || "effectWrapper"
             };
+
+            // Sets the default scale to identity for the post process vertex shader.
+            this.onApplyObservable.add(() => {
+                this.effect.setFloat2("scale", 1, 1);
+            });
         }
 
         this.effect = new Effect(effectCreationOptions,
             creationOptions.attributeNames || ["position"],
-            creationOptions.uniformNames || ["scale"],
+            uniformNames,
             creationOptions.samplerNames,
             creationOptions.engine);
     }