Skip to content

Commit

Permalink
More gles fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Nov 14, 2024
1 parent 57b9a94 commit ede19ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 9 additions & 11 deletions base/shaders/std/conetrace.glsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

const int voxelgi_resolution = 256;
const vec3 voxelgi_half_extents = vec3(1, 1, 1);
const float voxelgi_resolution = 256.0;
const vec3 voxelgi_half_extents = vec3(1.0, 1.0, 1.0);
const float voxelgi_occ = 1.0;
const float voxelgi_step = 1.0;
const float voxelgi_range = 2.0;
const float MAX_DISTANCE = 1.73205080757 * voxelgi_range;
const float VOXEL_SIZE = (2.0 / voxelgi_resolution) * voxelgi_step;

vec3 tangent(const vec3 n) {
vec3 t1 = cross(n, vec3(0, 0, 1));
vec3 t2 = cross(n, vec3(0, 1, 0));
vec3 t1 = cross(n, vec3(0.0, 0.0, 1.0));
vec3 t2 = cross(n, vec3(0.0, 1.0, 0.0));
if (length(t1) > length(t2)) return normalize(t1);
else return normalize(t2);
}
Expand All @@ -23,9 +23,9 @@ float trace_cone_ao(sampler3D voxels, const vec3 origin, vec3 dir, const float a
while (sample_col < 1.0 && dist < max_dist) {
sample_pos = dir * dist + origin;
float mip = max(log2(diam * voxelgi_resolution), 0.0);
float mip_sample = textureLod(voxels, sample_pos * 0.5 + vec3(0.5, 0.5, 0.5), mip).r;
float mip_sample = textureLod(voxels, sample_pos * vec3(0.5, 0.5, 0.5) + vec3(0.5, 0.5, 0.5), mip).r;
sample_col += (1 - sample_col) * mip_sample;
dist += max(diam / 2, VOXEL_SIZE);
dist += max(diam / 2.0, VOXEL_SIZE);
diam = dist * aperture;
}
return sample_col;
Expand All @@ -36,12 +36,12 @@ float trace_shadow(sampler3D voxels, const vec3 origin, const vec3 dir) {
}

float trace_ao(const vec3 origin, const vec3 normal, sampler3D voxels) {
const float angle_mix = 0.5f;
const float angle_mix = 0.5;
const float aperture = 0.55785173935;
vec3 o1 = normalize(tangent(normal));
vec3 o2 = normalize(cross(o1, normal));
vec3 c1 = 0.5f * (o1 + o2);
vec3 c2 = 0.5f * (o1 - o2);
vec3 c1 = vec3(0.5, 0.5, 0.5) * (o1 + o2);
vec3 c2 = vec3(0.5, 0.5, 0.5) * (o1 - o2);

#ifdef HLSL
const float factor = voxelgi_occ * 0.93;
Expand All @@ -55,6 +55,4 @@ float trace_ao(const vec3 origin, const vec3 normal, sampler3D voxels) {
col += trace_cone_ao(voxels, origin, mix(normal, -c1, angle_mix), aperture, MAX_DISTANCE);
col += trace_cone_ao(voxels, origin, mix(normal, -c2, angle_mix), aperture, MAX_DISTANCE);
return (col / 5.0) * factor;

return 0.0;
}
6 changes: 4 additions & 2 deletions base/shaders/std/deferred_light.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ vec3 sample_light(const vec3 p, const vec3 n, const vec3 v, const float dotnv, c
direct *= clamp(dotnl + 2.0 * occ * occ - 1.0, 0.0, 1.0); // Micro shadowing

#ifdef _Voxel
direct *= 1.0 - trace_shadow(voxels, voxpos, l);
float voxshadow = 1.0 - trace_shadow(voxels, voxpos, l);
direct *= vec3(voxshadow, voxshadow, voxshadow);
#endif

return direct;
Expand Down Expand Up @@ -262,7 +263,8 @@ void main() {

#ifdef _Voxel
vec3 voxpos = p / voxelgi_half_extents;
envl.rgb *= 1.0 - trace_ao(voxpos, n, voxels);
float voxao = 1.0 - trace_ao(voxpos, n, voxels);
envl.rgb *= vec3(voxao, voxao, voxao);
#endif

frag_color.rgb = envl;
Expand Down

0 comments on commit ede19ee

Please sign in to comment.