ray-tracing-renderer icon indicating copy to clipboard operation
ray-tracing-renderer copied to clipboard

Add support for texture .repeat and .offset

Open ManishJu opened this issue 4 years ago • 2 comments

If you set the texture to repeat over a surface, the texture does not repeat while doing ray tracing and resorts to 1 large texture over the entire surface. Here is the webgl2 renderer version : xz

And here is the raytraced version : xz2

This happens even when you upload a GLTF file with a repeat pattern . Here is the file for you to test: https://drive.google.com/file/d/1idu7p_C36dxsTNpcNE4vFQXfsP7IpAbi/view?usp=sharing

Thanks !

ManishJu avatar Jan 16 '20 09:01 ManishJu

Thanks for your contribution! The renderer doesn't implement Texture.repeat, so it doesn't do anything at the moment. It's been on my plate to add but it has been pushed away to higher priority tasks, so unfortunately I won't be able to get to it in the next few months.

If you're able to use this workaround, you can get texture tiling by modifying the geometry's UV values directly, before passing it to the renderer. e.g., from the GLTF model you loaded, the following works:

  model.traverse(child => {
    if (child.name === 'Plane') { // select and modify only the ground plane
      const tex = child.material.map;
      const uv = child.geometry.getAttribute('uv').array;

      for (let i = 0; i < uv.length; i += 2) {
        uv[i] *= tex.repeat.x; // u coord
        uv[i + 1] *= tex.repeat.y; // v coord
      }
    }
});

And wa-la. tile It's a messy workaround, but I hope it's okay for now.

jaxry avatar Jan 16 '20 20:01 jaxry

Thankyou for your answer :)

ManishJu avatar Jan 17 '20 14:01 ManishJu