Skip to content

Instantly share code, notes, and snippets.

@spite
Last active June 9, 2018 09:59
Show Gist options
  • Save spite/9110247 to your computer and use it in GitHub Desktop.
Save spite/9110247 to your computer and use it in GitHub Desktop.

Revisions

  1. spite revised this gist Feb 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,4 @@ m.copy( eyeGeoL.matrixWorld );
    m.multiply( camera.matrixWorldInverse );
    var i = new THREE.Matrix4().getInverse( m );

    eyeGeoL.material.uniforms.myMovelViewMatrixInverse.copy( i );
    eyeGeoL.material.uniforms.myModelViewMatrixInverse.copy( i );
  2. spite revised this gist Feb 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -31,4 +31,4 @@ m.copy( eyeGeoL.matrixWorld );
    m.multiply( camera.matrixWorldInverse );
    var i = new THREE.Matrix4().getInverse( m );

    eyeGeoL.material.attributes.myMovelViewMatrixInverse.copy( i );
    eyeGeoL.material.uniforms.myMovelViewMatrixInverse.copy( i );
  3. spite revised this gist Feb 20, 2014. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,15 @@

    /*
    on Init();
    Add this uniform to your uniforms
    myModelViewMatrixInverse: { type: 'm4', value: new THREE.Matrix4() }
    */

    material = new THREE.ShaderMaterial({
    attributes: {
    myModelViewMatrixInverse: { type: 'm4', value: new THREE.Matrix4() }
    },
    uniforms: uniforms,
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent
    } );
  4. spite created this gist Feb 20, 2014.
    32 changes: 32 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    /*
    uniform types: https://github.com/mrdoob/three.js/wiki/Uniforms-types
    THREE.Matrix4: http://threejs.org/docs/#Reference/Math/Matrix4
    https://github.com/mrdoob/three.js/issues/1188
    */

    /*
    on Init();
    */

    material = new THREE.ShaderMaterial({
    attributes: {
    myModelViewMatrixInverse: { type: 'm4', value: new THREE.Matrix4() }
    },
    uniforms: uniforms,
    vertexShader: document.getElementById( 'vertexShader' ).textContent,
    fragmentShader: document.getElementById( 'fragmentShader' ).textContent
    } );
    eyeGeoL = new THREE.Mesh(geometry, material );

    /*
    on Render();
    camera.matrixWorldInverse * object.matrixWorld => modelViewMatrix
    the order might be wrong, I never get it right at first try
    */

    var m = new THREE.Matrix4();
    m.copy( eyeGeoL.matrixWorld );
    m.multiply( camera.matrixWorldInverse );
    var i = new THREE.Matrix4().getInverse( m );

    eyeGeoL.material.attributes.myMovelViewMatrixInverse.copy( i );