animation - Update normals of animated skinned mesh in three.js?
问题描述
I have a simple animated model, animated throught skinning, and I am giving it a ShaderMaterial
which displays its normals:
gl_FragColor = vec4(vNormal, 1.0);
https://codepen.io/marco_fugaro/pen/ZEEBjKz?editors=0010
The problem is the normals aren't updated with the skinning of the model, and they always stay the same from the object's non animated position (see VertexNormalsHelper
).
How do I get the normals to update, or how do i get the animated vertices' normals?
model.geometry.computeVertexNormals()
doesn't work
解决方案
我最终猴子修补了MeshNormalMaterial
顶点着色器,并删除了法线相对于相机的逻辑,这是最终代码:
import * as THREE from 'three'
import normalVert from 'three/src/renderers/shaders/ShaderLib/normal_vert.glsl'
// like MeshNormalMaterial, but the normals are relative to world not camera
const normalMaterialGlobalvert = normalVert.replace(
'#include <defaultnormal_vertex>',
THREE.ShaderChunk['defaultnormal_vertex'].replace(
'transformedNormal = normalMatrix * transformedNormal;',
// take into consideration only the model matrix
'transformedNormal = mat3(modelMatrix) * transformedNormal;'
)
)
然后像这样使用它:
mesh.material = new THREE.ShaderMaterial({
vertexShader: normalMaterialGlobalvert,
fragmentShader: `
varying vec3 vNormal;
void main() {
gl_FragColor = vec4(vNormal, 1.0);
}
`,
})
感谢gman为我指明了正确的方向!
推荐阅读
- firebase - Firestore 规则拆分自定义令牌并查看它是否匹配
- html - Safari:可滚动 div 中的滚动条颜色错误
- python - 简单的内置函数将数字拆分为 bin
- python - pyserial 和 esp-32s - 当 ser.open esp32 停止运行时
- github - 有没有办法在合并其他分支时自动调用特定分支上的拉取请求?
- excel - Excel VBA(非常慢)如果满足条件,则将整行移至底部
- android-external-storage - 无法从 Android 外部存储中的外部文件位置读取文件
- python - 在 Tkinter 中使按钮更改自己的颜色
- python - 包装一个 2D numpy 数组
- docker - Jenkins Groovy 字符串插值将秘密解析为 ****