Browse Source

Some tweaks

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
83c6b6eed9

+ 2 - 1
samples/physics_playground/assets/gpu_sparks.ankimtl

@@ -5,7 +5,8 @@
 		<input shaderInput="specColor" value="0.04 0.04 0.04"/>
 		<input shaderInput="roughness" value="9.0"/>
 		<input shaderInput="metallic" value="0.0"/>
-		<input shaderInput="emission" value="1024 1024 1024"/>
+		<input shaderInput="initialEmission" value="1024 1024 1024"/>
+		<input shaderInput="finalEmission" value="10 10 10"/>
 	</inputs>
 </material>
 

+ 4 - 4
shaders/DepthDownscale.glslp

@@ -41,12 +41,12 @@ F32 resolveDepths(Vec4 depths)
 {
 #if SAMPLE_RESOLVE_TYPE == MIN
 	Vec2 mind2 = min(depths.xy, depths.zw);
-	F32 depth = min(mind2.x, mind2.y);
+	const F32 depth = min(mind2.x, mind2.y);
 #elif SAMPLE_RESOLVE_TYPE == MAX
 	Vec2 max2 = max(depths.xy, depths.zw);
-	F32 depth = max(max2.x, max2.y);
+	const F32 depth = max(max2.x, max2.y);
 #elif SAMPLE_RESOLVE_TYPE == AVG
-	F32 depth = dot(depths, Vec4(1.0 / 4.0));
+	const F32 depth = dot(depths, Vec4(1.0 / 4.0));
 #else
 #	error See file
 #endif
@@ -70,7 +70,7 @@ void main()
 
 		if(u_copyToClientLevel == 0u)
 		{
-			U32 idx = gl_GlobalInvocationID.y * u_level0WriteImgSize.x + gl_GlobalInvocationID.x;
+			const U32 idx = gl_GlobalInvocationID.y * u_level0WriteImgSize.x + gl_GlobalInvocationID.x;
 			u_clientBuf[idx] = depth;
 		}
 	}

+ 9 - 1
shaders/GpuParticles.glslp

@@ -7,7 +7,8 @@
 #pragma anki input const Vec3 specColor
 #pragma anki input const F32 roughness
 #pragma anki input const F32 metallic
-#pragma anki input const Vec3 emission
+#pragma anki input const Vec3 initialEmission
+#pragma anki input const Vec3 finalEmission
 
 #include <shaders/glsl_cpp_common/GpuParticles.h>
 
@@ -25,7 +26,10 @@ layout(set = 0, binding = 0) buffer ssbo_
 
 #pragma anki start vert
 
+#include <shaders/Common.glsl>
+
 layout(location = 0) out Vec2 out_velocity;
+layout(location = 1) flat out F32 out_lifeFactor;
 
 void main()
 {
@@ -41,6 +45,8 @@ void main()
 
 	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
 	out_velocity = ((gl_VertexID & 1) == 0) ? Vec2(0.0) : (prevNdc - crntNdc) * 0.5;
+
+	out_lifeFactor = saturate(1.0 - (part.m_life / part.m_startingLife));
 }
 #pragma anki end
 
@@ -54,6 +60,7 @@ layout(location = 2) out Vec4 out_gbuffer2;
 layout(location = 3) out Vec2 out_gbuffer3;
 
 layout(location = 0) in Vec2 in_velocity;
+layout(location = 1) flat in F32 in_lifeFactor;
 
 void main()
 {
@@ -63,6 +70,7 @@ void main()
 	g.m_specular = specColor;
 	g.m_roughness = roughness;
 	g.m_subsurface = 0.0;
+	const Vec3 emission = mix(initialEmission, finalEmission, in_lifeFactor);
 	g.m_emission = (emission.r + emission.g + emission.b) / 3.0;
 	g.m_metallic = metallic;
 	g.m_velocity = in_velocity;

+ 2 - 1
shaders/GpuParticlesSimulation.glslp

@@ -87,7 +87,8 @@ void initParticle(out GpuParticle p)
 	p.m_oldWorldPosition = p.m_newWorldPosition;
 
 	p.m_mass = mix(u_props.m_minMass, u_props.m_maxMass, randFactor);
-	p.m_life = mix(u_props.m_minLife, u_props.m_maxLife, randFactor);
+	p.m_startingLife = mix(u_props.m_minLife, u_props.m_maxLife, randFactor);
+	p.m_life = p.m_startingLife;
 	p.m_acceleration = mix(u_props.m_minGravity, u_props.m_maxGravity, randFactor);
 
 	// Calculate the initial velocity

+ 1 - 1
shaders/glsl_cpp_common/GpuParticles.h

@@ -41,7 +41,7 @@ struct GpuParticle
 	F32 m_life;
 
 	Vec3 m_acceleration;
-	F32 m_padding0;
+	F32 m_startingLife; // The original max life
 
 	Vec3 m_velocity;
 	F32 m_padding1;

+ 0 - 3
src/anki/scene/GpuParticleEmitterNode.cpp

@@ -158,7 +158,6 @@ Error GpuParticleEmitterNode::init(const CString& filename)
 		this,
 		0 // No merging
 	);
-	rcomp->setFlags(rcomp->getFlags() | RenderComponentFlag::SORT_LAST);
 
 	return Error::NONE;
 }
@@ -238,9 +237,7 @@ void GpuParticleEmitterNode::draw(RenderQueueDrawContext& ctx) const
 
 		// Draw
 		cmdb->setLineWidth(8.0f);
-		cmdb->setDepthWrite(false);
 		cmdb->drawArrays(PrimitiveTopology::LINES, m_particleCount * 2);
-		cmdb->setDepthWrite(true);
 	}
 	else
 	{