Rendering Particles Instead of Polygons

I've spent quite a lot of time perfecting how to draw particles in OpenGL. This is pretty easy, but if you want particles to correspond to world space then things get more difficult. I have found on GitHub other students doing a project with very similar goals to my own project, altough they have executed their project using mainly GPU and Cuda technology. I am doing my code so far a lot on the CPU side so our code will be very different. I did check their shader code for particles, and copied their way of diffusing a particle to get a 3D effect. The clipping needed to make particles appear round did I already discover on other parts of the internet. If interested, this project can be found here.

The main issue is that you have to use the shader code "gl_PointSize". This parameter only specifies how many pixels to draw, and don't care about where the pixel is in world space. Luckily someone already asked a question on how to solve this on StackOverflow here. If I had understood the accepted answer on StackOverflow, I would have saved myself a lot of time. What happened was that I naively tried to implement the solution without knowing what the parameters represented and thus got some of them wrong. This made me think for a short while that I had done something wrong or that the answer was bad. Later on I started to read about field of view and other things which turned out to be "wasted time", since I later got the code to work. Something VERY IMPORTANT that I also discovered is that the OpenGL program received the correct results after I resized the screen, but never before I resized it. The resize-callback code function called glViewport. Apparently you have to call glViewport with the correct values since this somehow affects the project-matrix or screen window that is used to calculate the correct amount of pixels gl_PointSize should have. This is really a long shot bug that is hard to find when you don't know what you are doing, like me.

It just so happens that I asked a question on StackOverflow about how to do this. I also answered this question myself on StackOverflow, I recommend for people who are doing the same thing as me to read it: https://computergraphics.stackexchange.com/questions/9055/represent-shape-as-particles


Here is a video when I test collision between two particles with a diameter of size 1. When they intersect one of the particles turn red:


Kommentarer

Populära inlägg i den här bloggen

Collisions

Optimizing Particles With VBO

Particle Generation