From 976856a0bd7182e2d6400126a1e6fd8968c10501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katharina=20Kr=C3=A4mer?= <kkraemer4@uni-koblenz.de> Date: Fri, 25 Jun 2021 10:03:20 +0200 Subject: [PATCH] [#69] edited particle application --- .../particle_simulation/shaders/comp1.spv | Bin 5328 -> 3772 bytes projects/particle_simulation/shaders/frag.spv | Bin 1156 -> 2556 bytes .../particle_simulation/shaders/shader.frag | 10 +++++++--- .../particle_simulation/shaders/shader.vert | 4 ++++ .../particle_simulation/shaders/shader1.comp | 7 ++++--- projects/particle_simulation/shaders/vert.spv | Bin 2116 -> 2396 bytes projects/particle_simulation/src/Particle.cpp | 3 ++- projects/particle_simulation/src/Particle.hpp | 2 ++ projects/particle_simulation/src/main.cpp | 17 ++++++++++------- 9 files changed, 29 insertions(+), 14 deletions(-) diff --git a/projects/particle_simulation/shaders/comp1.spv b/projects/particle_simulation/shaders/comp1.spv index e328ebb349371bff7bebebd787f04a2ffca07f24..ab40b1dac97d20bd5fa078460e8297edfd3e9acc 100644 GIT binary patch literal 3772 zcmZQ(Qf6mhU}WH8;ANP?00DvwObm<+3=G^1Y+%~mC)h`?xFki-#MA(!f{%e2M1ke_ z8Q2(D85kH?7#J9G6EpKb5;6=73<3;nU@<|E03*l-2xewrW?*7qU^v7G(!<H%?i24A z<P=|=T98<jSdtoFoROH4S`?q3l$DxXQVdeV1ybYg@9*y88lPNH5MNwUnUflylbM$q zpORUWnp~1umI_kGfut@oFFB_)1z7<r0}I$aFgJquoD2*M=|zcUnI)ABtPE@nAh$yK z0r{DEB_OA>GB7hpGB7Y?rZ6zDGH@_}{Fa^*@1B#Nl$hh0SC*fgSdy8a=jp-#l4oU5 zWME(jNGvMJOwLIK>1ShL1B-#!1^LC9AjKdyOdJ%>IhkpxA(^=->Oo;tmYS2F400R; z0|QJwDC7$gQ&KYX(<5cCs@lGcYhDm8PYo7R6`gAz2R61Cj&Thb#f|lPX9Mte=%Z zi-Cb5IX|zs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Fe!fGE_gPEdgrVTtTYWL25x^2r>sG4pIx! z2Qud>nmN~?{)Cxx9myP!T2R{tWDZCir1mcZBZCD4BLk=n3vvgj{|!nmp!UBx12ecU z3L49Su|a)#P`cp-+Y9Ndg2re-dO>YlP}vOXD<ktk^%^oCG(H33gZu!Z<)Qs$7$4M^ z2iXa$t3ds6kQ$IU$n7BeKw>cUDhvz^ATbzU70RCiZ6ByHFff4BfW$%Z1Bz311_lO@ zIH+$4G85!xkQm4ekh~TH19+?nlwLr5ZD@J{xdSBE0X18Pfq?;(CqeQcb3lFtiNVa# zV_*P}Pr>;5P(G{;0vZqmsR4<@)EJ_v0gVrV)Pcl7c7VbUBnDCs3O{40e?feZTTK`k l7(i-Z>D82hfdQljBn}fZXJB9eiG%vS{}`AUKzvX-006q05%B;3 diff --git a/projects/particle_simulation/shaders/frag.spv b/projects/particle_simulation/shaders/frag.spv index a37f971964481b32a05bafc7efcf0c7b4b25671e..43a80b0da3b74e4cb9617da580d9000b0b68eaf6 100644 GIT binary patch literal 2556 zcmZQ(Qf6mhU}WH8;AKc*fB-=TCI&_Z1_o{hHZbk(6YQf`T#}+^Vrl?V!N<T1qQG+e z44e!s3=CkLo0ypgl8|CxV31*8U@&B0U`SwKU=Uzn2FtTEFfcGPFf%YQFfbfq1nJ>q zaQBIK404JuPAy0*N-Rl@FV09zNiB-cPs&P7E-417;R2~~_xE@Aag9$dD2OjEsmw`@ z&&kY7jZeueN=+`wEK3Ec<3LiEnU|bXnu4r=m4OB92ACT`d`<=ihTQzp;#39(237`E z1}+8$hSGri;>?oFe2_=j7}&sKAU_o#gu!Zg7#J9kl!C=T{?0Egan8@lF9PXdWncq` zLwZiUTTx=VbAEmiIEX>wps*=OEH2K;OiK;P%mq1t0VECzFOYaxYEFJ~W=SQ)92SN| zklUapvoWxO`5?JusAVAkBr`BDK$S3fK>Y(!qYNS#7#Q3cn8E%5g}*xk3j@dxN^m&{ zUy%Wn8bE4U7(o7!Ly`x@DK`TH13%a-7I6H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(ADfdM22%IBbPf$0I!uyFAO*EgX2#=rnl4>AuHE`AIQ3?O-s|3LnN z+2aqj2No^?3=9k)F;KX`)C8ib31VPi0EvOrz``yVRL?UoFo5Jh=7TUS>_QkA7(ntM zH^9O!l!1W(6n-E%m_1=odthM~&cMI`5(D`e=8p&l1_qEg%pWj2q8Jz$KxH0C9%e^0 v0|Nud9*`VNT?_*Q14tZ{Phjd|85kHq`4l7vDmOs&3rOrQ10#b410w?f=O4k5 delta 339 zcmew(+``Gr%%sfDz`)4B#lXv;GLhF*oSlJ%fdPzj6EpJ|7#J9&7#J87CMN!8RG2)G zQCwA#fq|jaIX@@Ah=GBPft3No2PsR22r;lSurMf3KFb*IsKCI$AjbeQoq@pvNu@GK zIRgWOI|DOVHxro6!T=Iig3GZmC~xj%VrQ(^W?*4pV_;yA21_;A!}u~_J_Cae13QBR z0|SFBR1HWRhQ%3Jz)k?^X9oF$frUXH>LifUtf736QyIa|g*XXho&p04gAxOS5Ch14 hAYXzMgWRV)S(0_Jh#dnnIA}oD{$*ffuwY<h003%`8#@31 diff --git a/projects/particle_simulation/shaders/shader.frag b/projects/particle_simulation/shaders/shader.frag index 1c228be0..7acc2c60 100644 --- a/projects/particle_simulation/shaders/shader.frag +++ b/projects/particle_simulation/shaders/shader.frag @@ -2,6 +2,7 @@ #extension GL_ARB_separate_shader_objects : enable layout(location = 1) in vec3 passVelocity; +layout(location = 2) in float passlifeTime; layout(location = 0) out vec4 outColor; @@ -16,7 +17,10 @@ layout(set=0,binding=1) uniform uPosition{ void main() { vec2 mouse = vec2(Position.position.x, Position.position.y); - outColor = vec4(1,0,0,0); - //outColor = float(distance(gl_FragCoord.xy, mouse) < 100) * vec4(0,0,1,0) + - // float(distance(gl_FragCoord.xy, mouse) >= 100) * Color.color; + outColor = float(distance(gl_FragCoord.xy, vec2(400,300)) <= 30) * vec4(1,1,1,0) + + float(distance(gl_FragCoord.xy, vec2(400,300)) > 30) * + (float(passlifeTime < 1) * vec4(1,1,0,0) + + float(passlifeTime < 2 && passlifeTime > 1) * vec4(1,passlifeTime * 0.5,0,0) + + float(passlifeTime >= 2 && passlifeTime < 2.5f) * vec4(passlifeTime * 0.5,passlifeTime * 0.5,0,0) + + float(passlifeTime >= 2.5f) * vec4(1,0,0,0)); } \ No newline at end of file diff --git a/projects/particle_simulation/shaders/shader.vert b/projects/particle_simulation/shaders/shader.vert index d68f087f..16c860df 100644 --- a/projects/particle_simulation/shaders/shader.vert +++ b/projects/particle_simulation/shaders/shader.vert @@ -9,6 +9,8 @@ struct Particle float lifeTime; vec3 velocity; float padding_2; + vec3 reset_velocity; + float padding_3; }; layout(std430, binding = 2) coherent buffer buffer_inParticle @@ -21,11 +23,13 @@ layout( push_constant ) uniform constants{ }; layout(location = 1) out vec3 passVelocity; +layout(location = 2) out float passlifeTime; void main() { int id = gl_InstanceIndex; passVelocity = inParticle[id].velocity; + passlifeTime = inParticle[id].lifeTime; vec3 moved_particle = particle + inParticle[id].position; gl_Position = mvp * vec4(moved_particle, 1.0); } \ No newline at end of file diff --git a/projects/particle_simulation/shaders/shader1.comp b/projects/particle_simulation/shaders/shader1.comp index 38abe941..7ce0b5c3 100644 --- a/projects/particle_simulation/shaders/shader1.comp +++ b/projects/particle_simulation/shaders/shader1.comp @@ -17,8 +17,8 @@ layout(std430, binding = 0) coherent buffer buffer_inParticle }; layout( push_constant ) uniform constants{ - vec3 respawnPos; float deltaTime; + float rand; }; vec3 attraction(vec3 pos, vec3 attractPos) @@ -64,8 +64,9 @@ void main() { // vel += repulsion(pos, respawnPos) * 0.05; - if((pos.x < -1.0) || (pos.x > 1.0) || (pos.y < -1.0) || (pos.y > 1.0)|| (pos.z < -1.0) || (pos.z > 1.0)) - vel = (-vel * 0.1) + attraction(pos, respawnPos) * 12; + //if((pos.x < -1.0) || (pos.x > 1.0) || (pos.y < -1.0) || (pos.y > 1.0)|| (pos.z < -1.0) || (pos.z > 1.0)) + if((pos.x < -1.0) || (pos.x > 1.0)) + vel = (-vel * 0.1); pos += normalize(vel) * deltaTime; inParticle[id].position = pos; diff --git a/projects/particle_simulation/shaders/vert.spv b/projects/particle_simulation/shaders/vert.spv index bdfc6c77e59f2b2a73ea0c4ec9a44086a438d15e..2487c41569e344770c3a15c5266099a2cb234de6 100644 GIT binary patch delta 1204 zcmX>ia7T!jnMs+Qfq{{Mi-DKHX(F$wG8Y2~urM$%<R)h3f!H7seg*~x83qOhRR#tI z!;OjdjD~Cs><j`73=ANZMXAN9CGlmcIr+(%C6x>eYz%B*IaUS+hJwVDl+3*Jc;m@) z8ND3~5{rv-GSgB+GILWwX0tM|F(`xV$}dYzi7!YjD#=XFNo8PQWncx{g%AOWu`%dR z7Gx5a)CXy0U|>kki4Vvx&Me8y&tm|&M}M*-lQg6L<XA9S$t2Bd2vrF(&v^1eCSgHi zs7P*E0Rt-oGlS{mqfF(d9t^Bt7lV8Qa*qN70|QJ9<O`6P4g&*&I|B=YAOpyU3=9U7 zJ(<H5L7^hYz`(!+l?8<mh!3&`WP<+Wjm*N4AQv+-Ffed4fC3w0Hb@Ml3na!2wGSi) zVuQp$ZgFQ|W&nwS)Oj$lFu+_7audjO<H;YHgc*$|8?t~%SC*NK9Fy;}h)#aPQc({w zhlhcI!J2`EK^hu=ATezQ76vv31_qETL2goDU}2Dl`T(RJ#8+ZqU|?rpVBlq7U;yz| zpza3oLFR$@AfJNti!-n=XfrS{fb@dgEXu&bpu@mW&j1QUP%wZj1O=Wh)DRg476v`2 z29TH>0~^?rFhf9cAPlnDfPsMl<Y-VJfGh^_L6Hg)lVD(BFk)Z;TMn{Vj)55*Kp-&% z25%My69xtbP6h_BAV@QaZweIy8Eyt;gEW8~3G#sz$i)l|_8@r&sO8#|bJ>hpL1Cgi zc_~|dJt*{K85kHi7#J8F8Q8(02lA{40|SF70|Ns{4ivh!3@qSKQ3Qt~1A`p{GdLH4 z_#in@XsSVT6^IWqR~^Y*2?hoR4F(1Vn7JT1QBcT&6oWKtLKQSJu!5sXi-CawWFSZ! zWEm*gg2WsdSQ$W`HD_R800jWZksvcb9=Bj%U;v4O_#iVa85qD>GLV54?09Pi1_qEA zC|n?7RSXO^P(e`qLj)NZY@uSHv>L#`4vrQ(aQcI&2g!p%cOnBTSk9h-fdOPWNDat= bpwM;%l`qgx1bG0&2dVqZz{p_1z{mgqNq=KT delta 946 zcmca3bVPucnMs+Qfq{{Mi-DKHdLpl>JSPJPurM$%<R)h3f!JIO3=I4X3=DD%3=CQu zQ|%ci-(d96%*`)LO^Gi^EGo%N&PiopU}azht3Zf=#Ml@#CMPn9OKN}&VqjoM&xsGn zFU~B<%+F(BV_;{{m^_h5no(o&S}=K%Nt#y+suE<L&g73w!h$+bk=(KZ237`U2EECm z%;mi93@i+S3=9lx3=9kklMgb7TY}sN!XV`y46F<=JGnsu3=9k~F-8Uk29Owt28&Hj zWDzz5sb+@CfPC-HzzjBl39OTa0p<!;FrSq{XR;%+uqaHFoq>TtfPsMlq)TV=S(cg1 zYzzXE3t5}%K{C7`H!`p=$TEO}nt=htw}$dTE(W<ooPmWwg@J*Ahk=0sWWOi_3xg_H zAH@0EP`(<}3>gL%26d=<keD0;8`!-tGeC0c3=H)Q3Jfd^nhXpKAkTq339=Z(2L&`p zOoD-hL7RaAY&pncIR<91XF*~hy}Aqx44^~-@+wF#h_43~1Ig<{*&y{GM}j<H40dya zy#fO_3xg%pa+S%p?8dCp3=9l1lS|q2>p`I)4^3CL3@nhCWME+6U|?WyWMF5IU|?WS zWME(rVPIeog@y!(2B`(<Rf5VlGO&U}RGEQ+0c0LX+>U{nL56{W0VL+gz{&t}qyYm1 z1IXb}GwQ*<He_I607<|MH3B)0fq@~AffXDTCJYP=ATf}KU}C0FF;KL@#LS>#pyU$3 zzzz;ga|Q+mkbaPQkUS_<CNi*s<t#v^f-DCq0=W<rN>-p82K6n-2Oz!$0|Ucf21W)8 H21W(|TVhFd diff --git a/projects/particle_simulation/src/Particle.cpp b/projects/particle_simulation/src/Particle.cpp index 3a051c5b..387728eb 100644 --- a/projects/particle_simulation/src/Particle.cpp +++ b/projects/particle_simulation/src/Particle.cpp @@ -4,7 +4,8 @@ Particle::Particle(glm::vec3 position, glm::vec3 velocity, float lifeTime) : m_position(position), m_velocity(velocity), -m_lifeTime(lifeTime) +m_lifeTime(lifeTime), +m_reset_velocity(velocity) {} const glm::vec3& Particle::getPosition()const{ diff --git a/projects/particle_simulation/src/Particle.hpp b/projects/particle_simulation/src/Particle.hpp index 721d9bf8..268e4bcf 100644 --- a/projects/particle_simulation/src/Particle.hpp +++ b/projects/particle_simulation/src/Particle.hpp @@ -29,4 +29,6 @@ private: float m_lifeTime; glm::vec3 m_velocity; float padding_2 = 0.f; + glm::vec3 m_reset_velocity; + float padding_3 = 0.f; }; diff --git a/projects/particle_simulation/src/main.cpp b/projects/particle_simulation/src/main.cpp index a0dc4012..7e4a6f22 100644 --- a/projects/particle_simulation/src/main.cpp +++ b/projects/particle_simulation/src/main.cpp @@ -6,6 +6,7 @@ #include "ParticleSystem.hpp" #include <random> #include <glm/gtc/matrix_access.hpp> +#include <time.h> int main(int argc, const char **argv) { const char *applicationName = "Particlesystem"; @@ -120,10 +121,10 @@ int main(int argc, const char **argv) { 1 ); - glm::vec3 minVelocity = glm::vec3(-0.1f,-0.1f,0.f); - glm::vec3 maxVelocity = glm::vec3(0.1f,0.1f,0.f); + glm::vec3 minVelocity = glm::vec3(-0.1f,-0.1f,-0.1f); + glm::vec3 maxVelocity = glm::vec3(0.1f,0.1f,0.1f); glm::vec2 lifeTime = glm::vec2(-1.f,8.f); - ParticleSystem particleSystem = ParticleSystem( 10000 , minVelocity, maxVelocity, lifeTime); + ParticleSystem particleSystem = ParticleSystem( 100000 , minVelocity, maxVelocity, lifeTime); vkcv::Buffer<Particle> particleBuffer = core.createBuffer<Particle>( vkcv::BufferType::STORAGE, @@ -181,7 +182,7 @@ int main(int argc, const char **argv) { //std::cout << "Front: " << cameraManager.getCamera().getFront().x << ", " << cameraManager.getCamera().getFront().z << ", " << cameraManager.getCamera().getFront().z << std::endl; glm::mat4 viewmat = cameraManager.getCamera(0).getView(); spawnPosition = glm::vec3(pos.x, pos.y, 0.f); - tempPosition = viewmat * glm::vec4(spawnPosition, 1.0f); + tempPosition = glm::vec4(spawnPosition, 1.0f); spawnPosition = glm::vec3(tempPosition.x, tempPosition.y, tempPosition.z); particleSystem.setRespawnPos(glm::vec3(-spawnPosition.x, spawnPosition.y, spawnPosition.z)); // std::cout << "respawn pos: " << spawnPosition.x << ", " << spawnPosition.y << ", " << spawnPosition.z << std::endl; @@ -201,6 +202,7 @@ int main(int argc, const char **argv) { cameraManager.getCamera(camIndex1).setPosition(glm::vec3(0.0f, 0.0f, -2.0f)); cameraManager.getCamera(camIndex1).setCenter(glm::vec3(0.0f, 0.0f, 0.0f)); + srand((unsigned)time(NULL)); while (window.isWindowOpen()) { window.pollEvents(); @@ -223,10 +225,11 @@ int main(int argc, const char **argv) { mvp.push_back( cameraManager.getCamera(1).getMVP()); auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics); + float random = static_cast<float> (rand()) / (static_cast<float> (RAND_MAX/2.5f)); + std::cout << random << std::endl; + glm::vec2 pushData = glm::vec2(deltatime, random); - glm::vec4 pushData = glm::vec4(particleSystem.getRespawnPos(),deltatime); - - vkcv::PushConstantData pushConstantDataCompute( &pushData, sizeof(glm::vec4)); + vkcv::PushConstantData pushConstantDataCompute( &pushData, sizeof(glm::vec2)); uint32_t computeDispatchCount[3] = {static_cast<uint32_t> (std::ceil(particleSystem.getParticles().size()/256.f)),1,1}; core.recordComputeDispatchToCmdStream(cmdStream, computePipeline, -- GitLab