Skip to content

Commit

Permalink
Examples: Moved RaytracingWorker to BufferGeometry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 committed Dec 4, 2018
1 parent 1cd938a commit 3e07c28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
31 changes: 18 additions & 13 deletions examples/js/renderers/RaytracingWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ THREE.RaytracingRendererWorker = function () {
var material = object.material;
var face = intersection.face;

var vertices = object.geometry.vertices;
var geometry = object.geometry;

//

Expand Down Expand Up @@ -250,7 +250,7 @@ THREE.RaytracingRendererWorker = function () {
// (should be possible to cache even more)

localPoint.copy( point ).applyMatrix4( _object.inverseMatrix );
computePixelNormal( normalVector, localPoint, material.flatShading, face, vertices );
computePixelNormal( normalVector, localPoint, material.flatShading, face, geometry );
normalVector.applyMatrix3( _object.normalMatrix ).normalize();

normalComputed = true;
Expand Down Expand Up @@ -378,26 +378,32 @@ THREE.RaytracingRendererWorker = function () {

var computePixelNormal = ( function () {

var vA = new THREE.Vector3();
var vB = new THREE.Vector3();
var vC = new THREE.Vector3();

var tmpVec1 = new THREE.Vector3();
var tmpVec2 = new THREE.Vector3();
var tmpVec3 = new THREE.Vector3();

return function computePixelNormal( outputVector, point, flatShading, face, vertices ) {
return function computePixelNormal( outputVector, point, flatShading, face, geometry ) {

var faceNormal = face.normal;
var vertexNormals = face.vertexNormals;

if ( flatShading === true ) {

outputVector.copy( faceNormal );

} else {

// compute barycentric coordinates
var positions = geometry.attributes.position;
var normals = geometry.attributes.normal;

var vA = vertices[ face.a ];
var vB = vertices[ face.b ];
var vC = vertices[ face.c ];
vA.fromBufferAttribute( positions, face.a );
vB.fromBufferAttribute( positions, face.b );
vC.fromBufferAttribute( positions, face.c );

// compute barycentric coordinates

tmpVec3.crossVectors( tmpVec1.subVectors( vB, vA ), tmpVec2.subVectors( vC, vA ) );
var areaABC = faceNormal.dot( tmpVec3 );
Expand All @@ -414,13 +420,12 @@ THREE.RaytracingRendererWorker = function () {

// compute interpolated vertex normal

tmpVec1.copy( vertexNormals[ 0 ] );
tmpVec1.multiplyScalar( a );
tmpVec1.fromBufferAttribute( normals, face.a );
tmpVec2.fromBufferAttribute( normals, face.b );
tmpVec3.fromBufferAttribute( normals, face.c );

tmpVec2.copy( vertexNormals[ 1 ] );
tmpVec1.multiplyScalar( a );
tmpVec2.multiplyScalar( b );

tmpVec3.copy( vertexNormals[ 2 ] );
tmpVec3.multiplyScalar( c );

outputVector.addVectors( tmpVec1, tmpVec2 );
Expand Down
6 changes: 3 additions & 3 deletions examples/raytracing_sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@

// geometries

var sphereGeometry = new THREE.SphereGeometry( 100, 16, 8 );
var planeGeometry = new THREE.BoxGeometry( 600, 5, 600 );
var boxGeometry = new THREE.BoxGeometry( 100, 100, 100 );
var sphereGeometry = new THREE.SphereBufferGeometry( 100, 16, 8 );
var planeGeometry = new THREE.BoxBufferGeometry( 600, 5, 600 );
var boxGeometry = new THREE.BoxBufferGeometry( 100, 100, 100 );

// Sphere

Expand Down

0 comments on commit 3e07c28

Please sign in to comment.