Procházet zdrojové kódy

NME: Fix some bugs with particle shader (#8586)

* Fix crash when using a texture in a nme particle shader

* Fix infinite loop when editing a nme particle shader from a PG
Popov72 před 5 roky
rodič
revize
f0d928a5b1

+ 6 - 2
src/Materials/Node/Blocks/Dual/textureBlock.ts

@@ -52,7 +52,7 @@ export class TextureBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string, fragmentOnly = false) {
-        super(name, NodeMaterialBlockTargets.VertexAndFragment);
+        super(name, fragmentOnly ? NodeMaterialBlockTargets.Fragment : NodeMaterialBlockTargets.VertexAndFragment);
 
         this._fragmentOnly = fragmentOnly;
 
@@ -129,6 +129,10 @@ export class TextureBlock extends NodeMaterialBlock {
     }
 
     public get target() {
+        if (this._fragmentOnly) {
+            return NodeMaterialBlockTargets.Fragment;
+        }
+
         // TextureBlock has a special optimizations for uvs that come from the vertex shaders as they can be packed into a single varyings.
         // But we need to detect uvs coming from fragment then
         if (!this.uv.isConnected) {
@@ -300,7 +304,7 @@ export class TextureBlock extends NodeMaterialBlock {
             return;
         }
 
-        if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment || this._fragmentOnly) {
+        if (this.uv.ownerBlock.target === NodeMaterialBlockTargets.Fragment) {
             state.compilationString += `vec4 ${this._tempTextureRead} = texture2D(${this._samplerName}, ${uvInput.associatedVariableName});\r\n`;
             return;
         }

+ 3 - 3
src/Materials/Node/nodeMaterial.ts

@@ -836,7 +836,7 @@ export class NodeMaterial extends PushMaterial {
         return postProcess;
     }
 
-    private _createEffectForParticles(particleSystem: IParticleSystem, blendMode: number, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void, effect?: Effect, defines?: NodeMaterialDefines, dummyMesh?: Nullable<AbstractMesh>) {
+    private _createEffectForParticles(particleSystem: IParticleSystem, blendMode: number, onCompiled?: (effect: Effect) => void, onError?: (effect: Effect, errors: string) => void, effect?: Effect, defines?: NodeMaterialDefines, dummyMesh?: Nullable<AbstractMesh>, particleSystemDefinesJoined_ = "") {
         let tempName = this.name + this._buildId + "_" + blendMode;
 
         if (!defines) {
@@ -853,7 +853,7 @@ export class NodeMaterial extends PushMaterial {
         let buildId = this._buildId;
 
         let particleSystemDefines: Array<string> = [];
-        let particleSystemDefinesJoined = "";
+        let particleSystemDefinesJoined = particleSystemDefinesJoined_;
 
         if (!effect) {
             const result = this._processDefines(dummyMesh, defines);
@@ -898,7 +898,7 @@ export class NodeMaterial extends PushMaterial {
 
                 effect = this.getScene().getEngine().createEffectForParticles(tempName, this._fragmentCompilationState.uniforms, this._fragmentCompilationState.samplers, defines!.toString() + "\n" + particleSystemDefinesJoined, result?.fallbacks, onCompiled, onError, particleSystem);
                 particleSystem.setCustomEffect(effect, blendMode);
-                this._createEffectForParticles(particleSystem, blendMode, onCompiled, onError, effect, defines, dummyMesh); // add the effect.onBindObservable observer
+                this._createEffectForParticles(particleSystem, blendMode, onCompiled, onError, effect, defines, dummyMesh, particleSystemDefinesJoined); // add the effect.onBindObservable observer
                 return;
             }