我正在尝试从 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);
这个数字是 2π/360,即 DEG2RAD
而 dotp,又名 cos(theta) 不是一个角度
即 DEG2RAD 它没有意义。
括号是不是错了?
float DEG2RAD = 3.14159/180.0;
float theta_rad = acos(dotp) * DEG2RAD;
即便如此,我怀疑 acos() 返回度数。
任何人都可以在 GLSL 中提供 SLERP 的正确实现吗?
最佳答案
所有这些代码看起来都很好。只需删除“* 3.14159/180.0 ”,让它成为:
float theta = acos(dotp);
关于geometry - 如何在 GLSL/HLSL 中实现 SLERP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23793698/