Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. store anisotropic voxel data:
  2. -----------------------------
  3.         vec3 accum_total = vec3(0.0);
  4.         accum_total += outputs.data[cell_index*6+0].rgb;
  5.         accum_total += outputs.data[cell_index*6+1].rgb;
  6.         accum_total += outputs.data[cell_index*6+2].rgb;
  7.         accum_total += outputs.data[cell_index*6+3].rgb;
  8.         accum_total += outputs.data[cell_index*6+4].rgb;
  9.         accum_total += outputs.data[cell_index*6+5].rgb;
  10.  
  11.         float accum_total_energy = max(dot(accum_total,GREY_VEC),0.00001);
  12.         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);
  13.         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);
  14.  
  15. //aniso textures are R16U
  16.         {
  17.             uint aniso_pos = uint(clamp(iso_positive.b * 31.0,0.0,31.0));
  18.             aniso_pos |= uint(clamp(iso_positive.g * 63.0,0.0,63.0))<<5;
  19.             aniso_pos |= uint(clamp(iso_positive.r * 31.0,0.0,31.0))<<11;
  20.             imageStore(aniso_pos_tex,ivec3(posu),uvec4(aniso_pos));
  21.         }
  22.  
  23.         {
  24.             uint aniso_neg = uint(clamp(iso_negative.b * 31.0,0.0,31.0));
  25.             aniso_neg |= uint(clamp(iso_negative.g * 63.0,0.0,63.0))<<5;
  26.             aniso_neg |= uint(clamp(iso_negative.r * 31.0,0.0,31.0))<<11;
  27.             imageStore(aniso_neg_tex,ivec3(posu),uvec4(aniso_neg));
  28.         }
  29.  
  30.         imageStore(color_tex,ivec3(posu),vec4(accum_total / params.dynamic_range ,albedo.a));
  31.  
  32. Voxel Cone Trace with Anisotropy:
  33. ----------------------------------
  34.  
  35.  
  36. 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) {
  37.  
  38.     float dist = p_bias;
  39.     vec4 color = vec4(0.0);
  40.  
  41.     while (dist < max_distance && color.a < 0.95) {
  42.         float diameter = max(1.0, 2.0 * tan_half_angle * dist);
  43.         vec3 uvw_pos = (pos + dist * direction) * cell_size;
  44.         float half_diameter = diameter * 0.5;
  45.         //check if outside, then break
  46.         //if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + half_diameter * cell_size)) ) ) {
  47.         //  break;
  48.         //}
  49.         float log2_diameter = log2(diameter);
  50.         vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter);
  51.         vec3 aniso_neg = textureLod(sampler3D(aniso_neg,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb;
  52.         vec3 aniso_pos = textureLod(sampler3D(aniso_pos,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb;
  53.  
  54.         scolor.rgb*=dot(max(vec3(0.0),(normal * aniso_pos)),vec3(1.0)) + dot(max(vec3(0.0),(-normal * aniso_neg)),vec3(1.0));
  55.  
  56.         float a = (1.0 - color.a);
  57.         color += a * scolor;
  58.         dist += half_diameter;
  59.  
  60.     }
  61.  
  62.     return color;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement