Monday, February 11, 2008

Marching Through a Volume

I'm trying to decide between implementing marching cubes and marching tetrahedra. I'm aware of (some of the) limitations of each, and I'm trying to figure out which best serves my purposes.

I'm starting with an easy to follow instructional document written by Paul Bourke, and I hope to manage an original implementation in the next week or two.

Thursday, February 7, 2008

shadow2DProj Resolved

I'd like to offer a quick thanks to oc2k1 from the OpenGL message boards. He realized immediately that I was missing the following:


glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);


Alternatively, I could compare the value in the depth texture to the texCoord's z value myself, but I expect that this comparison is hardware accelerated.

If you're doing GLSL development, you might want to have a peek at Lumina. I'm going to be playing with it in the near future.

Thanks again to oc2k1, and the rest of the incredibly helpful people on the OpenGL message boards.

Andrew.

shadow2DProj

I'm having some difficulty implementing shadow maps in OpenGL. The Orange Book (section 13.2.3) says that shadow2DProj should return a value that is either 0 or 1. Below is an image of the diffuse term multiplied by the result of the lookup, which clearly is not giving values between 0 and 1. Beyond that, the shadows are much sharper than I had expected. I can imagine some sort of PCF going on, but that still doesn't account for the pale shadows.

I can simply force 0,1 values via the shader, but I'd like to understand what's going on rather than force my expectations onto things.





For completeness, the fragment shader follows.

#version 110

varying vec3 frag_Position;
varying vec3 frag_Normal;
varying vec3 frag_LightDirection;
varying vec4 frag_ShadowCoordinate;

uniform sampler2DShadow frag_ShadowMap;

void main()
{
vec3 E =-normalize(frag_Position);
vec3 L = normalize(frag_LightDirection);
vec3 H = normalize(E + L);

// Get shadow value
float shadow = shadow2DProj( frag_ShadowMap, frag_ShadowCoordinate ).x;
//if (shadow < 1.0) shadow = 0.0;

// Light properties
const vec3 light_ads = vec3( 0.0, 1.0, 0.0 );

// Material properties
const vec4 material_adss = vec4( 0.0, 0.5, 0.0, 0.0 );

// Light/Material interaction
const vec3 lightCoefficient = light_ads * material_adss.rgb;

vec3 ambientDiffuseSpecular = vec3( 0.0,
shadow * max(0.0, dot(frag_Normal, L)),
shadow == 0.0 ? 0.0 : pow( max(0.0, dot(frag_Normal, H)), material_adss.a ));

// Ambient, Diffuse, Specular contributions
float shade = dot(lightCoefficient, ambientDiffuseSpecular);

gl_FragColor = vec4( shade * gl_Color.rgb, 1.0 );
}