- Home /
TriPlanar Textures Not Working Properly
I recently implemented a Triplanar Shader to the terrain generator that I'm working on by following this tutorial: https://www.youtube.com/watch?v=XU0r-Xh-Jgc
The material with the shader attached to it seems to be working fine (as seen by the capsule in the image) but whenever I apply the material to my terrain it just maps some greenish color to the top and a grayish color to the sides. While this is the effect I was looking for I was wanting the actual textures to be mapped so I can see them rather than just a color. I don't know whether this is just because the texture is extremely stretched across a large part of the terrain or if the problem is elsewhere. Anyway, could somebody help me resolve this issue or at least point me to the source of the problem?
As a side note, I'm using 3D Perlin Noise with the Marching Cubes algorithm to generate the terrain if that helps at all.
Any help is appreciated so thank you very much in advance!
Answer by Namey5 · Mar 08, 2020 at 03:47 AM
At a glance, that doesn't look like triplanar texturing at all - it just looks like regular UV mapped texturing (see the stretching at the top of the capsule). This would also explain why you would get a single colour instead of the actual texture input on your model (the UVs would default to [0,0] and just return the top-left pixel of the texture). Instead of using UVs to sample the texture, use world-space position, matching the primary axis to the texture (i.e. surface facing up on the y-axis use the .xz components of the world position, etc).
Okay so I followed your advice but now I have run into another issue. The textures are working properly and actually mapping but they are being mapped in an odd way. Ins$$anonymous$$d of mapping straight from the top (or the side) they are swirling and for$$anonymous$$g these circles on the ground. You can see it in the previews in the shader. Thank you for your help from before but can you still help me understand where I went wrong here?
I'm a shader programmer (I've never used shader graph before), but below is an image of a basic graph that will work. Unfortunately, unity answers isn't cooperating today, so I'm unable to actually send any images or attachments directly. Ins$$anonymous$$d, here's a link to a lower resolution version on my website;
I would also send a copy of the graph, but I can't. Let me know if it's not readable and I'll try and explain what each part does.
So turns out that the issue I was having with the textures looking "spherical" on the ground was a problem with the actual textures I was using and not the shader. I fixed my own shader to work with the absolute world position of the object but I have taken parts of yours because it is in fact better. $$anonymous$$ine was also less versatile as it technically was a "biplanar" shader so yours gives me more control. The graph is readable and just by working through it I was able to make sense of most of it. Thank you so much for all of your help, your answers were amazing and really helped out!
Also, the reason I wanted to work with a shader graph is because I had never made one so I figured this might be the best opportunity to try to do so.