Prechádzať zdrojové kódy

local space in billboard case

Benjamin Guignabert 5 rokov pred
rodič
commit
098d5f4799

+ 5 - 3
src/Particles/gpuParticleSystem.ts

@@ -1378,10 +1378,9 @@ export class GPUParticleSystem extends BaseParticleSystem implements IDisposable
             var emitterPosition = (<Vector3>this.emitter);
             emitterWM = Matrix.Translation(emitterPosition.x, emitterPosition.y, emitterPosition.z);
         }
-        if (this.isLocal) {
+
+        if (!this.isLocal) {
             this._updateEffect.setMatrix("emitterWM", emitterWM);
-        } else {
-            this._renderEffect.setMatrix("emitterWM", emitterWM);
         }
 
         // Bind source VAO
@@ -1405,6 +1404,9 @@ export class GPUParticleSystem extends BaseParticleSystem implements IDisposable
             this._renderEffect.setTexture("textureSampler", this.particleTexture);
             this._renderEffect.setVector2("translationPivot", this.translationPivot);
             this._renderEffect.setVector3("worldOffset", this.worldOffset);
+            if (this.isLocal) {
+                this._renderEffect.setMatrix("emitterWM", emitterWM);
+            }
             if (this._colorGradientsTexture) {
                 this._renderEffect.setTexture("colorGradientSampler", this._colorGradientsTexture);
             } else {

+ 5 - 1
src/Shaders/gpuRenderParticles.vertex.fx

@@ -140,7 +140,11 @@ void main() {
 		rotatedCorner.z = 0.;
 
 		// Expand position
-		vec4 viewPosition = view * vec4((position + worldOffset), 1.0) + rotatedCorner;
+		#ifdef LOCAL
+			vec4 viewPosition = view * vec4(((emitterWM * vec4(position, 1.0)).xyz + worldOffset), 1.0) + rotatedCorner;
+		#else
+			vec4 viewPosition = view * vec4((position + worldOffset), 1.0) + rotatedCorner;
+		#endif
 	#endif
 
 #else