Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/jsm/environments/RoomEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RoomEnvironment extends Scene {
super();

this.name = 'RoomEnvironment';
this.position.y = - 3.5;

const geometry = new BoxGeometry();
geometry.deleteAttribute( 'uv' );
Expand Down
11 changes: 6 additions & 5 deletions examples/jsm/shaders/SSRShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const SSRShader = {
float x0=point.x,y0=point.y,z0=point.z;
float x=planePoint.x,y=planePoint.y,z=planePoint.z;
float d=-(a*x+b*y+c*z);
float distance=(a*x0+b*y0+c*z0+d)/sqrt(a*a+b*b+c*c);
float distance=a*x0+b*y0+c*z0+d;
return distance;
}
float getDepth( const in vec2 uv ) {
Expand Down Expand Up @@ -170,17 +170,17 @@ const SSRShader = {
#endif
d1=viewPositionToXY(d1viewPosition);

float totalLen=length(d1-d0);
float xLen=d1.x-d0.x;
float yLen=d1.y-d0.y;
float totalStep=max(abs(xLen),abs(yLen));
float xSpan=xLen/totalStep;
float ySpan=yLen/totalStep;
for(float i=0.;i<float(MAX_STEP);i++){
float sStep=1./totalStep;
float s=sStep; // start at sStep since loop starts at i=1
for(float i=1.;i<float(MAX_STEP);i++){
if(i>=totalStep) break;
vec2 xy=vec2(d0.x+i*xSpan,d0.y+i*ySpan);
if(xy.x<0.||xy.x>resolution.x||xy.y<0.||xy.y>resolution.y) break;
float s=length(xy-d0)/totalLen;
vec2 uv=xy/resolution;

float d = getDepth(uv);
Expand Down Expand Up @@ -221,7 +221,7 @@ const SSRShader = {

if(hit){
vec3 vN=getViewNormal( uv );
if(dot(viewReflectDir,vN)>=0.) continue;
if(dot(viewReflectDir,vN)>=0.) break; // treat backfaces as opaque
float distance=pointPlaneDistance(vP,viewPosition,viewNormal);
if(distance>maxDistance) break;
float op=opacity;
Expand All @@ -240,6 +240,7 @@ const SSRShader = {
break;
}
}
s+=sStep;
}
}
`
Expand Down
31 changes: 16 additions & 15 deletions examples/jsm/tsl/display/SSRNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HalfFloatType, RenderTarget, Vector2, RendererUtils, QuadMesh, TempNode, NodeMaterial, NodeUpdateType, LinearFilter, LinearMipmapLinearFilter } from 'three/webgpu';
import { texture, reference, viewZToPerspectiveDepth, logarithmicDepthToViewZ, getScreenPosition, getViewPosition, sqrt, mul, div, cross, float, Continue, Break, Loop, int, max, abs, sub, If, dot, reflect, normalize, screenCoordinate, nodeObject, Fn, passTexture, uv, uniform, perspectiveDepthToViewZ, orthographicDepthToViewZ, vec2, vec3, vec4 } from 'three/tsl';
import { texture, reference, viewZToPerspectiveDepth, logarithmicDepthToViewZ, getScreenPosition, getViewPosition, mul, div, cross, float, Break, Loop, int, max, abs, sub, If, dot, reflect, normalize, screenCoordinate, nodeObject, Fn, passTexture, uv, uniform, perspectiveDepthToViewZ, orthographicDepthToViewZ, vec2, vec3, vec4 } from 'three/tsl';
import { boxBlur } from './boxBlur.js';

const _quadMesh = /*@__PURE__*/ new QuadMesh();
Expand Down Expand Up @@ -400,9 +400,7 @@ class SSRNode extends TempNode {
// http://paulbourke.net/geometry/pointlineplane/

const d = mul( planeNormal.x, planePoint.x ).add( mul( planeNormal.y, planePoint.y ) ).add( mul( planeNormal.z, planePoint.z ) ).negate().toVar();

const denominator = sqrt( mul( planeNormal.x, planeNormal.x, ).add( mul( planeNormal.y, planeNormal.y ) ).add( mul( planeNormal.z, planeNormal.z ) ) ).toVar();
const distance = div( mul( planeNormal.x, point.x ).add( mul( planeNormal.y, point.y ) ).add( mul( planeNormal.z, point.z ) ).add( d ), denominator );
const distance = mul( planeNormal.x, point.x ).add( mul( planeNormal.y, point.y ) ).add( mul( planeNormal.z, point.z ) ).add( d );
return distance;

} );
Expand Down Expand Up @@ -481,28 +479,31 @@ class SSRNode extends TempNode {

// below variables are used to control the raymarching process

// total length of the ray
const totalLen = d1.sub( d0 ).length().toVar();

// offset in x and y direction
const xLen = d1.x.sub( d0.x ).toVar();
const yLen = d1.y.sub( d0.y ).toVar();

// determine the larger delta
// The larger difference will help to determine how much to travel in the X and Y direction each iteration and
// how many iterations are needed to travel the entire ray
const totalStep = int( max( abs( xLen ), abs( yLen ) ).mul( this.quality.clamp() ) ).toConst();
// scale step count by distance - distant surfaces need less precision (0.5 to 1.0 multiplier)
const distanceFactor = float( 1 ).sub( depth.mul( 0.5 ) ).clamp( 0.5, 1 );
const totalStep = int( max( abs( xLen ), abs( yLen ) ).mul( this.quality.clamp() ).mul( distanceFactor ) ).toConst();

// step sizes in the x and y directions
const xSpan = xLen.div( totalStep ).toVar();
const ySpan = yLen.div( totalStep ).toVar();

const output = vec4( 0 ).toVar();

// incremental interpolation factor
const sStep = float( 1 ).div( float( totalStep ) );
const s = sStep.toVar(); // start at sStep since loop starts at i=1

// the actual ray marching loop
// starting from d0, the code gradually travels along the ray and looks for an intersection with the geometry.
// it does not exceed d1 (the maximum ray extend)
Loop( totalStep, ( { i } ) => {
Loop( { start: int( 1 ), end: totalStep }, ( { i } ) => {

// advance on the ray by computing a new position in screen coordinates
const xy = vec2( d0.x.add( xSpan.mul( float( i ) ) ), d0.y.add( ySpan.mul( float( i ) ) ) ).toVar();
Expand All @@ -521,9 +522,6 @@ class SSRNode extends TempNode {

const viewReflectRayZ = float( 0 ).toVar();

// normalized distance between the current position xy and the starting point d0
const s = xy.sub( d0 ).length().div( totalLen );

// depending on the camera type, we now compute the z-coordinate of the reflected ray at the current step in view space
If( this._isPerspectiveCamera, () => {

Expand Down Expand Up @@ -559,9 +557,9 @@ class SSRNode extends TempNode {

If( dot( viewReflectDir, vN ).greaterThanEqual( 0 ), () => {

// the reflected ray is pointing towards the same side as the fragment's normal (current ray position),
// which means it wouldn't reflect off the surface. The loop continues to the next step for the next ray sample.
Continue();
// the reflected ray is hitting a backface (normal pointing away from ray),
// treat as opaque surface that blocks the ray
Break();

} );

Expand Down Expand Up @@ -596,6 +594,9 @@ class SSRNode extends TempNode {

} );

// advance interpolation factor
s.addAssign( sStep );

} );

return output;
Expand Down
Binary file modified examples/screenshots/misc_exporter_usdz.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_animation_keyframes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_batch_lod_bvh.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_instancing_dynamic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_animation_pointer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_compressed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_dispersion.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_sheen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_ldraw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_texture_lottie.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_materials_alphahash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_morphtargets_face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_morphtargets_webcam.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_instance_path.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_materials_alphahash.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_morphtargets_face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_postprocessing_ca.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_postprocessing_sobel.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgpu_postprocessing_ssr.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/webgl_loader_gltf_compressed.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

scene = new THREE.Scene();
scene.background = new THREE.Color( 0xbbbbbb );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
environment.dispose();

const grid = new THREE.GridHelper( 500, 10, 0xffffff, 0xffffff );
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_loader_gltf_dispersion.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
scene = new THREE.Scene();
scene.backgroundBlurriness = 0.5;

const env = pmremGenerator.fromScene( environment ).texture;
const env = pmremGenerator.fromScene( environment, 0.04 ).texture;
scene.background = env;
scene.environment = env;
environment.dispose();
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_loader_gltf_sheen.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0xbbbbbb );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;

controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_loader_ldraw.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

scene = new THREE.Scene();
scene.background = new THREE.Color( 0xdeebed );
scene.environment = pmremGenerator.fromScene( new RoomEnvironment() ).texture;
scene.environment = pmremGenerator.fromScene( new RoomEnvironment(), 0.04 ).texture;

controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
Expand Down
7 changes: 4 additions & 3 deletions examples/webgl_loader_texture_lottie.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
// texture = new THREE.TextureLoader().load( 'textures/uv_grid_directx.jpg' );
// texture.colorSpace = THREE.SRGBColorSpace;

const geometry = new RoundedBoxGeometry( 1, 1, 1, 7, 0.2 );
const material = new THREE.MeshStandardMaterial( { roughness: 0.1, map: texture } );
const geometry = new RoundedBoxGeometry( 1, 1, 1, 7, 0.1 );
const material = new THREE.MeshStandardMaterial( { roughness: 0, map: texture } );
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );

Expand All @@ -94,12 +94,13 @@
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.toneMapping = THREE.ACESFilmicToneMapping;
document.body.appendChild( renderer.domElement );

const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;

controls = new OrbitControls( camera, renderer.domElement );
controls.autoRotate = true;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_materials_alphahash.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
environment.dispose();

//
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_morphtargets_face.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0x666666 );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;

controls = new OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
Expand Down
11 changes: 5 additions & 6 deletions examples/webgl_morphtargets_webcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import * as THREE from 'three';

import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import { RoomEnvironment } from 'three/addons/environments/RoomEnvironment.js';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
Expand Down Expand Up @@ -114,13 +113,10 @@
camera.position.z = 5;

const scene = new THREE.Scene();
scene.background = new THREE.Color( 0x666666 );
scene.scale.x = - 1;

const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0x666666 );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.add( new THREE.AmbientLight( 0xffffff, 5 ) );

const controls = new OrbitControls( camera, renderer.domElement );

Expand All @@ -144,6 +140,9 @@
const head = mesh.getObjectByName( 'mesh_2' );
head.material = new THREE.MeshNormalMaterial();

const teeth = mesh.getObjectByName( 'mesh_3' );
teeth.material = new THREE.MeshNormalMaterial();

face = mesh.getObjectByName( 'mesh_2' );
eyeL = mesh.getObjectByName( 'eyeLeft' );
eyeR = mesh.getObjectByName( 'eyeRight' );
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_materials_alphahash.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
environment.dispose();

//
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_morphtargets_face.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0x666666 );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;

const ktx2Loader = await new KTX2Loader()
.setTranscoderPath( 'jsm/libs/basis/' )
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_postprocessing_ao.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.background = new THREE.Color( 0x666666 );
scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
environment.dispose();
pmremGenerator.dispose();

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_postprocessing_sobel.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
pmremGenerator.dispose();

//
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_postprocessing_ssr.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
const environment = new RoomEnvironment();
const pmremGenerator = new THREE.PMREMGenerator( renderer );

scene.environment = pmremGenerator.fromScene( environment ).texture;
scene.environment = pmremGenerator.fromScene( environment, 0.04 ).texture;
scene.environmentIntensity = 1.25;
pmremGenerator.dispose();

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
"puppeteer": "^24.25.0",
"qunit": "^2.19.4",
"rollup": "^4.6.0",
"rollup-plugin-filesize": "^10.0.0",
"servez": "^2.2.4"
},
"overrides": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/Object3D.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class Object3D extends EventDispatcher {
}

/**
* Converts the given vector from this 3D object's word space to local space.
* Converts the given vector from this 3D object's world space to local space.
*
* @param {Vector3} vector - The vector to convert.
* @return {Vector3} The converted vector.
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/puppeteer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import puppeteer from 'puppeteer';
import express from 'express';
import path from 'path';
import pixelmatch from 'pixelmatch';
import { Jimp } from 'jimp';
import * as fs from 'fs/promises';
import server from './server.js';

const exceptionList = [

Expand Down Expand Up @@ -117,9 +116,7 @@ let browser;

/* Launch server */

const app = express();
app.use( express.static( path.resolve() ) );
const server = app.listen( port, main );
server.listen( port, main );

process.on( 'SIGINT', async () => {

Expand Down
Loading