Reputation: 6221
Question: How do I render points in openGL using GLSL?
Info: a while back I made a gravity simulation in python and used blender to do the rendering. It looked something like this. As an exercise I'm porting it over to openGL and openCL. I actually already have it working in openCL, I think. It wasn't until i spent a fair bit of time working in openCL that I realized that it is hard to know if this is right without being able to see the result. So I started playing around with openGL. I followed the openGL GLSL tutorial on wikibooks, very informative, but it didn't cover points or particles.
I'm at a loss for where to start. most tutorials I find are for the openGL default program. I want to do it using GLSL. I'm still very new to all this so forgive me my potential idiocy if the answer is right beneath my nose. What I'm looking for is how to make halos around the points that blend into each other. I have a rough idea on how to do this in the fragment shader, but so far as I'm aware I can only grab the pixels that are enclosed by polygons created by my points. I'm sure there is a way around this, it would be crazy for there not to be, but me in my newbishness is clueless. Can some one give me some direction here? thanks.
Upvotes: 4
Views: 11093
Reputation: 973
I think what you want is to render the particles as GL_POINTS
with GL_POINT_SPRITE
enabled, then use your fragment shader to either map a texture in the usual way, or generate the halo gradient procedurally.
When you are rendering in GL_POINTS
mode, set gl_PointSize
in your vertex shader to set the size of the particle. The vec2
variable gl_PointCoord
will give you the coordinates of your fragment in the fragment shader.
EDIT: Setting gl_PointSize
will only take effect if GL_PROGRAM_POINT_SIZE
has been enabled. Alternatively, just use glPointSize
to set the same size for all points. Also, as of OpenGL 3.2 (core), the GL_POINT_SPRITE
flag has been removed and is effectively always on.
Upvotes: 7
Reputation: 10105
simply draw a point sprites (using GL_POINT_SPRITE) use blending functions: gl_src_alpha and gl_one and then "halos" should be visible. Blending should be responsible for "halos" so look for some more info about that topic. Also you have to disable depth wrties.
here is some link about that: http://content.gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:Particles
Upvotes: 0