Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuation of work on visual particles system #42248

Merged
merged 1 commit into from
Jun 9, 2021

Conversation

Chaosus
Copy link
Member

@Chaosus Chaosus commented Sep 22, 2020

This is a continuation of my work to the particle system in visual shaders.

Added new shader modes:

  • Emit(Custom)
  • Process(Custom)

Added nodes:

New Emit nodes:

image


class VisualShaderNodeParticleOutput : VisualShaderNodeOutput

Description: Created automatically in all modes of particle shader.
Have different input ports (depending on the shader mode).

Availability: Everywhere

Common Input ports (on all shader modes):

vec3 velocity - an initial velocity vector, translates to VELOCITY
vec3 color - translates to COLOR.rgb
float alpha - translates to COLOR.a
Transform position - translates to TRANSFORM
float scale
bool active

Emit:

  • (Common Input ports)
  • float lifetime_scale
  • float initial_angle
  • float anim_offset

Emit (Custom):

  • (Common Input ports)
  • vec3 custom
  • float custom_alpha

Process:

  • (Common Input ports)

Process (Custom):

  • (Common Input ports)

End:

  • (Common Input ports)

class VisualShaderNodeParticleEmitter : VisualShaderNode

Description: Abstract base class for all emitters.

Availability: Emit

Output ports:

  • Transform position - position of the particle, need to be connected to the position input port inside VisualShaderNodeParticleOutput.

class VisualShaderNodeParticleBoxEmitter : VisualShaderNodeParticleEmitter

Description: Generates a position inside a box.

Availability: Emit

image

Input ports:

  • vec3 extents (default: vec3(1, 1, 1)) - Defines a volume of the box.

Output ports:

  • Derived from VisualShaderNodeParticleEmitter

class VisualShaderNodeParticleRingEmitter : VisualShaderNodeParticleEmitter

Description: Generates a position inside a ring.

Availability: Emit

image

Input ports:

  • float radius (default:10) - A radius of the ring.
  • float inner (default:0) - An inner volume size of the ring.
  • float outer (default:0) - An outer volume size of the ring.

Output ports:

  • Derived from VisualShaderNodeParticleEmitter

class VisualShaderNodeParticleSphereEmitter : VisualShaderNodeParticleEmitter

Description: Generates a position inside a sphere.

Availability: Emit

image

Input ports:

  • float radius (default:10) - A radius of the sphere
  • bool use_inner_space (default:true) - if false the particles will generates on a sphere but not inside it.

Output ports:

  • Derived from VisualShaderNodeParticleEmitter

class VisualShaderNodeParticleTextureEmitter : VisualShaderNodeParticleEmitter

