I’m trying to apply a GTAO pass on my three js scene but nothing seems to happen when I add it.
And even when I try to change the value.
I have use this example : three.js examples
And here is my code :
textureLoader = new THREE.TextureLoader();
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
// document.body.appendChild( renderer.domElement );
// use ref as a mount point of the Three.js scene instead of the document.body
refContainer.current && refContainer.current.appendChild( renderer.domElement );
const pmremGenerator = new THREE.PMREMGenerator( renderer );
scene = new THREE.Scene();
scene.environment = pmremGenerator.fromScene( new RoomEnvironment( renderer ), 0.04 ).texture;
const camera = new THREE.PerspectiveCamera( 22, window.innerWidth / window.innerHeight, 0.1, 20 );
camera.position.set( 3.62, 2.734, 3.408 );
const controls = new OrbitControls( camera, renderer.domElement );
controls.target.set( 0, 0, 0 );
controls.update();
controls.enablePan = false;
controls.enableDamping = true;
controls.maxPolarAngle = Math.PI;
controls.minDistance = 1;
controls.maxDistance = 5;
const dirLight1 = new THREE.DirectionalLight( 0xffddcc, 3 );
dirLight1.position.set( 1, 0.75, 0.5 );
scene.add( dirLight1 );
const dirLight2 = new THREE.DirectionalLight( 0xccccff, 3 );
dirLight2.position.set( - 1, 0.75, - 0.5 );
scene.add( dirLight2 );
const pointLight = new THREE.PointLight( 0xff0000, Math.PI, 100, 0 );
pointLight.position.set( -10, -10, -1 );
scene.add( pointLight );
const ambientLight = new THREE.AmbientLight( 0xff0000, 1 );
scene.add( ambientLight );
const spotLight = new THREE.SpotLight( 0xff0000, Math.PI, 0, 0.15, 1, 0 );
spotLight.position.set( 10, 10, 10 );
scene.add( spotLight );
// add ambiant occlusion effect
// based on this : https://threejs.org/examples/?q=ambient#webgl_postprocessing_gtao
let composer = new EffectComposer( renderer );
const width = window.innerWidth;
const height = window.innerHeight;
const gtaoPass = new GTAOPass( scene, camera, width, height );
gtaoPass.output = GTAOPass.OUTPUT.Denoise;
composer.addPass( gtaoPass );
// Init gui
const gui = new GUI();
gui.add( gtaoPass, 'output', {
'Default': GTAOPass.OUTPUT.Default,
'Diffuse': GTAOPass.OUTPUT.Diffuse,
'AO Only': GTAOPass.OUTPUT.AO,
'AO Only + Denoise': GTAOPass.OUTPUT.Denoise,
'Depth': GTAOPass.OUTPUT.Depth,
'Normal': GTAOPass.OUTPUT.Normal
} ).onChange( function ( value ) {
console.log("ON CHANGE")
console.log("change gtaoPass: " + value)
gtaoPass.output = value;
} );
const aoParameters = {
radius: 0.25,
distanceExponent: 1.,
thickness: 1.,
scale: 1.,
samples: 16,
distanceFallOff: 1.,
screenSpaceRadius: false,
};
const pdParameters = {
lumaPhi: 10.,
depthPhi: 2.,
normalPhi: 3.,
radius: 0.,
radiusExponent: 1.,
rings: 2.,
samples: 16,
};
gtaoPass.updateGtaoMaterial( aoParameters );
gtaoPass.updatePdMaterial( pdParameters );
gui.add( gtaoPass, 'blendIntensity' ).min( 0 ).max( 1 ).step( 0.01 );
gui.add( aoParameters, 'radius' ).min( 0.01 ).max( 1 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'distanceExponent' ).min( 1 ).max( 4 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'thickness' ).min( 0.01 ).max( 10 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'distanceFallOff' ).min( 0 ).max( 1 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'scale' ).min( 0.01 ).max( 2.0 ).step( 0.01 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( aoParameters, 'screenSpaceRadius' ).onChange( () => gtaoPass.updateGtaoMaterial( aoParameters ) );
gui.add( pdParameters, 'lumaPhi' ).min( 0 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'depthPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'normalPhi' ).min( 0.01 ).max( 20 ).step( 0.01 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'radius' ).min( 0 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'radiusExponent' ).min( 0.1 ).max( 4. ).step( 0.1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'rings' ).min( 1 ).max( 16 ).step( 0.125 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
gui.add( pdParameters, 'samples' ).min( 2 ).max( 32 ).step( 1 ).onChange( () => gtaoPass.updatePdMaterial( pdParameters ) );
window.addEventListener( 'resize', onWindowResize );
const loader = new GLTFLoader();
loader.load( 'pahtTo3DModel.glb', function ( gltf ) {
const box = new THREE.Box3().setFromObject( scene );
gtaoPass.setSceneClipBox( box );
}
I wonder where is the issue, is it caused by the lighting of the scene, is it caused by the material used on the object ?
Someone can give me a clue please ?
Thanks in advance