Game Development Reference
In-Depth Information
in vec3 voxel_position , voxel_tex_coord;
uniform float voxel_r; // voxel radius
uniform sampler3D vol_shR, vol_shG, vol_shB, vol_normals;
void main ( void )
{
vec4 voxel_pos_wcs = vec4 (voxel_position , 1.0);
vec3 voxel_pos_css = PointWCS2CSS (voxel_pos_wcs.xyz);
vec3 voxel_pos_ecs = PointWCS2ECS (voxel_pos_wcs.xyz);
vec3 zbuffer_ss = MAP_-1To1_0To1 (voxel_pos_css);
float depth = SampleBuf (zbuffer, zbuffer_ss.xy).x;
vec3 zbuffer_css = vec3 (voxel_pos_css.xy, 2.0*depth -1.0);
vec3 zbuffer_ecs = PointCSS2ECS (zbuffer_css);
vec3 voxel_mf_wcs = voxel_pos_wcs.xyz + voxel_r * vec3(1.0);
voxel_mf_wcs = max (voxel_mf_wcs ,
voxel_pos_wcs.xyz + voxel_half_size);
vec3 voxel_mb_wcs = voxel_pos_wcs.xyz + voxel_r * vec3(-1.0);
voxel_mb_wcs = min (voxel_mb_wcs ,
voxel_pos_wcs.xyz - voxel_half_size);
vec3 voxel_mf_ecs = PointWCS2ECS (voxel_mf_wcs);
vec3 voxel_mb_ecs = PointWCS2ECS (voxel_mb_wcs);
float bias = distance (voxel_mf_ecs , voxel_mb_ecs);
vec4 shR_value = SampleBuf (vol_shR, voxel_tex_coord);
vec4 shG_value = SampleBuf (vol_shG, voxel_tex_coord);
vec4 shB_value = SampleBuf (vol_shB, voxel_tex_coord);
vec4 normal_value = SampleBuf (vol_normals , voxel_tex_coord);
if (voxel_pos_ecs.z > zbuffer_ecs.z + bias) { // discard
normal_value = vec4 (0,0,0,0);
shR_value = shG_value = shB_value = vec4 (0,0,0,0);
}
// keep
gl_FragData[0] = normal_value;
gl_FragData[1] = shR_value;
gl_FragData[2] = shG_value;
gl_FragData[3] = shB_value;
}
Listing 6.1. Cleanup phase fragment shader.
6.2.1
Cleanup Phase
Throughout the entire voxelization process, each voxel goes through three state
transitions: “turn-on,” “turn-off,” and “keep” (see Listing 6.1). The “turn-on”
state change is determined during the injection phase. During the cleanup stage
we need to be able to determine if the state of the voxel will be retained or turned
off (cleared). For each one of the available depth buffers, each voxel center
p v
p v ; accordingly the corresponding image
is transformed to eye-space coordinates
p ) is transformed to eye-space coordinates z e .
Expressing the coordinates in the eye reference frame ( Figure 6.2 ) , if
buffer depth Z (
p v,z >z e
the voxel must be cleared, as it lies in front of the recorded depth boundary in the
 
Search Nedrilad ::




Custom Search