Shader Z space perspective ShaderMaterial BufferGeometry
Shader Z space perspective ShaderMaterial BufferGeometry
我正在更改几何体上的 z 坐标顶点,但发现网格保持相同大小,我希望它变小。然而,顶点位置之间的补间在 X、Y space 中按预期工作。
这就是我通过在渲染函数中补间幅度均匀来计算 gl_Position 的方式:
<script type="x-shader/x-vertex" id="vertexshader">
uniform float amplitude;
uniform float direction;
uniform vec3 cameraPos;
uniform float time;
attribute vec3 tweenPosition;
varying vec2 vUv;
void main() {
vec3 pos = position;
vec3 morphed = vec3( 0.0, 0.0, 0.0 );
morphed += ( tweenPosition - position ) * amplitude;
morphed += pos;
vec4 mvPosition = modelViewMatrix * vec4( morphed * vec3(1, -1, 0), 1.0 );
vUv = uv;
gl_Position = projectionMatrix * mvPosition;
}
</script>
我也从 webglfundamentals 的计算角度尝试过这样的事情:
vec4 newPos = projectionMatrix * mvPosition;
float zToDivideBy = 1.0 + newPos.z * 1.0;
gl_Position = vec4(newPos.xyz, zToDivideBy);
这是我计算补间的另一个顶点集的循环:
for (var i = 0; i < positions.length; i++) {
if ((i+1) % 3 === 0) {
// subtracting from z coord of each vertex
tweenPositions[i] = positions[i]- (Math.random() * 2000);
} else {
tweenPositions[i] = positions[i]
}
}
我得到了相同的结果——在 Z-Space 中更远的物体不会缩放/衰减/做任何不同的事情。给出了什么?
morphed * vec3(1, -1, 0)
z 在您的代码中始终为零。
[x,y,z] * [1,-1,0] = [x,-y,0]
我正在更改几何体上的 z 坐标顶点,但发现网格保持相同大小,我希望它变小。然而,顶点位置之间的补间在 X、Y space 中按预期工作。
这就是我通过在渲染函数中补间幅度均匀来计算 gl_Position 的方式:
<script type="x-shader/x-vertex" id="vertexshader">
uniform float amplitude;
uniform float direction;
uniform vec3 cameraPos;
uniform float time;
attribute vec3 tweenPosition;
varying vec2 vUv;
void main() {
vec3 pos = position;
vec3 morphed = vec3( 0.0, 0.0, 0.0 );
morphed += ( tweenPosition - position ) * amplitude;
morphed += pos;
vec4 mvPosition = modelViewMatrix * vec4( morphed * vec3(1, -1, 0), 1.0 );
vUv = uv;
gl_Position = projectionMatrix * mvPosition;
}
</script>
我也从 webglfundamentals 的计算角度尝试过这样的事情:
vec4 newPos = projectionMatrix * mvPosition;
float zToDivideBy = 1.0 + newPos.z * 1.0;
gl_Position = vec4(newPos.xyz, zToDivideBy);
这是我计算补间的另一个顶点集的循环:
for (var i = 0; i < positions.length; i++) {
if ((i+1) % 3 === 0) {
// subtracting from z coord of each vertex
tweenPositions[i] = positions[i]- (Math.random() * 2000);
} else {
tweenPositions[i] = positions[i]
}
}
我得到了相同的结果——在 Z-Space 中更远的物体不会缩放/衰减/做任何不同的事情。给出了什么?
morphed * vec3(1, -1, 0)
z 在您的代码中始终为零。
[x,y,z] * [1,-1,0] = [x,-y,0]