Skip to content

Commit

Permalink
TSL: Rename viewportTopLeft -> viewportUV (#29211)
Browse files Browse the repository at this point in the history
* TSL: Rename `viewportTopLeft` -> `viewportUV`

* cleanup
  • Loading branch information
sunag committed Aug 22, 2024
1 parent 91c5b8d commit f22b8b0
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 71 deletions.
8 changes: 4 additions & 4 deletions examples/webgpu_backdrop.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { float, vec3, color, viewportSharedTexture, viewportSafeUV, viewportTopLeft, checker, uv, timerLocal, oscSine, output } from 'three/tsl';
import { float, vec3, color, viewportSharedTexture, viewportSafeUV, viewportUV, checker, uv, timerLocal, oscSine, output } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand All @@ -43,7 +43,7 @@
camera.position.set( 1, 2, 3 );

scene = new THREE.Scene();
scene.backgroundNode = viewportTopLeft.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
scene.backgroundNode = viewportUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
camera.lookAt( 0, 1, 0 );

clock = new THREE.Clock();
Expand Down Expand Up @@ -111,8 +111,8 @@
addBackdropSphere( viewportSharedTexture().rgb.saturation( 0 ) );
addBackdropSphere( viewportSharedTexture().rgb.saturation( 10 ), oscSine() );
addBackdropSphere( viewportSharedTexture().rgb.overlay( checker( uv().mul( 10 ) ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( viewportTopLeft.mul( 40 ).floor().div( 40 ) ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( viewportTopLeft.mul( 80 ).floor().div( 80 ) ) ).add( color( 0x0033ff ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( viewportUV.mul( 40 ).floor().div( 40 ) ) ) );
addBackdropSphere( viewportSharedTexture( viewportSafeUV( viewportUV.mul( 80 ).floor().div( 80 ) ) ).add( color( 0x0033ff ) ) );
addBackdropSphere( vec3( 0, 0, viewportSharedTexture().b ) );

//renderer
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_backdrop_area.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { color, linearDepth, viewportLinearDepth, viewportSharedTexture, viewportMipTexture, viewportTopLeft, checker, uv, modelScale } from 'three/tsl';
import { color, linearDepth, viewportLinearDepth, viewportSharedTexture, viewportMipTexture, viewportUV, checker, uv, modelScale } from 'three/tsl';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

Expand Down Expand Up @@ -106,7 +106,7 @@
bicubicMaterial.side = THREE.DoubleSide;

const pixelMaterial = new THREE.MeshBasicNodeMaterial();
pixelMaterial.backdropNode = viewportSharedTexture( viewportTopLeft.mul( 100 ).floor().div( 100 ) );
pixelMaterial.backdropNode = viewportSharedTexture( viewportUV.mul( 100 ).floor().div( 100 ) );
pixelMaterial.transparent = true;

// box / floor
Expand Down
8 changes: 4 additions & 4 deletions examples/webgpu_backdrop_water.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { color, vec2, pass, linearDepth, normalWorld, triplanarTexture, texture, objectPosition, viewportTopLeft, viewportLinearDepth, viewportDepthTexture, viewportSharedTexture, mx_worley_noise_float, positionWorld, timerLocal } from 'three/tsl';
import { color, vec2, pass, linearDepth, normalWorld, triplanarTexture, texture, objectPosition, viewportUV, viewportLinearDepth, viewportDepthTexture, viewportSharedTexture, mx_worley_noise_float, positionWorld, timerLocal } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand Down Expand Up @@ -148,14 +148,14 @@
const depthWater = viewportLinearDepth.sub( depth );
const depthEffect = depthWater.remapClamp( - .002, .04 );

const refractionUV = viewportTopLeft.add( vec2( 0, waterIntensity.mul( .1 ) ) );
const refractionUV = viewportUV.add( vec2( 0, waterIntensity.mul( .1 ) ) );

// linearDepth( viewportDepthTexture( uv ) ) return the linear depth of the scene
const depthTestForRefraction = linearDepth( viewportDepthTexture( refractionUV ) ).sub( depth );

const depthRefraction = depthTestForRefraction.remapClamp( 0, .1 );

const finalUV = depthTestForRefraction.lessThan( 0 ).select( viewportTopLeft, refractionUV );
const finalUV = depthTestForRefraction.lessThan( 0 ).select( viewportUV, refractionUV );

const viewportTexture = viewportSharedTexture( finalUV );

Expand Down Expand Up @@ -226,7 +226,7 @@
const scenePassColorBlurred = scenePassColor.gaussianBlur();
scenePassColorBlurred.directionNode = waterMask.select( scenePassDepth, scenePass.getLinearDepthNode().mul( 5 ) );

const vignet = viewportTopLeft.distance( .5 ).mul( 1.35 ).clamp().oneMinus();
const vignet = viewportUV.distance( .5 ).mul( 1.35 ).clamp().oneMinus();

postProcessing = new THREE.PostProcessing( renderer );
postProcessing.outputNode = waterMask.select( scenePassColorBlurred, scenePassColorBlurred.mul( color( 0x74ccf4 ) ).mul( vignet ) );
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_compute_audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<script type="module">

import * as THREE from 'three';
import { Fn, uniform, storage, storageObject, instanceIndex, float, texture, viewportTopLeft, color } from 'three/tsl';
import { Fn, uniform, storage, storageObject, instanceIndex, float, texture, viewportUV, color } from 'three/tsl';

import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

Expand Down Expand Up @@ -170,7 +170,7 @@

analyserTexture = new THREE.DataTexture( analyserBuffer, analyserBuffer.length, 1, THREE.RedFormat );

const spectrum = texture( analyserTexture, viewportTopLeft.x ).x.mul( viewportTopLeft.y );
const spectrum = texture( analyserTexture, viewportUV.x ).x.mul( viewportUV.y );
const backgroundNode = color( 0x0000FF ).mul( spectrum );


Expand Down
6 changes: 3 additions & 3 deletions examples/webgpu_compute_particles_snow.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { Fn, texture, vec3, pass, color, uint, viewportTopLeft, positionWorld, positionLocal, timerLocal, vec2, instanceIndex, storage, If } from 'three/tsl';
import { Fn, texture, vec3, pass, color, uint, viewportUV, positionWorld, positionLocal, timerLocal, vec2, instanceIndex, storage, If } from 'three/tsl';

import { TeapotGeometry } from 'three/addons/geometries/TeapotGeometry.js';

Expand Down Expand Up @@ -261,7 +261,7 @@

//

scene.backgroundNode = viewportTopLeft.distance( .5 ).mul( 2 ).mix( color( 0x0f4140 ), color( 0x060a0d ) );
scene.backgroundNode = viewportUV.distance( .5 ).mul( 2 ).mix( color( 0x0f4140 ), color( 0x060a0d ) );

//

Expand Down Expand Up @@ -295,7 +295,7 @@

const scenePass = pass( scene, camera );
const scenePassColor = scenePass.getTextureNode();
const vignet = viewportTopLeft.distance( .5 ).mul( 1.35 ).clamp().oneMinus();
const vignet = viewportUV.distance( .5 ).mul( 1.35 ).clamp().oneMinus();

const teapotTreePass = pass( teapotTree, camera ).getTextureNode();
const teapotTreePassBlurred = teapotTreePass.gaussianBlur( vec2( 1 ), 3 );
Expand Down
10 changes: 5 additions & 5 deletions examples/webgpu_mrt.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script type="module">

import * as THREE from 'three';
import { output, transformedNormalWorld, pass, step, diffuseColor, emissive, viewportTopLeft, mix, mrt, Fn } from 'three/tsl';
import { output, transformedNormalWorld, pass, step, diffuseColor, emissive, viewportUV, mix, mrt, Fn } from 'three/tsl';

import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';

Expand Down Expand Up @@ -108,10 +108,10 @@
const diffuse = scenePass.getTextureNode( 'diffuse' );
const emissive = scenePass.getTextureNode( 'emissive' );

const out = mix( output.renderOutput(), output, step( 0.2, viewportTopLeft.x ) );
const nor = mix( out, normal, step( 0.4, viewportTopLeft.x ) );
const emi = mix( nor, emissive, step( 0.6, viewportTopLeft.x ) );
const dif = mix( emi, diffuse, step( 0.8, viewportTopLeft.x ) );
const out = mix( output.renderOutput(), output, step( 0.2, viewportUV.x ) );
const nor = mix( out, normal, step( 0.4, viewportUV.x ) );
const emi = mix( nor, emissive, step( 0.6, viewportUV.x ) );
const dif = mix( emi, diffuse, step( 0.8, viewportUV.x ) );

return dif;

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_mrt_mask.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<script type="module">

import * as THREE from 'three';
import { color, viewportTopLeft, mrt, output, pass, vec4 } from 'three/tsl';
import { color, viewportUV, mrt, output, pass, vec4 } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand All @@ -45,7 +45,7 @@
camera.position.set( 1, 2, 3 );

scene = new THREE.Scene();
scene.backgroundNode = viewportTopLeft.y.mix( color( 0x66bbff ), color( 0x4466ff ) ).mul( .05 );
scene.backgroundNode = viewportUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) ).mul( .05 );
camera.lookAt( 0, 1, 0 );

clock = new THREE.Clock();
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_multiple_rendertargets.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { mix, vec2, step, texture, uv, viewportTopLeft, normalWorld, output, mrt } from 'three/tsl';
import { mix, vec2, step, texture, uv, viewportUV, normalWorld, output, mrt } from 'three/tsl';

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

Expand Down Expand Up @@ -86,7 +86,7 @@
// Post Processing

postProcessing = new THREE.PostProcessing( renderer );
postProcessing.outputNode = mix( texture( renderTarget.textures[ 0 ] ), texture( renderTarget.textures[ 1 ] ), step( 0.5, viewportTopLeft.x ) );
postProcessing.outputNode = mix( texture( renderTarget.textures[ 0 ] ), texture( renderTarget.textures[ 1 ] ), step( 0.5, viewportUV.x ) );

// Controls

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_multiple_rendertargets_readback.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { mix, step, texture, viewportTopLeft, mrt, output, transformedNormalWorld, uv, vec2 } from 'three/tsl';
import { mix, step, texture, viewportUV, mrt, output, transformedNormalWorld, uv, vec2 } from 'three/tsl';

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

Expand Down Expand Up @@ -111,7 +111,7 @@
// Output

material = new THREE.NodeMaterial();
material.colorNode = mix( texture( renderTarget.textures[ 0 ] ), texture( renderTarget.textures[ 1 ] ), step( 0.5, viewportTopLeft.x ) );
material.colorNode = mix( texture( renderTarget.textures[ 0 ] ), texture( renderTarget.textures[ 1 ] ), step( 0.5, viewportUV.x ) );

quadMesh = new THREE.QuadMesh( material );

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_portal.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { pass, color, mx_worley_noise_float, timerLocal, viewportTopLeft, vec2, uv, normalWorld, mx_fractal_noise_vec3 } from 'three/tsl';
import { pass, color, mx_worley_noise_float, timerLocal, viewportUV, vec2, uv, normalWorld, mx_fractal_noise_vec3 } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand Down Expand Up @@ -128,7 +128,7 @@
const geometry = new THREE.PlaneGeometry( 1.7, 2 );

const material = new THREE.MeshBasicNodeMaterial();
material.colorNode = pass( scenePortal, camera ).context( { getUV: () => viewportTopLeft } );
material.colorNode = pass( scenePortal, camera ).context( { getUV: () => viewportUV } );
material.opacityNode = uv().distance( .5 ).remapClamp( .3, .5 ).oneMinus();
material.side = THREE.DoubleSide;
material.transparent = true;
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_postprocessing_anamorphic.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<script type="module">

import * as THREE from 'three';
import { pass, cubeTexture, viewportTopLeft, uniform } from 'three/tsl';
import { pass, cubeTexture, viewportUV, uniform } from 'three/tsl';

import { RGBMLoader } from 'three/addons/loaders/RGBMLoader.js';

Expand Down Expand Up @@ -58,7 +58,7 @@
.loadCubemapAsync( rgbmUrls );

scene.environment = cube1Texture;
scene.backgroundNode = cubeTexture( cube1Texture ).mul( viewportTopLeft.distance( .5 ).oneMinus().remapClamp( .1, 4 ) ).saturation( 0 );
scene.backgroundNode = cubeTexture( cube1Texture ).mul( viewportUV.distance( .5 ).oneMinus().remapClamp( .1, 4 ) ).saturation( 0 );

const loader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
loader.load( 'DamagedHelmet.gltf', function ( gltf ) {
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_postprocessing_motion_blur.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { pass, texture, motionBlur, uniform, output, mrt, mix, velocity, uv, viewportTopLeft } from 'three/tsl';
import { pass, texture, motionBlur, uniform, output, mrt, mix, velocity, uv, viewportUV } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand Down Expand Up @@ -188,7 +188,7 @@

const mBlur = motionBlur( beauty, vel );

const vignet = viewportTopLeft.distance( .5 ).remap( .6, 1 ).mul( 2 ).clamp().oneMinus();
const vignet = viewportUV.distance( .5 ).remap( .6, 1 ).mul( 2 ).clamp().oneMinus();

postProcessing = new THREE.PostProcessing( renderer );
postProcessing.outputNode = mix( mBlur, vel, showVelocity ).mul( vignet );
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_reflection.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { color, pass, reflector, normalWorld, texture, uv, viewportTopLeft } from 'three/tsl';
import { color, pass, reflector, normalWorld, texture, uv, viewportUV } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand Down Expand Up @@ -151,7 +151,7 @@
const scenePassColorBlurred = scenePassColor.gaussianBlur();
scenePassColorBlurred.directionNode = scenePassDepth;

const vignet = viewportTopLeft.distance( .5 ).mul( 1.35 ).clamp().oneMinus();
const vignet = viewportUV.distance( .5 ).mul( 1.35 ).clamp().oneMinus();

postProcessing = new THREE.PostProcessing( renderer );
postProcessing.outputNode = scenePassColorBlurred.mul( vignet );
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_refraction.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { viewportSafeUV, viewportSharedTexture, viewportTopLeft, texture, uv } from 'three/tsl';
import { viewportSafeUV, viewportSharedTexture, viewportUV, texture, uv } from 'three/tsl';

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

Expand Down Expand Up @@ -66,7 +66,7 @@
const verticalNormalScale = 0.1;
const verticalUVOffset = texture( floorNormal, uv().mul( 5 ) ).xy.mul( 2 ).sub( 1 ).mul( verticalNormalScale );

const refractorUV = viewportTopLeft.add( verticalUVOffset );
const refractorUV = viewportUV.add( verticalUVOffset );
const verticalRefractor = viewportSharedTexture( viewportSafeUV( refractorUV ) );

const planeGeo = new THREE.PlaneGeometry( 100.1, 100.1 );
Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_skinning.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script type="module">

import * as THREE from 'three';
import { color, viewportTopLeft } from 'three/tsl';
import { color, viewportUV } from 'three/tsl';

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

Expand All @@ -41,7 +41,7 @@
camera.position.set( 1, 2, 3 );

scene = new THREE.Scene();
scene.backgroundNode = viewportTopLeft.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
scene.backgroundNode = viewportUV.y.mix( color( 0x66bbff ), color( 0x4466ff ) );
camera.lookAt( 0, 1, 0 );

clock = new THREE.Clock();
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export { default as FrontFacingNode, frontFacing, faceDirection } from './displa
export { default as NormalMapNode, normalMap } from './display/NormalMapNode.js';
export { default as PosterizeNode, posterize } from './display/PosterizeNode.js';
export { default as ToneMappingNode, toneMapping } from './display/ToneMappingNode.js';
export { default as ViewportNode, viewport, viewportCoordinate, viewportResolution, viewportTopLeft, viewportBottomLeft, viewportTopRight, viewportBottomRight } from './display/ViewportNode.js';
export { default as ViewportNode, viewport, viewportCoordinate, viewportResolution, viewportUV, viewportTopLeft } from './display/ViewportNode.js';
export { default as ViewportTextureNode, viewportTexture, viewportMipTexture } from './display/ViewportTextureNode.js';
export { default as ViewportSharedTextureNode, viewportSharedTexture } from './display/ViewportSharedTextureNode.js';
export { default as ViewportDepthTextureNode, viewportDepthTexture } from './display/ViewportDepthTextureNode.js';
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/display/ViewportDepthTextureNode.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ViewportTextureNode from './ViewportTextureNode.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
import { viewportTopLeft } from './ViewportNode.js';
import { viewportUV } from './ViewportNode.js';

import { DepthTexture } from '../../textures/DepthTexture.js';

let sharedDepthbuffer = null;

class ViewportDepthTextureNode extends ViewportTextureNode {

constructor( uvNode = viewportTopLeft, levelNode = null ) {
constructor( uvNode = viewportUV, levelNode = null ) {

if ( sharedDepthbuffer === null ) {

Expand Down
Loading

0 comments on commit f22b8b0

Please sign in to comment.