Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- store anisotropic voxel data:
- -----------------------------
- vec3 accum_total = vec3(0.0);
- accum_total += outputs.data[cell_index*6+0].rgb;
- accum_total += outputs.data[cell_index*6+1].rgb;
- accum_total += outputs.data[cell_index*6+2].rgb;
- accum_total += outputs.data[cell_index*6+3].rgb;
- accum_total += outputs.data[cell_index*6+4].rgb;
- accum_total += outputs.data[cell_index*6+5].rgb;
- float accum_total_energy = max(dot(accum_total,GREY_VEC),0.00001);
- vec3 iso_positive = vec3(dot(outputs.data[cell_index*6+0].rgb,GREY_VEC),dot(outputs.data[cell_index*6+2].rgb,GREY_VEC),dot(outputs.data[cell_index*6+4].rgb,GREY_VEC))/vec3(accum_total_energy);
- vec3 iso_negative = vec3(dot(outputs.data[cell_index*6+1].rgb,GREY_VEC),dot(outputs.data[cell_index*6+3].rgb,GREY_VEC),dot(outputs.data[cell_index*6+5].rgb,GREY_VEC))/vec3(accum_total_energy);
- //aniso textures are R16U
- {
- uint aniso_pos = uint(clamp(iso_positive.b * 31.0,0.0,31.0));
- aniso_pos |= uint(clamp(iso_positive.g * 63.0,0.0,63.0))<<5;
- aniso_pos |= uint(clamp(iso_positive.r * 31.0,0.0,31.0))<<11;
- imageStore(aniso_pos_tex,ivec3(posu),uvec4(aniso_pos));
- }
- {
- uint aniso_neg = uint(clamp(iso_negative.b * 31.0,0.0,31.0));
- aniso_neg |= uint(clamp(iso_negative.g * 63.0,0.0,63.0))<<5;
- aniso_neg |= uint(clamp(iso_negative.r * 31.0,0.0,31.0))<<11;
- imageStore(aniso_neg_tex,ivec3(posu),uvec4(aniso_neg));
- }
- imageStore(color_tex,ivec3(posu),vec4(accum_total / params.dynamic_range ,albedo.a));
- Voxel Cone Trace with Anisotropy:
- ----------------------------------
- vec4 voxel_cone_trace_anisotropic(texture3D probe,texture3D aniso_pos,texture3D aniso_neg,vec3 normal, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias) {
- float dist = p_bias;
- vec4 color = vec4(0.0);
- while (dist < max_distance && color.a < 0.95) {
- float diameter = max(1.0, 2.0 * tan_half_angle * dist);
- vec3 uvw_pos = (pos + dist * direction) * cell_size;
- float half_diameter = diameter * 0.5;
- //check if outside, then break
- //if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + half_diameter * cell_size)) ) ) {
- // break;
- //}
- float log2_diameter = log2(diameter);
- vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter);
- vec3 aniso_neg = textureLod(sampler3D(aniso_neg,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb;
- vec3 aniso_pos = textureLod(sampler3D(aniso_pos,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb;
- scolor.rgb*=dot(max(vec3(0.0),(normal * aniso_pos)),vec3(1.0)) + dot(max(vec3(0.0),(-normal * aniso_neg)),vec3(1.0));
- float a = (1.0 - color.a);
- color += a * scolor;
- dist += half_diameter;
- }
- return color;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement