Texture_coordinate_world weird results


I am trying to use the texture_coordinate_world to tile a texture in world-space. I’ve re-created the same material in both Substance Designer and manually/in-code and see the same issue in both where a flat plane with no transformation is not getting the texture applied.

Attached are a couple of pictures from substance to show the material + what is happening. You can see one side of the cube is correctly textured, but the other side (which is the side that faces straight down) has no texture applied. Is this the correct/intended behavior? I would expect all sides to have the tiled texture. Additionally, when the geometry is switched to a flat plane, then there’s no texture at all.

The same results are observed when changed to texture_coordinate_object as well.

if you use a 3d coordinate system like “world” with a 2d texture, you will use 2 out of the 3 dimensions for texturing (x,y) and the 3rd will have no use. What you effectively implement is a “planar projection” in x,y.

For the cube, this means that 2 sides will have varying xy and constant z, 2 sides will have varying xz and constant y and 2 sides have varying yz and constant x. only on the first you will see normal tiling, the other 2 will show 1d slices through your texture. That slice is probably constant white in your texture

If you want proper layout on all 6 sides, you will need to implement triplanar or box mapping, meaning implement not only planar in xy but also planar in xz and yz and select based on where the normal points.

there is a function “coordinate_projection” which can do this for you

for reference:
https://raytracing-docs.nvidia.com/mdl/base_module/index.html#base#functions and the actual implementation can be found here: MDL-SDK/base.mdl at master · NVIDIA/MDL-SDK · GitHub

ahhhh, that makes sense, thank you for the explanation!

Using the coordinate_projection and either triplanar or box mapping gives me what I’m looking for, thanks again.