I’m having some issues translating raw GLSL code into Defold’s shader. The objective is to make a triplanar texturing, the thing is it’s breaking in a very weird way:
I have the code in this repo: GitHub - Caue-Aron/Unfold: Defold extension to convert GLTF scenes into Defold's collection
But heres a snippet:
vertex:
#version 140
in vec4 position;
in vec3 normal;
uniform vs_uniforms
{
mat4 mtx_world;
mat4 mtx_view;
mat4 mtx_proj;
mat4 mtx_normal;
};
out vec3 w_normal;
out vec3 coords;
out float diff_light;
void main()
{
vec3 L = -normalize(vec3(0, -.5, -1));
vec3 N = normalize(vec3(mtx_normal * vec4(normal, 0.0)));
diff_light = max(dot(N, L), 0.0);
coords = vec3(mtx_world * vec4(position.xyz, 1.0));
w_normal = N;
gl_Position = mtx_proj * mtx_view * mtx_world * position;
}
fragment -notice i tried 2 different versions, to no success and failing the same way
#version 140
in vec3 w_normal;
in vec3 coords;
in float diff_light;
out vec4 color_out;
uniform sampler2D floor;
uniform sampler2D wall;
uniform sampler2D ceiling;
void main()
{
// vec3 blending = abs(w_normal);
// blending = normalize(max(blending, 0.00001));
// blending /= vec3(blending.x + blending.y + blending.z);
// vec4 xaxis = texture(ceiling, coords.yz);
// vec4 yaxis = texture(ceiling, coords.xz);
// vec4 zaxis = texture(ceiling, coords.xy);
// vec4 tex = xaxis * blending.x + yaxis * blending.y + zaxis * blending.z;
vec2 y_uv = coords.xz;
vec2 x_uv = coords.zy;
vec2 z_uv = coords.xy;
vec3 y_diff = texture(ceiling, y_uv).rgb;
vec3 x_diff = texture(ceiling, x_uv).rgb;
vec3 z_diff = texture(ceiling, z_uv).rgb;
vec3 blend_weights = abs(w_normal);
blend_weights /= (blend_weights.x + blend_weights.y + blend_weights.z);
vec3 tex = x_diff * blend_weights.x + y_diff * blend_weights.y + z_diff * blend_weights.z;
color_out = vec4(tex.rgb, 1.0);
}
If i could point something out as a culprit, id say im missing something either in the materials or some “quirk” with the specifics of Defold. But i genuinely dont know what it could be, since the material seems ok at first:
These were my resources:
https://code.tutsplus.com/use-tri-planar-texture-mapping-for-better-terrain--gamedev-13821a

