Skip to content
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

Node: Add FilmNode. #28770

Merged
merged 9 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
38 changes: 14 additions & 24 deletions examples/misc_controls_fly.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<script type="importmap">
{
"imports": {
"three": "../build/three.module.js",
"three": "../build/three.webgpu.js",
"three/tsl": "../build/three.webgpu.js",
"three/addons/": "./jsm/"
}
}
Expand All @@ -39,14 +40,10 @@
<script type="module">

import * as THREE from 'three';
import { pass } from 'three/tsl';

import Stats from 'three/addons/libs/stats.module.js';

import { FlyControls } from 'three/addons/controls/FlyControls.js';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { FilmPass } from 'three/addons/postprocessing/FilmPass.js';
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';

const radius = 6371;
const tilt = 0.41;
Expand All @@ -63,7 +60,7 @@
let geometry, meshPlanet, meshClouds, meshMoon;
let dirLight;

let composer;
let postProcessing;

const textureLoader = new THREE.TextureLoader();

Expand Down Expand Up @@ -173,17 +170,14 @@
starsGeometry[ 1 ].setAttribute( 'position', new THREE.Float32BufferAttribute( vertices2, 3 ) );

const starsMaterials = [
new THREE.PointsMaterial( { color: 0x9c9c9c, size: 2, sizeAttenuation: false } ),
new THREE.PointsMaterial( { color: 0x9c9c9c, size: 1, sizeAttenuation: false } ),
new THREE.PointsMaterial( { color: 0x7c7c7c, size: 2, sizeAttenuation: false } ),
new THREE.PointsMaterial( { color: 0x838383, size: 1, sizeAttenuation: false } ),
new THREE.PointsMaterial( { color: 0x5a5a5a, size: 2, sizeAttenuation: false } ),
new THREE.PointsMaterial( { color: 0x5a5a5a, size: 1, sizeAttenuation: false } )
new THREE.PointsMaterial( { color: 0x9c9c9c } ),
new THREE.PointsMaterial( { color: 0x838383 } ),
new THREE.PointsMaterial( { color: 0x5a5a5a } )
];

for ( let i = 10; i < 30; i ++ ) {

const stars = new THREE.Points( starsGeometry[ i % 2 ], starsMaterials[ i % 6 ] );
const stars = new THREE.Points( starsGeometry[ i % 2 ], starsMaterials[ i % 3 ] );

stars.rotation.x = Math.random() * 6;
stars.rotation.y = Math.random() * 6;
Expand All @@ -197,7 +191,7 @@

}

renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
renderer.setAnimationLoop( animate );
Expand All @@ -222,15 +216,12 @@

// postprocessing

const renderModel = new RenderPass( scene, camera );
const effectFilm = new FilmPass( 0.35 );
const outputPass = new OutputPass();
postProcessing = new THREE.PostProcessing( renderer );

composer = new EffectComposer( renderer );
const scenePass = pass( scene, camera );
const scenePassColor = scenePass.getTextureNode();

composer.addPass( renderModel );
composer.addPass( effectFilm );
composer.addPass( outputPass );
postProcessing.outputNode = scenePassColor.film();

}

Expand All @@ -243,7 +234,6 @@
camera.updateProjectionMatrix();

renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
composer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );

}

Expand Down Expand Up @@ -283,7 +273,7 @@
controls.movementSpeed = 0.33 * d;
controls.update( delta );

composer.render( delta );
postProcessing.render();

}

Expand Down
Binary file modified examples/screenshots/misc_controls_fly.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export { default as SobelOperatorNode, sobel } from './display/SobelOperatorNode
export { default as DepthOfFieldNode, dof } from './display/DepthOfFieldNode.js';
export { default as DotScreenNode, dotScreen } from './display/DotScreenNode.js';
export { default as RGBShiftNode, rgbShift } from './display/RGBShiftNode.js';
export { default as FilmNode, film } from './display/FilmNode.js';

export { default as PassNode, pass, texturePass, depthPass } from './display/PassNode.js';

Expand Down
60 changes: 60 additions & 0 deletions src/nodes/display/FilmNode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import TempNode from '../core/TempNode.js';
import { uv } from '../accessors/UVNode.js';
import { luminance } from './ColorAdjustmentNode.js';
import { addNodeElement, tslFn, nodeObject, vec3, vec4 } from '../shadernode/ShaderNode.js';
import { uniform } from '../core/UniformNode.js';
import { mix, fract, clamp, rand } from '../math/MathNode.js';
import { timerLocal } from '../utils/TimerNode.js';

class FilmNode extends TempNode {

constructor( textureNode, intensity = 0.5, grayscale = false ) {

super();

this.textureNode = textureNode;
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved

this.intensityNode = uniform( intensity );
this.grayscale = grayscale;

}

setup() {

const { textureNode } = this;

const uvNode = textureNode.uvNode || uv();

const film = tslFn( () => {

const base = textureNode;

const noise = rand( fract( uvNode.add( timerLocal() ) ) );

let color = base.rgb.add( base.rgb.mul( clamp( noise.add( 0.1 ), 0, 1 ) ) );

color = mix( base.rgb, color, this.intensityNode );

if ( this.grayscale === true ) {

color = vec3( luminance( color ) ); // assuming linear-srgb

}

return vec4( color, base.a );

} );

const outputNode = film();

return outputNode;

}

}

export const film = ( node, intensity, grayscale ) => nodeObject( new FilmNode( nodeObject( node ), intensity, grayscale ) );

addNodeElement( 'film', film );

export default FilmNode;
1 change: 1 addition & 0 deletions test/e2e/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const exceptionList = [
'webgpu_performance_renderbundle',
'webgpu_lights_rectarealight',
'webgpu_postprocessing',
'misc_controls_fly',

// WebGPU idleTime and parseTime too low
'webgpu_compute_particles',
Expand Down