Feb 18, 2013 18:12
I put together two simple OpenGL effect rendering prototypes over the weekend, starting out with a basic GLFW application I had made earlier.
The first effect prototype was a retro-styled "laser beam" effect made from random 1-bit noise, and pulled double-duty as a testbed for using OpenGL 3.x core profile. It sets up the vertex array object required by core profile, uses a vertex and index buffer for the beam geometry, a 4096×8 1-bit noise texture, and a slightly complicated vertex and fragment shader.
After a lot of experimentation and failure, I finally hit on an effect that I sorta-kinda like. It consists of three layers: a narrow solid beam core, a less-narrow rapidly-scrolling 75%-density 1-bit noise beam sheath, and a wider less-rapidly-scrolling 25%-density 1-bit noise beam fringe. Each layer has a gradient effect towards the edges. The entire effect is done in the fragment shader; the beam geometry itself is a single quad.
The second effect prototype was a point sprite starfield using shaders. VideoVenture constructs a quad list using scripting and wanted to see if I could achieve a similar effect with a simple point list. After doing some research, I found a way to enable shader-controlled point size and apply a perspective transform. The resulting vertex shader is fairly simple and the fragment shader is trivial. It definitely seems to be the right way to go in the future. The only complication is that the size is in pixel units so the shader needs the viewport width to generate proper results. (It's easy to pass it in as a uniform value.)
As a side experiment, I tried a few effects I found online that use point sprite coordinates for more interesting things that computing texture coordinates. I made soft-edged and crisp-edged flat circles, various star shapes, and even lit spheres. The trick is to compute values from point sprite coordinates. For example, the sphere example computes the surface normal from the coordinates and then applies per-pixel diffuse and specular lighting. I could see that being useful for a modern version of the Amiga-style blitter-object demo.
Both prototypes use functionality from VideoVenture. Both use the XOR-shift random number generator and OpenGL function binding. The starfield prototype also uses Perlin noise and the matrix stack.
opengl,
programming