I’m still having an issue after fixing it. Is there anything else here that could be returning a different value in hlsl to GLSL?
abs,dot,pow, max seem to the only functions used, and I know they’re fine usually. Could it be the normalizing of each element in the array that messing things up. There are also two fGDF functions, labelled exactly the same thing, I’m not sure you’re allowed to do that!
float3 GDFVectors[19] =
{
normalize(float3(1, 0, 0)),
normalize(float3(0, 1, 0)),
normalize(float3(0, 0, 1)),
normalize(float3(1, 1, 1 )),
normalize(float3(-1, 1, 1)),
normalize(float3(1, -1, 1)),
normalize(float3(1, 1, -1)),
normalize(float3(0, 1, PHI+1)),
normalize(float3(0, -1, PHI+1)),
normalize(float3(PHI+1, 0, 1)),
normalize(float3(-PHI-1, 0, 1)),
normalize(float3(1, PHI+1, 0)),
normalize(float3(-1, PHI+1, 0)),
normalize(float3(0, PHI, 1)),
normalize(float3(0, -PHI, 1)),
normalize(float3(1, 0, PHI)),
normalize(float3(-1, 0, PHI)),
normalize(float3(PHI, 1, 0)),
normalize(float3(-PHI, 1, 0))
};
//
// Version with variable exponent.
// This is slow and does not produce correct distances, but allows for bulging of objects.
float fGDF(float3 p, float r, float e, int begin, int end) {
float d = 0;
for (int i = begin; i <= end; ++i)
d += pow(abs(dot(p, GDFVectors[i])), e);
return pow(d, 1/e) - r;
}
// What is different in the title of these functions? How do I know which is getting called?
// Version with without exponent, creates objects with sharp edges and flat faces
float fGDF(float3 p, float r, int begin, int end) {
float d = 0;
for (int i = begin; i <= end; ++i)
d = max(d, abs(dot(p, GDFVectors[i])));
return d - r;
}
// Primitives follow:
float fOctahedron(float3 p, float r, float e) {
return fGDF(p, r, e, 3, 6);
}
float fDodecahedron(float3 p, float r, float e) {
return fGDF(p, r, e, 13, 18);
}
float fIcosahedron(float3 p, float r, float e) {
return fGDF(p, r, e, 3, 12);
}
float fTruncatedOctahedron(float3 p, float r, float e) {
return fGDF(p, r, e, 0, 6);
}
float fTruncatedIcosahedron(float3 p, float r, float e) {
return fGDF(p, r, e, 3, 18);
}
float fOctahedron(float3 p, float r) {
return fGDF(p, r, 3, 6);
}
float fDodecahedron(float3 p, float r) {
return fGDF(p, r, 13, 18);
}
float fIcosahedron(float3 p, float r) {
return fGDF(p, r, 3, 12);
}
float fTruncatedOctahedron(float3 p, float r) {
return fGDF(p, r, 0, 6);
}
float fTruncatedIcosahedron(float3 p, float r) {
return fGDF(p, r, 3, 18);
}