Bi-planar mapping shader

Hello everyone,

I’m trying to create some sort of a Bi-planar mapping shader.
I actually want to use it in a game engine like Godot, but as I’m not very good at writing shaders I decided to first try something in Blender.

Inigo Quilez has already created a Bi-planar mapping shader.
Biplanar mapping (shadertoy.com)
He is using 3 mapping directions ( which are on a 90 degree angle from each ohter so it’s just a box shape ).
Based on the normal the shader decides which 2 from these 3 are the closest, and use and blend those 2.
( So the third one is not used, and therefore is cheaper to render )

However I’m trying to make my version a bit more advanced.
Just like him I also use the first 3 mapping directions ( which are just a box shape, aligned to the world X, Y and Z axis).
BUT I also use 3 extra mapping directions which also have a box shape.
The second box however is first rotated 90 degrees on the world Z axis, and then rotated 45 degrees on the local X axis.

My shader ALWAYS uses one mapping direction from the first (green) box, and one mapping direction from the second rotated (blue) box.
So it always uses one direction which is basicly the world X, Y or Z axis, and a second direction that is 45 degrees rotated.
Because it can choose from more direction, there is less stretching going on.

This works pretty well.
The only thing I need to figure out is how to get the blending perfect.
I added the blend file.
With a blending of -6 some area’s are perfect while others give some problems.
Changing it to - for exampe - 40 fixes these but result in problems in other area’s.
So I guess I need to add some extra math for the blending but I can’t figure it out.
So I hope someone can help me with this.

bi_planar_mapping.blend (1.1 MB)

I don’t know anything about making shaders, but your textures are not packed. Maybe you can include a compressed folder of the texture as well?

Also maybe this is of interest.
https://docs.blender.org/manual/en/3.1/render/shader_nodes/osl.html

You can use any texture.
But the shaders works better with “organic” textures ( like grass, sand, concrete, … ).
A texture with a very clear pattern won’t work very well, although it might be easier to see where the blending problem area’s occur.

Well, I found this maybe it will help. There is at least one example in the thread of blending the edges.

thread:

example: