gamnit: make `SpriteSet` public so clients can use its services
[nit.git] / lib / gamnit / depth / particles.nit
index e3be795..bfe3392 100644 (file)
@@ -39,6 +39,9 @@ import depth_core
 
 redef class App
 
+       # Graphics program to display static non-moving particles
+       var static_program = new ParticleProgram
+
        # Graphics program to display blowing up particles
        var explosion_program = new ExplosionProgram
 
@@ -153,7 +156,7 @@ end
 #
 # This program should be subclassed to create custom particle effects.
 # Either `vertex_shader_source` and `vertex_shader_core` can be refined.
-abstract class ParticleProgram
+class ParticleProgram
        super GamnitProgramFromSource
 
        redef var vertex_shader_source = """
@@ -249,13 +252,12 @@ abstract class ParticleProgram
                uniform bool use_texture;
 
                // Texture to apply on this particle
-               uniform sampler2D texture;
+               uniform sampler2D texture0;
 
                void main()
                {
                        if (use_texture) {
-                               gl_FragColor = texture2D(texture, gl_PointCoord) * v_color;
-                               if (gl_FragColor.a <= 0.01) discard;
+                               gl_FragColor = texture2D(texture0, gl_PointCoord) * v_color;
                        } else {
                                gl_FragColor = v_color;
                        }
@@ -269,7 +271,7 @@ abstract class ParticleProgram
        var use_texture = uniforms["use_texture"].as(UniformBool) is lazy
 
        # Visible texture unit
-       var texture = uniforms["texture"].as(UniformSampler2D) is lazy
+       var texture = uniforms["texture0"].as(UniformSampler2D) is lazy
 
        # Color tint per vertex
        var color = attributes["color"].as(AttributeVec4) is lazy
@@ -298,7 +300,7 @@ class ExplosionProgram
                gl_Position = center * mvp;
                gl_PointSize = scale / gl_Position.z * pt;
 
-               if (pt > 0.8) v_color.a = (1.0-pt)/0.2;
+               if (pt > 0.8) v_color *= (1.0-pt)/0.2;
        """
 end
 
@@ -315,8 +317,8 @@ class SmokeProgram
                gl_PointSize = scale / gl_Position.z * (pt+0.1);
 
                if (pt < 0.1)
-                       v_color.a = pt / 0.1;
+                       v_color *= pt / 0.1;
                else
-                       v_color.a = 1.0 - pt*0.9;
+                       v_color *= 1.0 - pt*0.9;
        """
 end