Calculate slope of spherical terrain in shader

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DaddyMonster

I’ve got a planet with spherical terrain. It’s essentially a quadsphere except each face is made up of individual planes as part of an LOD chunk system.

I just want to get the slope of the landscape for texturing. This would normally be all you need:

float dotp_loc = dot(normalize(VERTEX), NORMAL);

but VERTEX is local space and each plane mesh is only a small section of the whole sphere whereas I need the dot from the centre of the sphere (at vec3(0.0) worldspace). So, I expected this to work:

float dotp_glob = dot(normalize((WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz), (WORLD_MATRIX * vec4(NORMAL, 0.0)).xyz);

but it’s giving me the dot product from the origin of each plane mesh. At least I think that’s what it’s doing. If this were gdscript I’d take the xform of the transform but I’m not sure what to do in the shader.

Any suggestions appreciated.