我正在尝试从GLSL进行SLERP (HLSL也可以,因为我的目标是Unity3D)
我找到了这个页面:http://www.geeks3d.com/20140205/glsl-simple-morph-target-animation-opengl-glslhacker-demo
它包含以下列表:
#version 150
in vec4 gxl3d_Position;
in vec4 gxl3d_Attrib0;
in vec4 gxl3d_Attrib1;
out vec4 Vertex_Color;
uniform mat4 gxl3d_ModelViewProjectionMatrix;
uniform float time;
vec4 Slerp(vec4 p0, vec4 p1, float t)
{
float dotp = dot(normalize(p0), normalize(p1));
if ((dotp > 0.9999) || (dotp<-0.9999))
{
if (t<=0.5)
return p0;
return p1;
}
float theta = acos(dotp * 3.14159/180.0);
vec4 P = ((p0*sin((1-t)*theta) + p1*sin(t*theta)) / sin(theta));
P.w = 1;
return P;
}
void main()
{
vec4 P = Slerp(gxl3d_Position, gxl3d_Attrib1, time);
gl_Position = gxl3d_ModelViewProjectionMatrix * P;
Vertex_Color = gxl3d_Attrib0;
}
数学可以在维基百科上找到SLERP的页面:http://en.wikipedia.org/wiki/Slerp
但我质疑这条线
float theta = acos(dotp * 3.14159/180.0);
这个数字是2theta/360,即DEG2RAD和dotp,又名cos(π)不是一个角度
也就是说,使用DEG2RAD是没有意义的。
括号是不是错了?
float DEG2RAD = 3.14159/180.0;
float theta_rad = acos(dotp) * DEG2RAD;
即使这样,我也怀疑acos()是否返回学位。
有人能在GLSL中提供SLERP的正确实现吗?
发布于 2018-08-22 06:06:38
所有这些代码看起来都很好。去掉“*180.0/3.14159”,就这样吧:
float theta = acos(dotp);
https://stackoverflow.com/questions/23793698
复制相似问题