- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,我已经在 OpenGL 引擎中加载和渲染了基本模型。我有为模型工作的动画。然而,当我尝试向一个场景中添加多个带有动画的模型时,我遇到了一堆奇怪的行为——最后一个模型动画不正确。
在尝试隔离问题时,我相信我遇到了一些可能相关的事情 - 在渲染模型时,如果我将 OpenGL 中的骨骼数据“归零”(即,发送一堆单位矩阵),然后发送实际的骨骼数据,我在模型动画中出现奇怪的“断断续续”。看起来动画中有一个间隙,模型突然回到中间位置,然后快速回到下一帧的动画。
我正在使用安装了专有 NVidia 图形驱动程序的 Debian 7 64 位(带有 3GB VRAM 的 GeForce GTX 560M)。
我在这里有一段视频:http://jarrettchisholm.com/static/videos/wolf_model_animation_problem_1.ogv
在视频中有点难看(我猜它没有捕捉到所有帧)。当狼在它身边时,你可以更清楚地看到它。这贯穿整个动画。
我的模型渲染代码:
for ( glm::detail::uint32 i = 0; i < meshes_.size(); i++ )
{
if ( textures_[i] != nullptr )
{
// TODO: bind to an actual texture position (for multiple textures per mesh, which we currently don't support...maybe at some point we will??? Why would we need multiple textures?)
textures_[i]->bind();
//shader->bindVariable( "Texture", textures_[i]->getBindPoint() );
}
if ( materials_[i] != nullptr )
{
materials_[i]->bind();
shader->bindVariable( "Material", materials_[i]->getBindPoint() );
}
if (currentAnimation_ != nullptr)
{
// This is when I send the Identity matrices to the shader
emptyAnimation_->bind();
shader->bindVariable( "Bones", emptyAnimation_->getBindPoint() );
glw::Animation* a = currentAnimation_->getAnimation();
a->setAnimationTime( currentAnimation_->getAnimationTime() );
// This generates the new bone matrices
a->generateBoneTransforms(globalInverseTransformation_, rootBoneNode_, meshes_[i]->getBoneData());
// This sends the new bone matrices to the shader,
// and also binds the buffer
a->bind();
// This sets the bind point to the Bone uniform matrix in the shader
shader->bindVariable( "Bones", a->getBindPoint() );
}
else
{
// Zero out the animation data
// TODO: Do we need to do this?
// TODO: find a better way to load 'empty' bone data in the shader
emptyAnimation_->bind();
shader->bindVariable( "Bones", emptyAnimation_->getBindPoint() );
}
meshes_[i]->render();
}
着色器绑定(bind)代码:
void GlslShaderProgram::bindVariable(std::string varName, GLuint bindPoint)
{
GLuint uniformBlockIndex = glGetUniformBlockIndex(programId_, varName.c_str());
glUniformBlockBinding(programId_, uniformBlockIndex, bindPoint);
}
动画代码:
...
// This gets called when we create an Animation object
void Animation::setupAnimationUbo()
{
bufferId_ = openGlDevice_->createBufferObject(GL_UNIFORM_BUFFER, 100 * sizeof(glm::mat4), ¤tTransforms_[0]);
}
void Animation::loadIntoVideoMemory()
{
glBindBuffer(GL_UNIFORM_BUFFER, bufferId_);
glBufferSubData(GL_UNIFORM_BUFFER, 0, currentTransforms_.size() * sizeof(glm::mat4), ¤tTransforms_[0]);
}
/**
* Will stream the latest transformation matrices into opengl memory, and will then bind the data to a bind point.
*/
void Animation::bind()
{
loadIntoVideoMemory();
bindPoint_ = openGlDevice_->bindBuffer( bufferId_ );
}
...
我的 OpenGL 包装器代码:
...
GLuint OpenGlDevice::createBufferObject(GLenum target, glmd::uint32 totalSize, const void* dataPointer)
{
GLuint bufferId = 0;
glGenBuffers(1, &bufferId);
glBindBuffer(target, bufferId);
glBufferData(target, totalSize, dataPointer, GL_DYNAMIC_DRAW);
glBindBuffer(target, 0);
bufferIds_.push_back(bufferId);
return bufferId;
}
...
GLuint OpenGlDevice::bindBuffer(GLuint bufferId)
{
// TODO: Do I need a better algorithm here?
GLuint bindPoint = bindPoints_[currentBindPoint_];
currentBindPoint_++;
if ( currentBindPoint_ > bindPoints_.size() )
currentBindPoint_ = 1;
glBindBufferBase(GL_UNIFORM_BUFFER, bindPoint, bufferId);
return bindPoint;
}
...
我的顶点着色器:
#version 150 core
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 pvmMatrix;
uniform mat3 normalMatrix;
in vec3 in_Position;
in vec2 in_Texture;
in vec3 in_Normal;
in ivec4 in_BoneIds;
in vec4 in_BoneWeights;
out vec2 textureCoord;
out vec3 normalDirection;
out vec3 lightDirection;
struct Light {
vec4 ambient;
vec4 diffuse;
vec4 specular;
vec4 position;
vec4 direction;
};
layout(std140) uniform Lights
{
Light lights[ 2 ];
};
layout(std140) uniform Bones
{
mat4 bones[ 100 ];
};
void main() {
// Calculate the transformation on the vertex position based on the bone weightings
mat4 boneTransform = bones[ in_BoneIds[0] ] * in_BoneWeights[0];
boneTransform += bones[ in_BoneIds[1] ] * in_BoneWeights[1];
boneTransform += bones[ in_BoneIds[2] ] * in_BoneWeights[2];
boneTransform += bones[ in_BoneIds[3] ] * in_BoneWeights[3];
vec4 tempPosition = boneTransform * vec4(in_Position, 1.0);
gl_Position = pvmMatrix * tempPosition;
vec4 lightDirTemp = viewMatrix * lights[0].direction;
textureCoord = in_Texture;
normalDirection = normalize(normalMatrix * in_Normal);
lightDirection = normalize(vec3(lightDirTemp));
}
如果我没有包含足够的信息,我深表歉意 - 我输入了我认为有用的信息。如果您想/需要查看更多信息,可以在 https://github.com/jarrettchisholm/glr 获取所有代码。在 master_animation_work
分支下。
最佳答案
它并不是特定于 opengl 的。
当导出器导出模型时,其中一些导出“皮肤游行”姿势。 IE。最初应用“骨骼修改器”的姿势。
在你的情况下,它可能是其中之一
问题可能出在计算动画变换的例程中。
这是调试它的方法。
渲染调试骨骼层次结构(可能使用最笨的着色器,甚至使用固定功能的 opengl)。调试骨骼层次结构可能如下所示:
在图片中 - 橙色线表示动画骨骼的当前位置。飞行坐标系(未连接的坐标系)显示默认位置。三角形和正方形是用于其他目的的调试几何体,与动画系统无关。
目视检查骨骼层级是否正确移动。
如果这个“默认帧”出现在调试层次结构中(即骨骼本身偶尔采取“皮肤游行”姿势),它要么是一个动画框架问题,纯粹是数学问题,它与 opengl 没有任何关系本身,或者是导出商问题(额外的框架)
如果它没有出现在那里(即骨骼正确移动但几何体以皮肤游行姿势站立),这是着色器问题。
调试动画骨架应该在没有任何骨骼权重的情况下渲染 - 只需计算骨骼的世界空间位置并用简单的线条连接它们。尽可能使用最笨的着色器或固定功能。
关于c++ - OpenGL 动画似乎偶尔会丢失骨骼数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797328/
在 OpenGL/ES 中,在实现渲染到纹理功能时,您必须小心,不要引起反馈循环(从正在写入的同一纹理中读取像素)。由于显而易见的原因,当您读取和写入纹理的相同像素时,行为是未定义的。但是,如果您正在
正如我们最终都知道的那样,规范是一回事,实现是另一回事。大多数错误是我们自己造成的,但有时情况并非如此。 我相信列出以下内容会很有用: GPU 驱动程序中当前已知的与最新版本的 OpenGL 和 GL
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。为了帮助澄清这个问题以便可以重新打开它,visit the help center
我正在学习 OpenGL,非常想知道与显卡的交互如何。 我觉得了解它是如何在图形驱动程序中实现的,会让我了解 opengl 的完整内部结构(通过这个我可以知道哪些阶段/因素影响我对 opengl 性能
我正在尝试绘制到大于屏幕尺寸(即 320x480)的渲染缓冲区 (512x512)。 执行 glReadPixels 后,图像看起来是正确的,除非图像的尺寸超过屏幕尺寸——在本例中,超过 320 水平
我正在 Windows 中制作一个 3D 小行星游戏(使用 OpenGL 和 GLUT),您可以在其中穿过一堆障碍物在太空中移动并生存下来。我正在寻找一种方法来针对无聊的 bg 颜色选项设置图像背景。
如果我想要一个包含 100 个 10*10 像素 Sprite 的 Sprite 表,是否可以将它们全部排成一排来制作 1,000*10 像素纹理?还是 GPU 对不那么窄的纹理表现更好?这对性能有什
这个问题在这里已经有了答案: Rendering 2D sprites in a 3D world? (7 个答案) 关闭 6 年前。 我如何概念化让图像始终面对相机。我尝试将三角函数与 arcta
是否可以在 OpenGL 中增加缓冲区? 假设我想使用实例化渲染。每次在世界上生成一个新对象时,我都必须用实例化数据更新缓冲区。 在这种情况下,我有一个 3 个 float 的缓冲区 std::v
有人可以向我解释为什么下面的代码没有绘制任何东西,但如果我使用 GL_LINE_LOOP 它确实形成了一个闭环吗? glBegin(GL_POLYGON); for(int i = 0; i <= N
正如标题所说,OpenGL 中的渲染目标是什么?我对 OpenGL 很陌生,我看到的所有网站都让我很困惑。 它只是一个缓冲区,我在其中放置稍后将用于渲染的东西吗? 如果您能提供一个很好的引用来阅读它,
当使用 OpenGL 1.4 固定功能多纹理时,每个纹理阶段的输出在传递到下一个阶段之前是否都固定在 [0, 1]? spec说(第 153 页): If the value of TEXTURE_E
我比较了 2 个函数 openGL ES 和 openGL gvec4 texelFetchOffset(gsampler2DArray sampler, ivec3 P, int lod, ivec
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
那么当你调用opengl函数时,比如glDraw或者gLBufferData,是否会导致程序线程停止等待GL完成调用呢? 如果不是,那么 GL 如何处理调用像 glDraw 这样的重要函数,然后立即更
我正在尝试实现级联阴影贴图,当我想访问我的视锥体的每个分区的相应深度纹理时,我遇到了一个错误。 更具体地说,当我想选择正确的阴影纹理时会出现我的问题,如果我尝试下面的代码,我会得到一个像 this 中
我想为OpenGL ES和OpenGL(Windows)使用相同的着色器源。为此,我想定义自定义数据类型并仅使用OpenGL ES函数。 一种方法是定义: #define highp #define
我尝试用 6 个位图映射立方体以实现天空盒效果。我的问题是一个纹理映射到立方体的每个面。我已经检查了 gDEBugger,在立方体纹理内存中我只有一个 图像(因为我尝试加载六个图像)。 代码准备纹理:
在 OpenGL 中偏移深度的最佳方法是什么?我目前每个多边形都有索引顶点属性,我将其传递给 OpenGL 中的顶点着色器。我的目标是在深度上偏移多边形,其中最高索引始终位于较低索引的前面。我目前有这
我是一名优秀的程序员,十分优秀!