Core GLSL code for vertex_shader_source

Refine this function to easily tweak the position, size and color of particles.

Reminder: Each execution of the vertex shader applies to a single particle.

Input variables:

  • center: reference coordinates of the particle effect. This if often the center of the particle itself, but it can also be reference coordinates for a moving particle.

  • mvp: model-view-projection matrix.

  • color: color tint of the particle.

  • t: global seconds counter since the creation of this particle emitter.

  • ot: creation time of the particle, in seconds, in reference to t.

  • dt: seconds since creation of the particle.

  • ttl: time-to-live of the particle, in seconds.

  • pt: advancement of this particle in its lifetime, in [0.0 .. 1.0].

Output variables:

  • gl_Position: position of the particle in camera coordinates.
  • gl_PointSize: size of the particle in camera coordinates. Set to 0.0 to discard the particle.
  • v_color: tint applied to the particle. Assigned by default to the value of color.

Reference implementation

The default implementation apply the model-view-projection matrix on the position and scales according to the distance from the camera. Most particle effects should apply the same base logic as the default implementation. Here it is for reference:

gl_Position = center * mvp;
gl_PointSize = scale / gl_Position.z;

Property definitions

gamnit $ ParticleProgram :: vertex_shader_core
	# Core GLSL code for `vertex_shader_source`
	#
	# Refine this function to easily tweak the position, size and color of particles.
	#
	# Reminder: Each execution of the vertex shader applies to a single particle.
	#
	# ## Input variables:
	# * `center`: reference coordinates of the particle effect.
	#   This if often the center of the particle itself,
	#   but it can also be reference coordinates for a moving particle.
	# * `mvp`: model-view-projection matrix.
	# * `color`: color tint of the particle.
	#
	# * `t`: global seconds counter since the creation of this particle emitter.
	# * `ot`: creation time of the particle, in seconds, in reference to `t`.
	# * `dt`: seconds since creation of the particle.
	# * `ttl`: time-to-live of the particle, in seconds.
	# * `pt`: advancement of this particle in its lifetime, in `[0.0 .. 1.0]`.
	#
	# ## Output variables:
	# * `gl_Position`: position of the particle in camera coordinates.
	# * `gl_PointSize`: size of the particle in camera coordinates.
	#   Set to `0.0` to discard the particle.
	# * `v_color`: tint applied to the particle.
	#   Assigned by default to the value of `color`.
	#
	# ## Reference implementation
	#
	# The default implementation apply the model-view-projection matrix on the position
	# and scales according to the distance from the camera.
	# Most particle effects should apply the same base logic as the default implementation.
	# Here it is for reference:
	#
	# ~~~glsl
	# gl_Position = center * mvp;
	# gl_PointSize = scale / gl_Position.z;
	# ~~~
	fun vertex_shader_core: String do return """
			gl_Position = center * mvp;
			gl_PointSize = scale / gl_Position.z;
	"""
lib/gamnit/depth/particles.nit:213,2--253,4