Bläddra i källkod

Almost feature complete

Panagiotis Christopoulos Charitos 6 år sedan
förälder
incheckning
1c7f987929

BIN
samples/physics_playground/assets/Icosphere.ankimesh


+ 9 - 0
samples/physics_playground/assets/Icospherewalls-material.ankimdl

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<model>
+	<modelPatches>
+		<modelPatch>
+			<mesh>assets/Icosphere.ankimesh</mesh>
+			<material>assets/walls-material.ankimtl</material>
+		</modelPatch>
+	</modelPatches>
+</model>

+ 11 - 0
samples/physics_playground/assets/gpu_sparks.ankimtl

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<material shaderProgram="shaders/GpuParticles.glslp" shadow="0">
+	<inputs>
+		<input shaderInput="diffColor" value="1.0 0.1 0.1"/>
+		<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="10 10 10"/>
+	</inputs>
+</material>
+

+ 13 - 0
samples/physics_playground/assets/gpu_sparks.ankipart

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<particleEmitter>
+	<life min="1" max="1.2"/>
+	<gravity value="0.0 -9 0.0"/>
+
+	<startingPosition min="-0.04 0.1 -0.04" max="0.04 0.1 0.04"/>
+
+	<maxNumberOfParticles value="10"/>
+	<emissionPeriod value="0.05"/>
+	<particlesPerEmission value="1"/>
+	<material value="assets/gpu_sparks.ankimtl"/>
+</particleEmitter>

+ 3 - 3
shaders/GpuParticles.glslp

@@ -31,12 +31,12 @@ void main()
 {
 {
 	const Particle part = u_particles[gl_VertexID / 2];
 	const Particle part = u_particles[gl_VertexID / 2];
 
 
-	const Vec4 clipPos = u_mvp * Vec4(part.m_newWorldPosition, 1.0);
+	const Vec4 crntClipPos = u_mvp * Vec4(part.m_newWorldPosition, 1.0);
 	const Vec4 prevClipPos = u_mvp * Vec4(part.m_oldWorldPosition, 1.0);
 	const Vec4 prevClipPos = u_mvp * Vec4(part.m_oldWorldPosition, 1.0);
 
 
-	gl_Position = ((gl_VertexID & 1) == 0) ? clipPos : prevClipPos;
+	gl_Position = ((gl_VertexID & 1) == 0) ? crntClipPos : prevClipPos;
 
 
-	const Vec2 crntNdc = clipPos.xy / clipPos.w;
+	const Vec2 crntNdc = crntClipPos.xy / crntClipPos.w;
 	const Vec2 prevNdc = prevClipPos.xy / prevClipPos.w;
 	const Vec2 prevNdc = prevClipPos.xy / prevClipPos.w;
 
 
 	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:
 	// It's NDC_TO_UV(prevNdc) - NDC_TO_UV(crntNdc) or:

+ 17 - 1
src/anki/scene/GpuParticleEmitterNode.cpp

@@ -212,7 +212,23 @@ void GpuParticleEmitterNode::draw(RenderQueueDrawContext& ctx) const
 		m_emitterRsrc->getRenderingInfo(ctx.m_key.m_lod, prog);
 		m_emitterRsrc->getRenderingInfo(ctx.m_key.m_lod, prog);
 		cmdb->bindShaderProgram(prog);
 		cmdb->bindShaderProgram(prog);
 
 
-		// TODO
+		// Resources
+		cmdb->bindStorageBuffer(0, 0, m_particlesBuff, 0, MAX_PTR_SIZE);
+
+		struct PC
+		{
+			Mat4 m_mvp;
+			Vec3 m_minusCameraZ;
+			U32 m_particleCount;
+		} pc;
+
+		pc.m_mvp = ctx.m_viewProjectionMatrix;
+		pc.m_minusCameraZ = ctx.m_cameraTransform.getColumn(2).xyz();
+		pc.m_particleCount = m_particleCount;
+		cmdb->setPushConstants(&pc, sizeof(pc));
+
+		// Draw
+		cmdb->drawArrays(PrimitiveTopology::LINES, m_particleCount * 2);
 	}
 	}
 	else
 	else
 	{
 	{