geometry - 如何在 GLSL/HLSL 中实现 SLERP

标签 geometry glsl interpolation hlsl

我正在尝试从 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/

相关文章:

c# - 点靠近对角线

opengl - 对数深度缓冲区

glsl - GLSL rand() 这一行代码的起源是什么?

c++ - 我已经转换了 The Red Book 9ed ex。 3.7 从旧功能到 4.5 功能,但不显示任何内容

arrays - 根据参数数量在循环中创建数组

python - Pandas 插值在最后一个数据点之后替换 NaN,但不在第一个数据点之前

java - 多个坐标之间的距离

math - 计算由 2 条贝塞尔曲线定义的曲面的边缘点?

java - 获取 GeneralPath 的有序顶点

c# - CPU 上的 XNA 插值?