<commit_before>export default class SDFShader {
  static Voxel() {
    return `
      struct Voxel
      {
        vec4 coord;
        vec4 material;
      };
    `
  }

  static sdfBox() {
    return `
      Voxel sdfBox(vec3 position, vec3 box, vec4 material) {
        return Voxel(vec4(position, length(max(abs(position) - box, 0.0))), material);
      }
    `;
  }

  static sdfSphere() {
    return `
      Voxel sdfSphere(vec3 position, float radius, vec4 material) {
        return Voxel(vec4(position, length(position) - radius), material);
      }
    `;
  }

  static smoothMin() {
    return `
      Voxel smoothMin(Voxel voxel1, Voxel voxel2, float blendRatio) {
        float ratio = clamp(.5 + .5 * (voxel2.coord.w - voxel1.coord.w) / blendRatio, 0., 1.);
    
        vec4 coord = mix(voxel2.coord, voxel1.coord, ratio) - blendRatio * ratio * (1. - ratio);
        vec4 material = mix(voxel2.material, voxel1.material, ratio);
    
        return Voxel(coord, material);
      }
    `;
  }

  static min() {
    return `
      Voxel min(Voxel voxel1, Voxel voxel2) {
        if(voxel1.coord.w < voxel2.coord.w) {
          return voxel1;
        }
        else {
          return voxel2;
        }
      }
    `;
  }

  static repeat() {
    return `
      float repeat(float p, float c) {
        return mod(p,c) - 0.5 * c;
      }

      vec2 repeat(vec2 p, vec2 c) {
        return mod(p,c) - 0.5 * c;
      }

      vec3 repeat(vec3 p, vec3 c) {
        return mod(p,c) - 0.5 * c;
      }
    `;
  }

  static rayMarch({
    map = `
      Voxel voxel = Voxel(0., vec4(0.));
      return voxel;
    `
  } = {}) {
    return `
      Voxel map(vec3 position) {
        ${map}
      }

      vec3 normalFromPosition(vec3 position) {
        vec2 e = vec2(.01, 0.0);
        return normalize(vec3(
          map(position + e.xyy).coord.w - map(position - e.xyy).coord.w,
          map(position + e.yxy).coord.w - map(position - e.yxy).coord.w,
          map(position + e.yyx).coord.w - map(position - e.yyx).coord.w
        ));
      }

      Voxel rayMarch(Ray ray, float near, float far, int steps)
      {
        Voxel voxel;

        float rayMarchingStep = far;
        float distance = near;

        for(int i = 0; i < 128; i++) {
          if (i == steps || rayMarchingStep < 0.0001 || distance > far) break;
          voxel = map(ray.origin + ray.direction * distance);
          rayMarchingStep = voxel.coord.w;
          distance += rayMarchingStep;
        }

        voxel.coord.w = distance;

        return voxel;<commit_msg>fix SDFShader far voxel<commit_after>export default class SDFShader {
  static Voxel() {
    return `
      struct Voxel
      {
        vec4 coord;
        vec4 material;
      };
    `
  }

  static sdfBox() {
    return `
      Voxel sdfBox(vec3 position, vec3 box, vec4 material) {
        return Voxel(vec4(position, length(max(abs(position) - box, 0.0))), material);
      }
    `;
  }

  static sdfSphere() {
    return `
      Voxel sdfSphere(vec3 position, float radius, vec4 material) {
        return Voxel(vec4(position, length(position) - radius), material);
      }
    `;
  }

  static smoothMin() {
    return `
      Voxel smoothMin(Voxel voxel1, Voxel voxel2, float blendRatio) {
        float ratio = clamp(.5 + .5 * (voxel2.coord.w - voxel1.coord.w) / blendRatio, 0., 1.);
    
        vec4 coord = mix(voxel2.coord, voxel1.coord, ratio) - blendRatio * ratio * (1. - ratio);
        vec4 material = mix(voxel2.material, voxel1.material, ratio);
    
        return Voxel(coord, material);
      }
    `;
  }

  static min() {
    return `
      Voxel min(Voxel voxel1, Voxel voxel2) {
        if(voxel1.coord.w < voxel2.coord.w) {
          return voxel1;
        }
        else {
          return voxel2;
        }
      }
    `;
  }

  static repeat() {
    return `
      float repeat(float p, float c) {
        return mod(p,c) - 0.5 * c;
      }

      vec2 repeat(vec2 p, vec2 c) {
        return mod(p,c) - 0.5 * c;
      }

      vec3 repeat(vec3 p, vec3 c) {
        return mod(p,c) - 0.5 * c;
      }
    `;
  }

  static rayMarch({
    map = `
      Voxel voxel = Voxel(0., vec4(0.));
      return voxel;
    `,
    maxSteps = 128
  } = {}) {
    return `
      Voxel map(vec3 position) {
        ${map}
      }

      vec3 normalFromPosition(vec3 position) {
        vec2 e = vec2(.01, 0.0);
        return normalize(vec3(
          map(position + e.xyy).coord.w - map(position - e.xyy).coord.w,
          map(position + e.yxy).coord.w - map(position - e.yxy).coord.w,
          map(position + e.yyx).coord.w - map(position - e.yyx).coord.w
        ));
      }

      Voxel rayMarch(Ray ray, float near, float far, int steps)
      {
        Voxel voxel;

        float rayMarchingStep = far;
        float distance = near;

        for(int i = 0; i < ${maxSteps}; i++) {
          if (i == steps || rayMarchingStep < 0.0001 || distance > far) break;
          voxel = map(ray.origin + ray.direction * distance);
          rayMarchingStep = voxel.coord.w;
          distance += rayMarchingStep;
        }

        voxel.coord.w = distance;
        voxel = min(voxel, Voxel(vec4(0., 0., 0., far), vec4(0.)));

        return voxel;
{'fraction_non_alphanumeric': 0.13261786124952088, 'fraction_numerical': 0.026446914526638558, 'mean_word_length': 1.7482885729331228, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2089878', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1827, 'n_words': 417}