SourceForge.net Logo
Home
Documentation
Tutorials
    Beginning
    Gears
    Noise
    Bumpmapping
    Point sprites
    Hello World
    Armature
    Geometryshader
    Toolscripting
    Keyframe animation
    Instancing
    Bezier Surface
    Deferred shading
    Depth peeling
    Particle System
Links
Support This Project
OpenGL
Point Sprites

This tutorial demonstrates rendering pointsprites.

Pointsprites are simple are simple billboards with only one vertex at the center. Let's
start with the script code:

shader = gl.Shader(Vertexshader,Fragmentshader);

shader.Uniformi("Colormap",0);
shader.Uniform("Pointsize",World.getCamHeight());

gl.Enable(gl.VERTEX_PROGRAM_POINT_SIZE);

function render(){
Colormap.Bind(0);

gl.Rotate(60 * World.getTime(), 0,1,0);
gl.Rotate(60 * World.getTime(), 1,0,0);

shader.Bind();

Sphere.Vertex.Bind();

gl.Disable(gl.DEPTH_TEST);
gl.Enable(gl.BLEND);
gl.BlendFunc(gl.SRC_ALPHA,gl.ONE);
gl.Enable(gl.POINT_SPRITE);

Sphere.Draw(gl.POINTS);

gl.Disable(gl.POINT_SPRITE);
gl.Disable(gl.BLEND);
gl.Enable(gl.DEPTH_TEST);
}

function resizeEvent(w,h){
shader.Uniform("Pointsize",h);
}

This code use some new functions and enums. First we have to enable the
gl.VERTEX_PROGRAM_POINT_SIZE (may be removed in future lumina version). The output value
in the vertex shader use "pixels" for calculating the size. To get always the same
picture with different resolutions, we need to pass the viewportheight to the shader.
The resizeEvent() handler correct thatr value if the Cam would be resized.

The render() function contains some new Enable disable functions. They enable blending
without depth test. gl.Enable(gl.POINT_SPRITE); enables rendering point sprites instead
Points.
(should I add Sphere.Draw(gl.POINTS_SPRITE); for cleaning the API?)

Sphere is an simple stream of vertexpositions that can be created with the new "Test
Particles" script located in the nodes contextmenus.
A texture with a pointsprite texture is also needed, create one ....

This Vertexshader calculates the depth corrected point size:
uniform float Pointsize;


void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 mod = gl_ModelViewMatrix * gl_Vertex;

gl_PointSize = 2 *Pointsize/ -mod.z ;
}


An this simple Fragmentshader map the texture on the point sprite:

uniform sampler2D Colormap;

void main(void){
gl_FragColor = texture2D(Colormap,gl_PointCoord);
}



EDIT