0
votes

I'm changing the z coordinate vertices on my geometry but find that the Mesh Stays the same size, and I'm expecting it to get smaller. Tweening between vertex positions works as expected in X,Y space however.

This is how I'm calculating my gl_Position by tweening the amplitude uniform in my render function:

<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>

I also tried something like this from calculating perspective on webglfundamentals:

vec4 newPos = projectionMatrix * mvPosition;
float zToDivideBy = 1.0 + newPos.z * 1.0;
gl_Position = vec4(newPos.xyz, zToDivideBy);

This is my loop to calculate another vertex set that I'm tweening between:

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]
    }   
}

I get the same results with this -- objects further away in Z-Space do not scale / attenuate / do anything different. What gives?

1
I see no z changing above. Where's the code that's changing z? Also what's your projection matrix? - gman
Updated the question. Projection matrix is whatever is being passed by THREE by default, if anything, using a PerspectiveCamera. read: not sure... - N. Pyle
morphed * vec3(1, -1, 0) means "no matter what the morphed is, after multiplication its z-coordinate will be 0" - prisoner849
Wow, good eye, thank you - N. Pyle

1 Answers

0
votes

morphed * vec3(1, -1, 0)

z is always zero in your code.

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