Saturday, April 21, 2012

Sphere Test

After much tribulation, I have managed to render a soft sphere! It turns out I had, in my somewhat sleep-deprived state, forgotten to check if I was hitting a zero-density voxel and skipping some computation if I hit a zero-density voxel. Without that check I was rendering very strange looking black cubes with sphere-esque blobs inside them. In any case, I am feeling much better about the state of my project than I was even just a few minutes ago.

Noisy Raymarch

Here is an attempt to render a spherical cloud using raymarching, now that I've resolved my 3D texture issue. I'm yet not sure why that noise is appearing nor am I certain as to why it does not look quite spherical. Still, it's an improvement over the black cube I was seeing before.


Here's another render (this time with what looks like an ellipse but what should be a sphere):




Texture Generation

Well, it turns out that, as I suspected,  the source of my problems was the texture generation after all. I was using the variable GL_R instead of GL_RED when passing float data from my voxel buffer to the shader, which is meant to be used in the context of a texture coordinate rather than color. I'm a bit frustrated that it took me three days to track this bug down... At least I have this knowledge for any future OpenGL projects I might work on.

Wednesday, April 18, 2012

Raymarching Uncertainty

I've implemented raymarching code in the fragment shader. However, at the moment the object that is supposed to be my cloud is appearing as a black cube. I know why this is occurring; the function that samples density data from the 3D texture I output to the shader always returns 0. I can think of two reasons why this is occurring:

1) The texture I'm sending to the shader is being created incorrectly
2) My sampling function is wrong.

I'm inclined to believe that my texture is being made incorrectly, since I'm using a sampling function similar to the one I used when making a volumetric renderer in CIS 560. Now off to figure out why my texture is wrong...

Wednesday, April 11, 2012

Fragment Shader Raycasts

I figured out how to raycast in my fragment shader! I discovered the gl_FragCoord variable, which returns the coordinates of the current fragment in screen space. By passing the shader the screen's dimensions I can convert this number into normalized device coordinates and create a 3D ray based on the fragment and view matrix.

I've tested my raycasts by coloring each fragment with the X, Y, and Z components of the ray it generates. So far everything looks correct. Next step: getting a raymarch to work!

As an added bonus, it's already given that each ray generated will hit the cloud's bounding box since they're only generated from fragments. I can skip that particular test during my raymarch now, since it would actually serve to slow down my renders rather than speed them up as it would in an offline renderer.

Rays as RGB:


Monday, April 9, 2012

GL Bug Fixed

Earlier this week I encountered some trouble getting just a simple cube to render in my GLUT window. I thought I was doing something wrong when initializing my GL viewport, since I was only able to see the background color of my scene. It turns out that my program wasn't properly setting a value for the unsigned int used to represent a varying vec4 in my shader program, and as such none of my vertices were being placed anywhere in the GL scene. To fix this I just defined its location myself using layout(location) in its definition in my vertex shader. Now I can actually see the geometry I generate and know that my camera controls are working properly. Next step: change my fragment shader to use raymarch code to render a cloud.