Ich spiele mit GLSL
und bekam this effect. Und ich versuchte, es zu Metall zu konvertieren, aber ich habe einige flippige Ergebnis für y-axis
, wenn er kleiner als 0:Mathe Unterschiede zwischen GLSL und Metall
Es gibt diese lustige kurvige Ernte weg für die meisten der Würfel über dem Horizont (< 0). Das ist mein Metal
Code:
static float mod(float x, float y)
{
return x - y * floor(x/y);
}
static float vmax(float3 v) {
return max(max(v.x, v.y), v.z);
}
float fBoxCheap(float3 p, float3 b) { //cheap box
return vmax(abs(p) - b);
}
static float map(float3 p)
{
p.x = mod(p.x + 5,10)-5;
p.y = mod(p.y + 5 ,10)-5;
p.z = mod(p.z + 5 ,10)-5;
float box = fBoxCheap(p-float3(0.0,3.0,0.0),float3(4.0,3.0,1.0));
return box;
}
Es ist fast der gleiche Code in GLSL
:
float vmax(vec3 v) {
return max(max(v.x, v.y), v.z);
}
float box(vec3 p, vec3 b) { //cheap box
return vmax(abs(p) - b);
}
float map(vec3 p)
{
p.x=mod(p.x+3.0,6.0)-3.0;
p.y=mod(p.y+3.0,6.0)-3.0;
p.z=mod(p.z+3.0,6.0)-3.0;
return box(p, vec3(1.,1.,1.));
}
Wie kann ich dieses Problem lösen? Ich bin relativ neu sowohl GLSL
und Metal
, aber ich finde Metal
ist schwieriger wegen dieser Mathe Problem.
Ich bemerke den gleichen Effekt in GLSL, wenn Sie p-vec3 (0.0, 3.0.0.0) verwenden. Versuche es mit nur p, ohne etwas davon zu subtrahieren. – Marius
Ich habe es versucht. Es wird noch feiger. – sooon
Was ist deine Definition von 'mod'? – warrenm