【问题标题】:Shader Z space perspective ShaderMaterial BufferGeometryShader Z 空间透视 ShaderMaterial BufferGeometry
【发布时间】:2017-07-17 04:36:23
【问题描述】:

我正在更改几何上的 z 坐标顶点,但发现网格保持相同的大小,并且我希望它变得更小。然而,顶点位置之间的补间在 X、Y 空间中按预期工作。

这就是我通过在渲染函数中调整幅度均匀来计算 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 空间中更远的对象不会缩放/衰减/做任何不同的事情。什么给了?

【问题讨论】:

  • 我看到上面没有 z 变化。 z 更改的代码在哪里?还有你的投影矩阵是什么?
  • 更新了问题。投影矩阵是默认情况下由 THREE 传递的任何内容,如果有的话,使用 PerspectiveCamera。阅读:不确定...
  • morphed * vec3(1, -1, 0) 的意思是“不管morphed是什么,乘以它的z-坐标将为0”
  • 哇,好眼力,谢谢

标签: three.js webgl shader


【解决方案1】:

变形 * vec3(1, -1, 0)

z 在您的代码中始终为零。

[x,y,z] * [1,-1,0] = [x,-y,0]

【讨论】:

    猜你喜欢
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多