1- // ---------------------------------------------------------------------------------------------//
1+ // - ---------------------------------------------------------------------------------------------//
22// A voxel cone tracing implementation for real-time global illumination, //
33// refraction, specular, glossy and diffuse reflections, and soft shadows. //
44// The implementation traces cones through a 3D texture which contains a //
@@ -80,8 +80,8 @@ in vec3 normalFrag;
8080
8181out vec4 color;
8282
83- const vec3 normal = normalize (normalFrag);
84- const float MAX_DISTANCE = distance (vec3 (abs (worldPositionFrag)), vec3 (- 1 ));
83+ vec3 normal = normalize (normalFrag);
84+ float MAX_DISTANCE = distance (vec3 (abs (worldPositionFrag)), vec3 (- 1 ));
8585
8686// Returns an attenuation factor given a distance.
8787float attenuate(float dist){ dist *= DIST_FACTOR; return 1 .0f / (CONSTANT + LINEAR * dist + QUADRATIC * dist * dist); }
@@ -97,7 +97,7 @@ vec3 orthogonal(vec3 u){
9797vec3 scaleAndBias(const vec3 p) { return 0 .5f * p + vec3 (0 .5f); }
9898
9999// Returns true if the point p is inside the unity cube.
100- bool isInsideCube(const vec3 p, float e = 0 ) { return abs (p.x) < 1 + e && abs (p.y) < 1 + e && abs (p.z) < 1 + e; }
100+ bool isInsideCube(const vec3 p, float e) { return abs (p.x) < 1 + e && abs (p.y) < 1 + e && abs (p.z) < 1 + e; }
101101
102102// Returns a soft shadow blend by using shadow cone tracing.
103103// Uses 2 samples per step, so it's pretty expensive.
@@ -112,7 +112,7 @@ float traceShadowCone(vec3 from, vec3 direction, float targetDistance){
112112
113113while (dist < STOP && acc < 1 ){
114114vec3 c = from + dist * direction;
115- if (! isInsideCube(c)) break ;
115+ if (! isInsideCube(c, 0 )) break ;
116116c = scaleAndBias(c);
117117float l = pow (dist, 2 ); // Experimenting with inverse square falloff for shadows.
118118float s1 = 0.062 * textureLod(texture3D , c, 1 + 0.75 * l).a;
@@ -166,7 +166,7 @@ vec3 traceSpecularVoxelCone(vec3 from, vec3 direction){
166166// Trace.
167167while (dist < MAX_DISTANCE && acc.a < 1 ){
168168vec3 c = from + dist * direction;
169- if (! isInsideCube(c)) break ;
169+ if (! isInsideCube(c, 0 )) break ;
170170c = scaleAndBias(c);
171171
172172float level = 0.1 * material.specularDiffusion * log2 (1 + dist / VOXEL_SIZE);
0 commit comments