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.
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]
.
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
.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;
# 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
redef fun vertex_shader_core do return """
gl_Position = center * mvp;
gl_PointSize = scale / gl_Position.z * pt;
if (pt > 0.8) v_color *= (1.0-pt)/0.2;
"""
lib/gamnit/depth/particles.nit:309,2--314,4
redef fun vertex_shader_core do return """
vec4 c = center;
c.y += dt * 1.0;
c.x += dt * 0.1;
gl_Position = c * mvp;
gl_PointSize = scale / gl_Position.z * (pt+0.1);
if (pt < 0.1)
v_color *= pt / 0.1;
else
v_color *= 1.0 - pt*0.9;
"""
lib/gamnit/depth/particles.nit:321,2--333,4