-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TSL: parallaxUV
#27739
Merged
Merged
TSL: parallaxUV
#27739
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5146695
BlendModeNode: Add layout and fix if used with textures
sunag ae3c188
TSL: Add parallaxUV
sunag aacaba3
Examples: Add `webgpu_parallax_uv`
sunag 1d577a8
Merge branch 'dev' into dev-parallax-uv
sunag 3b57fa0
update
sunag bd5ad3d
cleanup
sunag 69a1f70
Automatic compute tangents if needed
sunag c44c283
use default TBNViewMatrix
sunag 38f57a6
Rename parallaxDelta -> parallaxDirection
sunag fb7b510
Reg optional overlay using mix()
sunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>three.js webgpu - parallax uv</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> | ||
<link type="text/css" rel="stylesheet" href="main.css"> | ||
</head> | ||
<body> | ||
|
||
<div id="info"> | ||
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> webgpu - parallax uv<br /> | ||
Textures by <a href="https://ambientcg.com/view?id=Ice002" target="_blank" rel="noopener">ambientCG</a><br /> | ||
|
||
</div> | ||
|
||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"three": "../build/three.module.js", | ||
"three/addons/": "./jsm/", | ||
"three/nodes": "./jsm/nodes/Nodes.js" | ||
} | ||
} | ||
</script> | ||
|
||
<script type="module"> | ||
|
||
import * as THREE from 'three'; | ||
import { MeshStandardNodeMaterial, texture, parallaxUV, uv } from 'three/nodes'; | ||
|
||
import WebGPURenderer from 'three/addons/renderers/webgpu/WebGPURenderer.js'; | ||
|
||
import { OrbitControls } from 'three/addons/controls/OrbitControls.js'; | ||
|
||
let camera, scene, renderer; | ||
|
||
let controls; | ||
|
||
init(); | ||
|
||
function init() { | ||
|
||
// scene | ||
|
||
scene = new THREE.Scene(); | ||
|
||
// camera | ||
|
||
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, .1, 50 ); | ||
camera.position.set( 10, 14, 10 ); | ||
|
||
// environment | ||
|
||
const environmentTexture = new THREE.CubeTextureLoader() | ||
.setPath( './textures/cube/Park2/' ) | ||
.load( [ 'posx.jpg', 'negx.jpg', 'posy.jpg', 'negy.jpg', 'posz.jpg', 'negz.jpg' ] ); | ||
|
||
|
||
scene.environment = environmentTexture; | ||
scene.background = environmentTexture; | ||
|
||
// textures | ||
|
||
const loader = new THREE.TextureLoader(); | ||
|
||
const topTexture = loader.load( 'textures/ambientcg/Ice002_1K-JPG_Color.jpg' ); | ||
topTexture.colorSpace = THREE.SRGBColorSpace; | ||
|
||
const roughnessTexture = loader.load( 'textures/ambientcg/Ice002_1K-JPG_Roughness.jpg' ); | ||
roughnessTexture.colorSpace = THREE.SRGBColorSpace; | ||
|
||
const normalTexture = loader.load( 'textures/ambientcg/Ice002_1K-JPG_NormalGL.jpg' ); | ||
normalTexture.colorSpace = THREE.NoColorSpace; | ||
|
||
const displaceTexture = loader.load( 'textures/ambientcg/Ice002_1K-JPG_Displacement.jpg' ); | ||
displaceTexture.colorSpace = THREE.SRGBColorSpace; | ||
|
||
// | ||
|
||
const bottomTexture = loader.load( 'textures/ambientcg/Ice003_1K-JPG_Color.jpg' ); | ||
bottomTexture.colorSpace = THREE.SRGBColorSpace; | ||
bottomTexture.wrapS = THREE.RepeatWrapping; | ||
bottomTexture.wrapT = THREE.RepeatWrapping; | ||
|
||
// paralax effect | ||
|
||
const parallaxScale = .3; | ||
const offsetUV = texture( displaceTexture ).mul( parallaxScale ); | ||
|
||
const parallaxUVOffset = parallaxUV( uv(), offsetUV ); | ||
const parallaxResult = texture( bottomTexture, parallaxUVOffset ); | ||
|
||
const iceNode = texture( topTexture ).overlay( parallaxResult ); | ||
|
||
// material | ||
|
||
const material = new MeshStandardNodeMaterial(); | ||
material.colorNode = iceNode.mul( 5 ); // increase the color intensity to 5 ( contrast ) | ||
material.roughnessNode = texture( roughnessTexture ); | ||
material.normalMap = normalTexture; | ||
material.metalness = 0; | ||
|
||
const geometry = new THREE.BoxGeometry( 10, 10, 10 ); | ||
|
||
const ground = new THREE.Mesh( geometry, material ); | ||
ground.rotateX( - Math.PI / 2 ); | ||
scene.add( ground ); | ||
|
||
// renderer | ||
|
||
renderer = new WebGPURenderer( { antialias: true } ); | ||
renderer.setPixelRatio( window.devicePixelRatio ); | ||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
renderer.setAnimationLoop( animate ); | ||
renderer.toneMapping = THREE.ReinhardToneMapping; | ||
renderer.toneMappingExposure = 6; | ||
document.body.appendChild( renderer.domElement ); | ||
|
||
// controls | ||
|
||
controls = new OrbitControls( camera, renderer.domElement ); | ||
controls.target.set( 0, 0, 0 ); | ||
controls.maxDistance = 40; | ||
controls.minDistance = 10; | ||
controls.autoRotate = true; | ||
controls.autoRotateSpeed = - 1; | ||
controls.update(); | ||
|
||
window.addEventListener( 'resize', onWindowResize ); | ||
|
||
} | ||
|
||
function onWindowResize() { | ||
|
||
camera.aspect = window.innerWidth / window.innerHeight; | ||
camera.updateProjectionMatrix(); | ||
|
||
renderer.setSize( window.innerWidth, window.innerHeight ); | ||
|
||
} | ||
|
||
function animate() { | ||
|
||
controls.update(); | ||
|
||
renderer.render( scene, camera ); | ||
|
||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
roughness
anddisplacement
should beNoColorSpace
.And likewise, the normal texture, but its color profile is
sRGB
. Regardless, I'd leave it asNoColorSpace
./ping @donmccurdy for second opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we should use
NoColorSpace
for all textures containing non-color data, including all three here. The color profiles tend to be unreliable, and I'm not sure there's any way to tag an image clearly identifying it as non-color data. If the material looks incorrect when non-color textures are annotated withNoColorSpace
, then we would need fix the textures.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opened PR: