Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
particles [2019/03/22 08:22] – [Shader / Material] admin | particles [2020/11/06 14:04] – admin | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Using the ParticleSystem ====== | ====== Using the ParticleSystem ====== | ||
+ | |||
+ | {{:: | ||
Gorilla3D provides an integrated particle system for rendering complex and individual particle effects. | Gorilla3D provides an integrated particle system for rendering complex and individual particle effects. | ||
Line 7: | Line 9: | ||
Gorilla3D already supplies some of the most popular effects, like: fire, smoke, rain, snow, waterfall, eruption, explosion. | Gorilla3D already supplies some of the most popular effects, like: fire, smoke, rain, snow, waterfall, eruption, explosion. | ||
+ | {{:: | ||
It is possible to manipulate each particle by the so-called influencers. | It is possible to manipulate each particle by the so-called influencers. | ||
Line 20: | Line 23: | ||
* Endless or limited emmittance | * Endless or limited emmittance | ||
* Physically based particle collision detection with other scene objects (not with particles!) | * Physically based particle collision detection with other scene objects (not with particles!) | ||
+ | * Autosorting of particles depending on assigned camera | ||
===== Shader / Material ===== | ===== Shader / Material ===== | ||
Line 34: | Line 38: | ||
To allow extended particle functionality Gorilla3D changes the default values of some vertex attributes, because at the moment it is not possible to declare our own vertex attributes. | To allow extended particle functionality Gorilla3D changes the default values of some vertex attributes, because at the moment it is not possible to declare our own vertex attributes. | ||
+ | |||
+ | In the following table we show the attribute settings for each particle, when using a TGorillaParticleEmitter: | ||
^ Vertex-Attribute ^ Value ^ | ^ Vertex-Attribute ^ Value ^ | ||
- | | a_Position | particle | + | | a_Position | position | |
- | | a_Normal | particle | + | | a_Normal | velocity | |
- | | a_Color0 | current color of particle | + | | a_Color0 | current color| |
| a_TexCoord0 | current texture or texture atlas offset | | | a_TexCoord0 | current texture or texture atlas offset | | ||
| a_Binormal | X = size, Y = angle, Z = weight | | | a_Binormal | X = size, Y = angle, Z = weight | | ||
| a_Tangent | X = age, Y = life time, Z = delta time | | | a_Tangent | X = age, Y = life time, Z = delta time | | ||
+ | ===== Influencers ===== | ||
+ | |||
+ | Influencers are helper classes to manipulate particles at runtime. | ||
+ | |||
+ | ===== Physics Particle Support ===== | ||
+ | |||
+ | {{:: | ||
+ | |||
+ | Our particles system can be linked to the physics system for particle collision detection. | ||
+ | In the following example we use the rain particle emitter as basis. | ||
+ | |||
+ | <file pascal> | ||
+ | uses | ||
+ | [...] | ||
+ | Gorilla.Material.Particle, | ||
+ | Gorilla.Particle.Emitter, | ||
+ | Gorilla.Particle.Influencer, | ||
+ | Gorilla.Particle.Rain, | ||
+ | Gorilla.Particle.Spot, | ||
+ | Gorilla.Physics, | ||
+ | Gorilla.Physics.Q3.Body; | ||
+ | | ||
+ | TForm1 = class(TForm) | ||
+ | procedure FormCreate(Sender: | ||
+ | protected | ||
+ | FViewport : TGorillaViewport; | ||
+ | FCamera : TGorillaCamera; | ||
+ | FPhysics : TGorillaPhysicsSystem; | ||
+ | FParticles : TGorillaRainParticleEmitter; | ||
+ | FInfluencer : TGorillaPhysicsInfluencer; | ||
+ | FSplashes : TGorillaSpotParticleEmitter; | ||
+ | | ||
+ | procedure DoOnGorillaPhysicsNotifyContact(const ABodyA, ABodyB : TQ3Body); | ||
+ | [...] | ||
+ | end; | ||
+ | |||
+ | [...] | ||
+ | |||
+ | procedure TForm1.DoOnGorillaPhysicsNotifyContact(const ABodyA, ABodyB : TQ3Body); | ||
+ | begin | ||
+ | // collision detected - create splashes on particle-sphere/ | ||
+ | // not on particle-particle collision (too much) | ||
+ | if (PTypeInfo(ABodyA.UserDataType) = TypeInfo(PGorillaParticle)) | ||
+ | and (PTypeInfo(ABodyB.UserDataType) = TypeInfo(PGorillaParticle)) then | ||
+ | Exit; | ||
+ | |||
+ | if (PTypeInfo(ABodyA.UserDataType) = TypeInfo(PGorillaParticle)) then | ||
+ | FSplashes.EmitParticle( | ||
+ | PGorillaParticle(ABodyA.UserData)^.Position | ||
+ | ) | ||
+ | else if (PTypeInfo(ABodyB.UserDataType) = TypeInfo(PGorillaParticle)) then | ||
+ | FSplashes.EmitParticle( | ||
+ | PGorillaParticle(ABodyB.UserData)^.Position | ||
+ | ); | ||
+ | end; | ||
+ | |||
+ | procedure TForm1.FormCreate(Sender: | ||
+ | begin | ||
+ | [...] | ||
+ | | ||
+ | // create physics system with contact callback function to display splashes | ||
+ | FPhysics := TGorillaPhysicsSystem.Create(FViewport); | ||
+ | FPhysics.OnBeginContact := DoOnGorillaPhysicsNotifyContact; | ||
+ | | ||
+ | // create rain particle emitter | ||
+ | FParticles := TGorillaRainParticleEmitter.Create(FViewport); | ||
+ | FParticles.Parent := FViewport; | ||
+ | FParticles.Camera := FCamera; | ||
+ | FParticles.EmitParticles := 25; | ||
+ | |||
+ | // preconfigure particles | ||
+ | FParticles.Colored.StartColor := TAlphaColorF.Create( TAlphaColorRec.Blue ); | ||
+ | FParticles.Colored.EndColor := TAlphaColorF.Create( TAlphaColorRec.Blueviolet ); | ||
+ | FParticles.ParticleSize | ||
+ | FParticles.ParticleGrowth := TParticlePreset.Create(0, | ||
+ | FParticles.Colored.Enabled := false; | ||
+ | FParticles.Wind.Enabled := false; | ||
+ | |||
+ | // create a physics influencer | ||
+ | FInfluencer := TGorillaPhysicsInfluencer.Create(FParticles); | ||
+ | FInfluencer.Emitter := FParticles; | ||
+ | // link to physics system component | ||
+ | FInfluencer.Physics := FPhysics; | ||
+ | FInfluencer.Enabled := true; | ||
+ | |||
+ | // another particle emitter to simulate rain drop splashes when they hit an obstacle | ||
+ | FSplashes := TGorillaSpotParticleEmitter.Create(FViewport); | ||
+ | FSplashes.Parent := FViewport; | ||
+ | FSplashes.Camera := FCamera; | ||
+ | FSplashes.LoadTexture(' | ||
+ | |||
+ | // activate physics | ||
+ | FPhysics.Active := true; | ||
+ | FParticles.Start(); | ||
+ | FSplashes.Start(); | ||
+ | end; | ||
+ | </ | ||
===== Example ===== | ===== Example ===== | ||
Line 52: | Line 155: | ||
begin | begin | ||
LParticles := TGorillaFireParticleEmitter.Create(FGorilla); | LParticles := TGorillaFireParticleEmitter.Create(FGorilla); | ||
- | LParticles .Camera := FCamera; | + | |
+ | | ||
// a fire effect contains multiple parts: a front and back flame and smoke | // a fire effect contains multiple parts: a front and back flame and smoke | ||
Line 79: | Line 183: | ||
begin | begin | ||
LParticles := TGorillaSmokeParticleEmitter.Create(FGorilla); | LParticles := TGorillaSmokeParticleEmitter.Create(FGorilla); | ||
+ | LParticles.Parent := FGorilla; | ||
LParticles.Camera := FCamera; | LParticles.Camera := FCamera; | ||
Line 108: | Line 213: | ||
begin | begin | ||
LParticles := TGorillaEruptionParticleEmitter.Create(FGorilla); | LParticles := TGorillaEruptionParticleEmitter.Create(FGorilla); | ||
+ | LParticles.Parent := FGorilla; | ||
LParticles.Camera := FCamera; | LParticles.Camera := FCamera; | ||
Line 130: | Line 236: | ||
begin | begin | ||
LParticles := TGorillaRainParticleEmitter.Create(FGorilla); | LParticles := TGorillaRainParticleEmitter.Create(FGorilla); | ||
+ | LParticles.Parent := FGorilla; | ||
LParticles.Camera := FCamera; | LParticles.Camera := FCamera; | ||
end; | end; | ||
Line 147: | Line 254: | ||
begin | begin | ||
LParticles := TGorillaSnowParticleEmitter.Create(FGorilla); | LParticles := TGorillaSnowParticleEmitter.Create(FGorilla); | ||
+ | LParticles.Parent := FGorilla; | ||
LParticles.Camera := FCamera; | LParticles.Camera := FCamera; | ||
end; | end; | ||
Line 268: | Line 376: | ||
end; | end; | ||
</ | </ | ||
+ | |||
Next step: [[physics|Physics]] | Next step: [[physics|Physics]] |