Sfoglia il codice sorgente

fixed particles fadeIn/Out (now is a range)

Nicolas Cannasse 8 anni fa
parent
commit
8e94a75dfb
3 ha cambiato i file con 10 aggiunte e 7 eliminazioni
  1. 2 1
      h3d/parts/GpuParticles.hx
  2. 4 3
      h3d/shader/GpuParticle.hx
  3. 4 3
      samples/GpuParticles.hx

+ 2 - 1
h3d/parts/GpuParticles.hx

@@ -228,6 +228,7 @@ class GpuPartGroup {
 		texture = loadTexture(o.texture);
 		colorGradient = loadTexture(o.colorGradient);
 		if( Math.isNaN(emitStartDist) ) emitStartDist = 0;
+		if( version == 1 ) fadeOut = 1 - fadeOut;
 	}
 
 	public function updateBounds( bounds : h3d.col.Bounds ) {
@@ -380,7 +381,7 @@ class GpuPartGroup {
 
 class GpuParticles extends h3d.scene.MultiMaterial {
 
-	static inline var VERSION = 1;
+	static inline var VERSION = 2;
 	static inline var STRIDE = 14;
 
 	var groups : Array<GpuPartGroup>;

+ 4 - 3
h3d/shader/GpuParticle.hx

@@ -98,9 +98,10 @@ class GpuParticle extends hxsl.Shader {
 				projectedPosition.xy += dist;
 			}
 			projectedPosition *= visibility;
-			var comp = vec2(normT, 1 - fadeOut) < vec2(fadeIn, normT);
-			var fade = vec2(t / fadeIn, (normT - 1 + fadeOut) / fadeOut).pow(fadePower.xx);
-			pixelColor.a *= (1 - comp.x * (1 - fade.x) - comp.y * fade.y).min(1.);
+			if( normT < fadeIn )
+				pixelColor.a *= (normT / fadeIn).pow(fadePower)
+			else if( normT > fadeOut )
+				pixelColor.a *= ((1 - normT) / (1 - fadeOut)).pow(fadePower);
 			colorUV = vec2(normT, randProp);
 		}
 

+ 4 - 3
samples/GpuParticles.hx

@@ -11,14 +11,15 @@ class GpuParticles extends SampleApp {
 		super.init();
 		parts = new h3d.parts.GpuParticles(s3d);
 
-		var g = new h3d.parts.GpuParticles.GpuPartGroup();
+		var g = new h3d.parts.GpuParticles.GpuPartGroup(parts);
 
 		g.emitMode = Cone;
 		g.emitAngle = 0.5;
 		g.emitDist = 0;
 
-		g.fadeIn = 0.1;
-		g.fadeOut = 0.2;
+		g.fadeIn = 0.8;
+		g.fadeOut = 0.8;
+		g.fadePower = 10;
 		g.gravity = 1;
 		g.size = 0.1;
 		g.sizeRand = 0.5;