Description: (I think @reduz should implement it himself since I'm not sure how to make it properly).

Availability: Emit

Input ports:

  • sampler2D position
  • sampler2D normal

Output ports:

  • Derived from VisualShaderNodeParticleEmitter

class VisualShaderNodeParticleRandomness : VisualShaderNodeParticleEmitter

Description: Generates a random scalar or a vector.

Availability: Everywhere

Properties: Op
Type - OP_TYPE_SCALAR / OP_TYPE_VECTOR which affect a type of result

vsp_randomness

Input ports:

  • float/vec3 min (default: 0.0/vec3(-1, -1, -1)) - a minimum value to generate
  • float/vec3 max (default: 1.0/vec3(1, 1, 1)) - a maximum value to generate

Output ports:

  • float/vec3 random - a generated value

class VisualShaderNodeParticleConeVelocity

Description: Generates a velocity normalized vector inside a cone.

Availability: Emit

vsp_cone

Input ports:

  • vec3 direction (default: vec3(1, 0, 0)) - a direction vector
  • float spread(degrees) (default: 45.0) - spread amount

Output ports:

  • vec3 velocity - a velocity normalized vector inside a cone.

class VisualShaderNodeParticleAccelerator : VisualShaderNode

Description: Intended to modify particle velocity via time.

Availability: Process

Properties: Mode: MODE_LINEAR/MODE_RADIAL/MODE_TANGENTIAL

vsp_accel

Input ports:

  • vec3 velocity
  • vec3 amount
  • float randomness

Notes:

  • The internal code is mainly copy/pasted from ParticlesMaterial and their outputs is almost identical

  • All these new types have a "Particle" suffix to make sorting/seeing of them easy.

@Chaosus Chaosus added this to the 4.0 milestone Sep 22, 2020
@Chaosus Chaosus requested a review from reduz September 22, 2020 14:38
@Chaosus Chaosus changed the title Continuation of work on visual particles system [WIP] Continuation of work on visual particles system Sep 22, 2020
@Chaosus Chaosus force-pushed the vs_particles_shader branch 6 times, most recently from d9b48d1 to 5d7c715 Compare September 24, 2020 06:57
@Chaosus Chaosus force-pushed the vs_particles_shader branch 2 times, most recently from 8b3667e to 78eae55 Compare October 4, 2020 08:14
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 78eae55 to 7e325d4 Compare October 12, 2020 18:50
@Chaosus Chaosus requested a review from a team as a code owner October 12, 2020 18:50
@Chaosus
Copy link
Member Author

Chaosus commented Oct 12, 2020

UPDATE (12/10/2020):

  • Added Emit(Custom) and Process(Custom) basic implementation - @reduz is still working on it and there will be separate functions for them in the near future.

  • Added Collide mode (and remove End mode for now) - to provide a way to handle colliders
    image

  • Removed TextureEmitter since I still don't understand how it should work

  • Added Emit node to provide a way to emitting - this node does not have outputs instead every instance of it proceeded independently (after Output processing)

image

- Changed position type of EmitOutput to vector, I think it's better to handle and modify rather than matrix, and logically position associated with vectors. - decided to leave it as it is since the user may want to use whole transform instead (UPDATE 13.10.2020)

  • Added rotation_axis port to EmitOutput - now it will work with initial_angle to rotate a mesh transformation
  • Removed RotateVector since I think it bloats the engine and perfectly fits to the user extension. (UPDATE 13.10.2020)
  • Added PointEmitter (UPDATE 13.10.2020)

@Chaosus Chaosus force-pushed the vs_particles_shader branch 7 times, most recently from c08cdbc to 8857063 Compare October 16, 2020 05:09
@Chaosus Chaosus force-pushed the vs_particles_shader branch 2 times, most recently from 4c624d9 to 7b528a9 Compare October 21, 2020 14:00
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 7b528a9 to b94a059 Compare November 4, 2020 06:33
@Chaosus Chaosus force-pushed the vs_particles_shader branch from b94a059 to 3c78ce1 Compare November 13, 2020 07:46
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 3c78ce1 to 8f6aca0 Compare November 25, 2020 16:22
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 8f6aca0 to 164a4a9 Compare December 7, 2020 13:04
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 164a4a9 to a8c5fb2 Compare December 17, 2020 09:03
@Chaosus Chaosus force-pushed the vs_particles_shader branch 2 times, most recently from a0aa685 to ae6b863 Compare June 6, 2021 17:26
@QbieShay QbieShay self-requested a review June 6, 2021 17:31
Copy link
Contributor

@QbieShay QbieShay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment from a code perspective, but I did try out the PR and it already adds pretty good functionalities. It's solid work that will already bring Godot's particle shaders miles ahead in terms of accessibility! 👍

@clayjohn
Copy link
Member

clayjohn commented Jun 7, 2021

I tested this out locally and played around with it for a bit. The only odd thing I noticed was that Velocity was added to VELOCITY in the normal process shader, but overwrote VELOCITY in custom mode. In my opinion, it makes more sense to overwrite velocity every frame in the process shader. That way users can actually control velocity/acceleration. When you specify a value to increase velocity, you are actually specifying acceleration.

@Chaosus Chaosus force-pushed the vs_particles_shader branch 3 times, most recently from d8de7f5 to e16012d Compare June 7, 2021 07:07
@Chaosus
Copy link
Member Author

Chaosus commented Jun 7, 2021

@clayjohn I removed VELOCITY from custom mode - does it looks ok now?

@Chaosus
Copy link
Member Author

Chaosus commented Jun 7, 2021

I managed to make scaling and rotation properly work with CurveTexture in Process, but this required an additional matrix to be attached to each particle to keep started transformation: START_TRANSFORM.

particles

The position is being redundant here - since it is inherited from the start function, and being modified by velocity.

@Chaosus Chaosus force-pushed the vs_particles_shader branch from e16012d to d17f0dc Compare June 7, 2021 08:29
@Chaosus Chaosus requested a review from a team as a code owner June 7, 2021 08:29
@Chaosus Chaosus force-pushed the vs_particles_shader branch 3 times, most recently from a0fbb7a to d49be6c Compare June 7, 2021 09:52
@Chaosus Chaosus requested a review from clayjohn June 7, 2021 10:42
@Chaosus Chaosus force-pushed the vs_particles_shader branch from d49be6c to b4ab3e5 Compare June 7, 2021 13:44
@Chaosus
Copy link
Member Author

Chaosus commented Jun 7, 2021

@reduz said that he would add new built-ins for user data to better performance so I've reverted the changes I made about introducing START_TRANSFORM to the particles renderer. This PR can be merged as it is as it mostly worked properly.

@clayjohn
Copy link
Member

clayjohn commented Jun 7, 2021

I removed VELOCITY from custom mode - does it looks ok now?

I was not suggesting that you remove VELOCITY. I was suggesting that, when you use the Velocity port, you write directly to VELOCITY instead of adding to VELOCITY

@Chaosus Chaosus force-pushed the vs_particles_shader branch from b4ab3e5 to c85e1e4 Compare June 7, 2021 17:16
@Chaosus
Copy link
Member Author

Chaosus commented Jun 7, 2021

Sorry, then I wrongly understood you (probably tired). Bring it back and fixed.

@Chaosus Chaosus force-pushed the vs_particles_shader branch from c85e1e4 to 814b328 Compare June 7, 2021 17:20
@Chaosus Chaosus force-pushed the vs_particles_shader branch from 814b328 to f632e36 Compare June 7, 2021 17:33
@akien-mga akien-mga merged commit 27cf525 into godotengine:master Jun 9, 2021
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants