|
@@ -3,7 +3,6 @@ import {
|
|
|
Color,
|
|
|
CustomBlending,
|
|
|
DataTexture,
|
|
|
- DepthStencilFormat,
|
|
|
DepthTexture,
|
|
|
DstAlphaFactor,
|
|
|
DstColorFactor,
|
|
@@ -16,19 +15,18 @@ import {
|
|
|
ShaderMaterial,
|
|
|
UniformsUtils,
|
|
|
UnsignedByteType,
|
|
|
- UnsignedInt248Type,
|
|
|
WebGLRenderTarget,
|
|
|
ZeroFactor
|
|
|
} from 'three';
|
|
|
import { Pass, FullScreenQuad } from './Pass.js';
|
|
|
-import { generateHaboSampleKernelInitializer, HBAOShader, HBAODepthShader } from '../shaders/HBAOShader.js';
|
|
|
+import { generateMagicSquareNoise, GTAOShader, GTAODepthShader, GTAOBlendShader } from '../shaders/GTAOShader.js';
|
|
|
import { generatePdSamplePointInitializer, PoissonDenoiseShader } from '../shaders/PoissonDenoiseShader.js';
|
|
|
import { CopyShader } from '../shaders/CopyShader.js';
|
|
|
import { SimplexNoise } from '../math/SimplexNoise.js';
|
|
|
|
|
|
-class HBAOPass extends Pass {
|
|
|
+class GTAOPass extends Pass {
|
|
|
|
|
|
- constructor( scene, camera, width, height, parameters ) {
|
|
|
+ constructor( scene, camera, width, height, parameters, aoParameters, pdParameters ) {
|
|
|
|
|
|
super();
|
|
|
|
|
@@ -40,32 +38,32 @@ class HBAOPass extends Pass {
|
|
|
this.output = 0;
|
|
|
this._renderGBuffer = true;
|
|
|
this._visibilityCache = new Map();
|
|
|
+ this.blendIntensity = 1.;
|
|
|
|
|
|
- this.rings = 4;
|
|
|
- this.samples = 16;
|
|
|
+ this.pdRings = 2.;
|
|
|
+ this.pdRadiusExponent = 2.;
|
|
|
+ this.pdSamples = 16;
|
|
|
|
|
|
- this.noiseTexture = this.generateNoise();
|
|
|
+ this.gtaoNoiseTexture = generateMagicSquareNoise();
|
|
|
+ this.pdNoiseTexture = this.generateNoise();
|
|
|
|
|
|
- this.hbaoRenderTarget = new WebGLRenderTarget( this.width, this.height, { type: HalfFloatType } );
|
|
|
- this.pdRenderTarget = this.hbaoRenderTarget.clone();
|
|
|
+ this.gtaoRenderTarget = new WebGLRenderTarget( this.width, this.height, { type: HalfFloatType } );
|
|
|
+ this.pdRenderTarget = this.gtaoRenderTarget.clone();
|
|
|
|
|
|
- this.hbaoMaterial = new ShaderMaterial( {
|
|
|
- defines: Object.assign( {}, HBAOShader.defines ),
|
|
|
- uniforms: UniformsUtils.clone( HBAOShader.uniforms ),
|
|
|
- vertexShader: HBAOShader.vertexShader,
|
|
|
- fragmentShader: HBAOShader.fragmentShader,
|
|
|
+ this.gtaoMaterial = new ShaderMaterial( {
|
|
|
+ defines: Object.assign( {}, GTAOShader.defines ),
|
|
|
+ uniforms: UniformsUtils.clone( GTAOShader.uniforms ),
|
|
|
+ vertexShader: GTAOShader.vertexShader,
|
|
|
+ fragmentShader: GTAOShader.fragmentShader,
|
|
|
blending: NoBlending,
|
|
|
depthTest: false,
|
|
|
depthWrite: false,
|
|
|
} );
|
|
|
- this.hbaoMaterial.defines[ 'PERSPECTIVE_CAMERA' ] = this.camera.isPerspectiveCamera ? 1 : 0;
|
|
|
- this.hbaoMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
|
|
|
- this.hbaoMaterial.uniforms[ 'resolution' ].value.set( this.width, this.height );
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
|
- this.hbaoMaterial.uniforms[ 'radius' ].value = 2;
|
|
|
- this.hbaoMaterial.uniforms[ 'distanceExponent' ].value = 2;
|
|
|
- this.hbaoMaterial.uniforms[ 'bias' ].value = 0.01;
|
|
|
+ this.gtaoMaterial.definesPERSPECTIVE_CAMERA = this.camera.isPerspectiveCamera ? 1 : 0;
|
|
|
+ this.gtaoMaterial.uniforms.tNoise.value = this.gtaoNoiseTexture;
|
|
|
+ this.gtaoMaterial.uniforms.resolution.value.set( this.width, this.height );
|
|
|
+ this.gtaoMaterial.uniforms.cameraNear.value = this.camera.near;
|
|
|
+ this.gtaoMaterial.uniforms.cameraFar.value = this.camera.far;
|
|
|
|
|
|
this.normalMaterial = new MeshNormalMaterial();
|
|
|
this.normalMaterial.blending = NoBlending;
|
|
@@ -78,22 +76,23 @@ class HBAOPass extends Pass {
|
|
|
depthTest: false,
|
|
|
depthWrite: false,
|
|
|
} );
|
|
|
- this.pdMaterial.uniforms[ 'tDiffuse' ].value = this.hbaoRenderTarget.texture;
|
|
|
- this.pdMaterial.uniforms[ 'tNoise' ].value = this.noiseTexture;
|
|
|
- this.pdMaterial.uniforms[ 'resolution' ].value.set( this.width, this.height );
|
|
|
- this.pdMaterial.uniforms[ 'lumaPhi' ].value = 10;
|
|
|
- this.pdMaterial.uniforms[ 'depthPhi' ].value = 2;
|
|
|
- this.pdMaterial.uniforms[ 'normalPhi' ].value = 3;
|
|
|
+ this.pdMaterial.uniforms.tDiffuse.value = this.gtaoRenderTarget.texture;
|
|
|
+ this.pdMaterial.uniforms.tNoise.value = this.pdNoiseTexture;
|
|
|
+ this.pdMaterial.uniforms.resolution.value.set( this.width, this.height );
|
|
|
+ this.pdMaterial.uniforms.lumaPhi.value = 10;
|
|
|
+ this.pdMaterial.uniforms.depthPhi.value = 2;
|
|
|
+ this.pdMaterial.uniforms.normalPhi.value = 3;
|
|
|
+ this.pdMaterial.uniforms.radius.value = 8;
|
|
|
|
|
|
this.depthRenderMaterial = new ShaderMaterial( {
|
|
|
- defines: Object.assign( {}, HBAODepthShader.defines ),
|
|
|
- uniforms: UniformsUtils.clone( HBAODepthShader.uniforms ),
|
|
|
- vertexShader: HBAODepthShader.vertexShader,
|
|
|
- fragmentShader: HBAODepthShader.fragmentShader,
|
|
|
+ defines: Object.assign( {}, GTAODepthShader.defines ),
|
|
|
+ uniforms: UniformsUtils.clone( GTAODepthShader.uniforms ),
|
|
|
+ vertexShader: GTAODepthShader.vertexShader,
|
|
|
+ fragmentShader: GTAODepthShader.fragmentShader,
|
|
|
blending: NoBlending
|
|
|
} );
|
|
|
- this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
|
- this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
|
+ this.depthRenderMaterial.uniforms.cameraNear.value = this.camera.near;
|
|
|
+ this.depthRenderMaterial.uniforms.cameraFar.value = this.camera.far;
|
|
|
|
|
|
this.copyMaterial = new ShaderMaterial( {
|
|
|
uniforms: UniformsUtils.clone( CopyShader.uniforms ),
|
|
@@ -110,19 +109,48 @@ class HBAOPass extends Pass {
|
|
|
blendEquationAlpha: AddEquation
|
|
|
} );
|
|
|
|
|
|
+ this.blendMaterial = new ShaderMaterial( {
|
|
|
+ uniforms: UniformsUtils.clone( GTAOBlendShader.uniforms ),
|
|
|
+ vertexShader: GTAOBlendShader.vertexShader,
|
|
|
+ fragmentShader: GTAOBlendShader.fragmentShader,
|
|
|
+ transparent: true,
|
|
|
+ depthTest: false,
|
|
|
+ depthWrite: false,
|
|
|
+ blending: CustomBlending,
|
|
|
+ blendSrc: DstColorFactor,
|
|
|
+ blendDst: ZeroFactor,
|
|
|
+ blendEquation: AddEquation,
|
|
|
+ blendSrcAlpha: DstAlphaFactor,
|
|
|
+ blendDstAlpha: ZeroFactor,
|
|
|
+ blendEquationAlpha: AddEquation
|
|
|
+ } );
|
|
|
+
|
|
|
this.fsQuad = new FullScreenQuad( null );
|
|
|
|
|
|
this.originalClearColor = new Color();
|
|
|
|
|
|
- this.setTextures( parameters ? parameters.depthTexture : undefined, parameters ? parameters.normalTexture : undefined );
|
|
|
+ this.setGBuffer( parameters ? parameters.depthTexture : undefined, parameters ? parameters.normalTexture : undefined );
|
|
|
+
|
|
|
+ if ( aoParameters !== undefined ) {
|
|
|
+
|
|
|
+ this.updateGtaoMaterial( aoParameters );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( pdParameters !== undefined ) {
|
|
|
+
|
|
|
+ this.updatePdMaterial( pdParameters );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
dispose() {
|
|
|
|
|
|
- this.noiseTexture.dispose();
|
|
|
+ this.gtaoNoiseTexture.dispose();
|
|
|
+ this.pdNoiseTexture.dispose();
|
|
|
this.normalRenderTarget.dispose();
|
|
|
- this.hbaoRenderTarget.dispose();
|
|
|
+ this.gtaoRenderTarget.dispose();
|
|
|
this.pdRenderTarget.dispose();
|
|
|
this.normalMaterial.dispose();
|
|
|
this.pdMaterial.dispose();
|
|
@@ -132,7 +160,7 @@ class HBAOPass extends Pass {
|
|
|
|
|
|
}
|
|
|
|
|
|
- setTextures( depthTexture, normalTexture ) {
|
|
|
+ setGBuffer( depthTexture, normalTexture ) {
|
|
|
|
|
|
if ( depthTexture !== undefined ) {
|
|
|
|
|
@@ -143,9 +171,6 @@ class HBAOPass extends Pass {
|
|
|
} else {
|
|
|
|
|
|
this.depthTexture = new DepthTexture();
|
|
|
- this.depthTexture.format = DepthStencilFormat;
|
|
|
- this.depthTexture.type = UnsignedInt248Type;
|
|
|
-
|
|
|
this.normalRenderTarget = new WebGLRenderTarget( this.width, this.height, {
|
|
|
minFilter: NearestFilter,
|
|
|
magFilter: NearestFilter,
|
|
@@ -158,47 +183,83 @@ class HBAOPass extends Pass {
|
|
|
}
|
|
|
|
|
|
const normalVectorType = ( this.normalTexture ) ? 1 : 0;
|
|
|
- const depthValueSource = ( this.depthTexture === this.normalTexture ) ? 1 : 0;
|
|
|
+ const depthValueSource = ( this.depthTexture === this.normalTexture ) ? 'w' : 'x';
|
|
|
|
|
|
- this.hbaoMaterial.defines[ 'NORMAL_VECTOR_TYPE' ] = normalVectorType;
|
|
|
- this.hbaoMaterial.defines[ 'DEPTH_VALUE_SOURCE' ] = depthValueSource;
|
|
|
- this.hbaoMaterial.uniforms[ 'tNormal' ].value = this.normalTexture;
|
|
|
- this.hbaoMaterial.uniforms[ 'tDepth' ].value = this.depthTexture;
|
|
|
+ this.gtaoMaterial.defines.NORMAL_VECTOR_TYPE = normalVectorType;
|
|
|
+ this.gtaoMaterial.defines.DEPTH_SWIZZLING = depthValueSource;
|
|
|
+ this.gtaoMaterial.uniforms.tNormal.value = this.normalTexture;
|
|
|
+ this.gtaoMaterial.uniforms.tDepth.value = this.depthTexture;
|
|
|
|
|
|
- this.pdMaterial.defines[ 'NORMAL_VECTOR_TYPE' ] = normalVectorType;
|
|
|
- this.pdMaterial.defines[ 'DEPTH_VALUE_SOURCE' ] = depthValueSource;
|
|
|
- this.pdMaterial.uniforms[ 'tNormal' ].value = this.normalTexture;
|
|
|
- this.pdMaterial.uniforms[ 'tDepth' ].value = this.depthTexture;
|
|
|
+ this.pdMaterial.defines.NORMAL_VECTOR_TYPE = normalVectorType;
|
|
|
+ this.pdMaterial.defines.DEPTH_SWIZZLING = depthValueSource;
|
|
|
+ this.pdMaterial.uniforms.tNormal.value = this.normalTexture;
|
|
|
+ this.pdMaterial.uniforms.tDepth.value = this.depthTexture;
|
|
|
|
|
|
- this.depthRenderMaterial.uniforms[ 'tDepth' ].value = this.normalRenderTarget.depthTexture;
|
|
|
+ this.depthRenderMaterial.uniforms.tDepth.value = this.normalRenderTarget.depthTexture;
|
|
|
|
|
|
}
|
|
|
|
|
|
- updateHbaoMaterial( parameters ) {
|
|
|
+ setSceneClipBox( box ) {
|
|
|
+
|
|
|
+ if ( box ) {
|
|
|
+
|
|
|
+ this.gtaoMaterial.needsUpdate = this.gtaoMaterial.defines.SCENE_CLIP_BOX !== 1;
|
|
|
+ this.gtaoMaterial.defines.SCENE_CLIP_BOX = 1;
|
|
|
+ this.gtaoMaterial.uniforms.sceneBoxMin.value.copy( box.min );
|
|
|
+ this.gtaoMaterial.uniforms.sceneBoxMax.value.copy( box.max );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ this.gtaoMaterial.needsUpdate = this.gtaoMaterial.defines.SCENE_CLIP_BOX === 0;
|
|
|
+ this.gtaoMaterial.defines.SCENE_CLIP_BOX = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ updateGtaoMaterial( parameters ) {
|
|
|
|
|
|
if ( parameters.radius !== undefined ) {
|
|
|
|
|
|
- this.hbaoMaterial.uniforms[ 'radius' ].value = parameters.radius;
|
|
|
+ this.gtaoMaterial.uniforms.radius.value = parameters.radius;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( parameters.distanceExponent !== undefined ) {
|
|
|
|
|
|
- this.hbaoMaterial.uniforms[ 'distanceExponent' ].value = parameters.distanceExponent;
|
|
|
+ this.gtaoMaterial.uniforms.distanceExponent.value = parameters.distanceExponent;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( parameters.thickness !== undefined ) {
|
|
|
+
|
|
|
+ this.gtaoMaterial.uniforms.thickness.value = parameters.thickness;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( parameters.bias !== undefined ) {
|
|
|
|
|
|
- this.hbaoMaterial.uniforms[ 'bias' ].value = parameters.bias;
|
|
|
+ this.gtaoMaterial.uniforms.bias.value = parameters.bias;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( parameters.scale !== undefined ) {
|
|
|
+
|
|
|
+ this.gtaoMaterial.uniforms.scale.value = parameters.scale;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( parameters.samples !== undefined && parameters.samples !== this.hbaoMaterial.defines[ 'SAMPLES' ] ) {
|
|
|
+ if ( parameters.samples !== undefined && parameters.samples !== this.gtaoMaterial.defines.SAMPLES ) {
|
|
|
|
|
|
- this.hbaoMaterial.defines[ 'SAMPLES' ] = parameters.samples;
|
|
|
- this.hbaoMaterial.defines[ 'SAMPLE_VECTORS' ] = generateHaboSampleKernelInitializer( parameters.samples );
|
|
|
- this.hbaoMaterial.needsUpdate = true;
|
|
|
+ this.gtaoMaterial.defines.SAMPLES = parameters.samples;
|
|
|
+ this.gtaoMaterial.needsUpdate = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( parameters.screenSpaceRadius !== undefined && ( parameters.screenSpaceRadius ? 1 : 0 ) !== this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS ) {
|
|
|
+
|
|
|
+ this.gtaoMaterial.defines.SCREEN_SPACE_RADIUS = parameters.screenSpaceRadius ? 1 : 0;
|
|
|
+ this.gtaoMaterial.needsUpdate = true;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -210,47 +271,53 @@ class HBAOPass extends Pass {
|
|
|
|
|
|
if ( parameters.lumaPhi !== undefined ) {
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'lumaPhi' ].value = parameters.lumaPhi;
|
|
|
+ this.pdMaterial.uniforms.lumaPhi.value = parameters.lumaPhi;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( parameters.depthPhi !== undefined ) {
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'depthPhi' ].value = parameters.depthPhi;
|
|
|
+ this.pdMaterial.uniforms.depthPhi.value = parameters.depthPhi;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( parameters.normalPhi !== undefined ) {
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'normalPhi' ].value = parameters.normalPhi;
|
|
|
+ this.pdMaterial.uniforms.normalPhi.value = parameters.normalPhi;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ( parameters.radius !== undefined && parameters.radius !== this.radius ) {
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'radius' ].value = parameters.radius;
|
|
|
+ this.pdMaterial.uniforms.radius.value = parameters.radius;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( parameters.rings !== undefined && parameters.rings !== this.rings ) {
|
|
|
+ if ( parameters.radiusExponent !== undefined && parameters.radiusExponent !== this.pdRadiusExponent ) {
|
|
|
|
|
|
- this.rings = parameters.rings;
|
|
|
+ this.pdRadiusExponent = parameters.radiusExponent;
|
|
|
updateShader = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( parameters.samples !== undefined && parameters.samples !== this.samples ) {
|
|
|
+ if ( parameters.rings !== undefined && parameters.rings !== this.pdRings ) {
|
|
|
|
|
|
- this.samples = parameters.samples;
|
|
|
+ this.pdRings = parameters.rings;
|
|
|
updateShader = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
- if ( updateShader ) {
|
|
|
+ if ( parameters.samples !== undefined && parameters.samples !== this.pdSamples ) {
|
|
|
+
|
|
|
+ this.pdSamples = parameters.samples;
|
|
|
+ updateShader = true;
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( updateShader ) {
|
|
|
|
|
|
- this.pdMaterial.defines[ 'SAMPLES' ] = parameters.samples;
|
|
|
- this.pdMaterial.defines[ 'SAMPLE_VECTORS' ] = generatePdSamplePointInitializer( parameters.samples, this.rings );
|
|
|
+ this.pdMaterial.defines.SAMPLES = this.pdSamples;
|
|
|
+ this.pdMaterial.defines.SAMPLE_VECTORS = generatePdSamplePointInitializer( this.pdSamples, this.pdRings, this.pdRadiusExponent );
|
|
|
this.pdMaterial.needsUpdate = true;
|
|
|
|
|
|
}
|
|
@@ -259,7 +326,7 @@ class HBAOPass extends Pass {
|
|
|
|
|
|
render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
|
|
|
|
|
|
- // render normals and depth (honor only meshes, points and lines do not contribute to HBAO)
|
|
|
+ // render normals and depth (honor only meshes, points and lines do not contribute to AO)
|
|
|
|
|
|
if ( this._renderGBuffer ) {
|
|
|
|
|
@@ -269,77 +336,78 @@ class HBAOPass extends Pass {
|
|
|
|
|
|
}
|
|
|
|
|
|
- // render HBAO
|
|
|
+ // render AO
|
|
|
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraProjectionMatrix' ].value.copy( this.camera.projectionMatrix );
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraProjectionMatrixInverse' ].value.copy( this.camera.projectionMatrixInverse );
|
|
|
- this.renderPass( renderer, this.hbaoMaterial, this.hbaoRenderTarget, 0xffffff, 1.0 );
|
|
|
+ this.gtaoMaterial.uniforms.cameraNear.value = this.camera.near;
|
|
|
+ this.gtaoMaterial.uniforms.cameraFar.value = this.camera.far;
|
|
|
+ this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy( this.camera.projectionMatrix );
|
|
|
+ this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
|
+ this.gtaoMaterial.uniforms.cameraWorldMatrix.value.copy( this.camera.matrixWorld );
|
|
|
+ this.renderPass( renderer, this.gtaoMaterial, this.gtaoRenderTarget, 0xffffff, 1.0 );
|
|
|
|
|
|
// render poisson denoise
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'cameraProjectionMatrixInverse' ].value.copy( this.camera.projectionMatrixInverse );
|
|
|
+ this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
|
this.renderPass( renderer, this.pdMaterial, this.pdRenderTarget, 0xffffff, 1.0 );
|
|
|
|
|
|
// output result to screen
|
|
|
|
|
|
switch ( this.output ) {
|
|
|
|
|
|
- case HBAOPass.OUTPUT.Diffuse:
|
|
|
+ case GTAOPass.OUTPUT.Diffuse:
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
|
|
|
+ this.copyMaterial.uniforms.tDiffuse.value = readBuffer.texture;
|
|
|
this.copyMaterial.blending = NoBlending;
|
|
|
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case HBAOPass.OUTPUT.HBAO:
|
|
|
+ case GTAOPass.OUTPUT.AO:
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = this.hbaoRenderTarget.texture;
|
|
|
+ this.copyMaterial.uniforms.tDiffuse.value = this.gtaoRenderTarget.texture;
|
|
|
this.copyMaterial.blending = NoBlending;
|
|
|
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case HBAOPass.OUTPUT.Denoise:
|
|
|
+ case GTAOPass.OUTPUT.Denoise:
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = this.pdRenderTarget.texture;
|
|
|
+ this.copyMaterial.uniforms.tDiffuse.value = this.pdRenderTarget.texture;
|
|
|
this.copyMaterial.blending = NoBlending;
|
|
|
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case HBAOPass.OUTPUT.Depth:
|
|
|
+ case GTAOPass.OUTPUT.Depth:
|
|
|
|
|
|
- this.depthRenderMaterial.uniforms[ 'cameraNear' ].value = this.camera.near;
|
|
|
- this.depthRenderMaterial.uniforms[ 'cameraFar' ].value = this.camera.far;
|
|
|
+ this.depthRenderMaterial.uniforms.cameraNear.value = this.camera.near;
|
|
|
+ this.depthRenderMaterial.uniforms.cameraFar.value = this.camera.far;
|
|
|
this.renderPass( renderer, this.depthRenderMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case HBAOPass.OUTPUT.Normal:
|
|
|
+ case GTAOPass.OUTPUT.Normal:
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = this.normalRenderTarget.texture;
|
|
|
+ this.copyMaterial.uniforms.tDiffuse.value = this.normalRenderTarget.texture;
|
|
|
this.copyMaterial.blending = NoBlending;
|
|
|
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
- case HBAOPass.OUTPUT.Default:
|
|
|
+ case GTAOPass.OUTPUT.Default:
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = readBuffer.texture;
|
|
|
+ this.copyMaterial.uniforms.tDiffuse.value = readBuffer.texture;
|
|
|
this.copyMaterial.blending = NoBlending;
|
|
|
this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
- this.copyMaterial.uniforms[ 'tDiffuse' ].value = this.pdRenderTarget.texture;
|
|
|
- this.copyMaterial.blending = CustomBlending;
|
|
|
- this.renderPass( renderer, this.copyMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
+ this.blendMaterial.uniforms.intensity.value = this.blendIntensity;
|
|
|
+ this.blendMaterial.uniforms.tDiffuse.value = this.pdRenderTarget.texture;
|
|
|
+ this.renderPass( renderer, this.blendMaterial, this.renderToScreen ? null : writeBuffer );
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
- console.warn( 'THREE.HBAOPass: Unknown output type.' );
|
|
|
+ console.warn( 'THREE.GTAOPass: Unknown output type.' );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -398,8 +466,6 @@ class HBAOPass extends Pass {
|
|
|
renderer.render( this.scene, this.camera );
|
|
|
this.scene.overrideMaterial = null;
|
|
|
|
|
|
- // restore original state
|
|
|
-
|
|
|
renderer.autoClear = originalAutoClear;
|
|
|
renderer.setClearColor( this.originalClearColor );
|
|
|
renderer.setClearAlpha( originalClearAlpha );
|
|
@@ -411,16 +477,16 @@ class HBAOPass extends Pass {
|
|
|
this.width = width;
|
|
|
this.height = height;
|
|
|
|
|
|
- this.hbaoRenderTarget.setSize( width, height );
|
|
|
+ this.gtaoRenderTarget.setSize( width, height );
|
|
|
this.normalRenderTarget.setSize( width, height );
|
|
|
this.pdRenderTarget.setSize( width, height );
|
|
|
|
|
|
- this.hbaoMaterial.uniforms[ 'resolution' ].value.set( width, height );
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraProjectionMatrix' ].value.copy( this.camera.projectionMatrix );
|
|
|
- this.hbaoMaterial.uniforms[ 'cameraProjectionMatrixInverse' ].value.copy( this.camera.projectionMatrixInverse );
|
|
|
+ this.gtaoMaterial.uniforms.resolution.value.set( width, height );
|
|
|
+ this.gtaoMaterial.uniforms.cameraProjectionMatrix.value.copy( this.camera.projectionMatrix );
|
|
|
+ this.gtaoMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
|
|
|
|
- this.pdMaterial.uniforms[ 'resolution' ].value.set( width, height );
|
|
|
- this.pdMaterial.uniforms[ 'cameraProjectionMatrixInverse' ].value.copy( this.camera.projectionMatrixInverse );
|
|
|
+ this.pdMaterial.uniforms.resolution.value.set( width, height );
|
|
|
+ this.pdMaterial.uniforms.cameraProjectionMatrixInverse.value.copy( this.camera.projectionMatrixInverse );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -469,10 +535,10 @@ class HBAOPass extends Pass {
|
|
|
const x = i;
|
|
|
const y = j;
|
|
|
|
|
|
- data[ ( i * size + j ) * 4 ] = ( simplex.noise( x, y ) + 1.0 ) * 255.0;
|
|
|
- data[ ( i * size + j ) * 4 + 1 ] = ( simplex.noise( x + size, y ) + 1.0 ) * 255.0;
|
|
|
- data[ ( i * size + j ) * 4 + 2 ] = ( simplex.noise( x, y + size ) + 1.0 ) * 255.0;
|
|
|
- data[ ( i * size + j ) * 4 + 3 ] = ( simplex.noise( x + size, y + size ) + 1.0 ) * 255.0;
|
|
|
+ data[ ( i * size + j ) * 4 ] = ( simplex.noise( x, y ) * 0.5 + 0.5 ) * 255;
|
|
|
+ data[ ( i * size + j ) * 4 + 1 ] = ( simplex.noise( x + size, y ) * 0.5 + 0.5 ) * 255;
|
|
|
+ data[ ( i * size + j ) * 4 + 2 ] = ( simplex.noise( x, y + size ) * 0.5 + 0.5 ) * 255;
|
|
|
+ data[ ( i * size + j ) * 4 + 3 ] = ( simplex.noise( x + size, y + size ) * 0.5 + 0.5 ) * 255;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -489,13 +555,13 @@ class HBAOPass extends Pass {
|
|
|
|
|
|
}
|
|
|
|
|
|
-HBAOPass.OUTPUT = {
|
|
|
+GTAOPass.OUTPUT = {
|
|
|
'Default': 0,
|
|
|
'Diffuse': 1,
|
|
|
'Depth': 2,
|
|
|
'Normal': 3,
|
|
|
- 'HBAO': 4,
|
|
|
+ 'AO': 4,
|
|
|
'Denoise': 5,
|
|
|
};
|
|
|
|
|
|
-export { HBAOPass };
|
|
|
+export { GTAOPass };
|