提交 b051d7e1 编写于 作者: A alteredq

WebGLDeferredRenderer: added API for injecting postprocessing effects into...

WebGLDeferredRenderer: added API for injecting postprocessing effects into deferred rendering pipeline.
上级 4a976331
...@@ -47,6 +47,12 @@ THREE.EffectComposer.prototype = { ...@@ -47,6 +47,12 @@ THREE.EffectComposer.prototype = {
}, },
insertPass: function ( pass, index ) {
this.passes.splice( index, 0, pass );
},
render: function ( delta ) { render: function ( delta ) {
this.writeBuffer = this.renderTarget1; this.writeBuffer = this.renderTarget1;
......
...@@ -205,7 +205,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -205,7 +205,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
uniforms.viewWidth.value = scaledWidth; uniforms.viewWidth.value = scaledWidth;
uniforms.viewHeight.value = scaledHeight; uniforms.viewHeight.value = scaledHeight;
resizableMaterials.push( material ); resizableMaterials.push( { "material": material } );
} }
...@@ -402,7 +402,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -402,7 +402,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
// sync proxy uniforms to the original light // sync proxy uniforms to the original light
...@@ -478,7 +478,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -478,7 +478,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
// sync proxy uniforms to the original light // sync proxy uniforms to the original light
...@@ -544,7 +544,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -544,7 +544,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
// sync proxy uniforms to the original light // sync proxy uniforms to the original light
...@@ -610,7 +610,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -610,7 +610,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
// sync proxy uniforms to the original light // sync proxy uniforms to the original light
...@@ -698,7 +698,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -698,7 +698,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
// sync proxy uniforms to the original light // sync proxy uniforms to the original light
...@@ -734,7 +734,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -734,7 +734,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
// keep reference for size reset // keep reference for size reset
resizableMaterials.push( materialLight ); resizableMaterials.push( { "material": materialLight } );
return meshLight; return meshLight;
...@@ -849,6 +849,25 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -849,6 +849,25 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
}; };
this.addEffect = function ( effect, normalDepthUniform, colorUniform ) {
if ( effect.material && effect.uniforms ) {
if ( normalDepthUniform ) effect.uniforms[ normalDepthUniform ].value = compNormalDepth.renderTarget2;
if ( colorUniform ) effect.uniforms[ colorUniform ].value = compColor.renderTarget2;
if ( normalDepthUniform || colorUniform ) {
resizableMaterials.push( { "material": effect.material, "normalDepth": normalDepthUniform, "color": colorUniform } );
}
}
compFinal.insertPass( effect, -1 );
};
this.setScale = function ( scale ) { this.setScale = function ( scale ) {
currentScale = scale; currentScale = scale;
...@@ -866,13 +885,19 @@ THREE.WebGLDeferredRenderer = function ( parameters ) { ...@@ -866,13 +885,19 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
for ( var i = 0, il = resizableMaterials.length; i < il; i ++ ) { for ( var i = 0, il = resizableMaterials.length; i < il; i ++ ) {
var uniforms = resizableMaterials[ i ].uniforms; var materialEntry = resizableMaterials[ i ];
var material = materialEntry.material;
var uniforms = material.uniforms;
var colorLabel = materialEntry.color !== undefined ? materialEntry.color : 'samplerColor';
var normalDepthLabel = materialEntry.normalDepth !== undefined ? materialEntry.normalDepth : 'samplerNormalDepth';
uniforms[ "viewWidth" ].value = scaledWidth; if ( uniforms[ colorLabel ] ) uniforms[ colorLabel ].value = compColor.renderTarget2;
uniforms[ "viewHeight" ].value = scaledHeight; if ( uniforms[ normalDepthLabel ] ) uniforms[ normalDepthLabel ].value = compNormalDepth.renderTarget2;
if ( uniforms[ 'samplerColor' ] ) uniforms[ 'samplerColor' ].value = compColor.renderTarget2; if ( uniforms[ 'viewWidth' ] ) uniforms[ "viewWidth" ].value = scaledWidth;
if ( uniforms[ 'samplerNormalDepth' ] ) uniforms[ 'samplerNormalDepth' ].value = compNormalDepth.renderTarget2; if ( uniforms[ 'viewHeight' ] ) uniforms[ "viewHeight" ].value = scaledHeight;
} }
......
...@@ -54,11 +54,13 @@ ...@@ -54,11 +54,13 @@
<script src="js/shaders/CopyShader.js"></script> <script src="js/shaders/CopyShader.js"></script>
<script src="js/shaders/FXAAShader.js"></script> <script src="js/shaders/FXAAShader.js"></script>
<script src="js/shaders/ConvolutionShader.js"></script>
<script src="js/postprocessing/EffectComposer.js"></script> <script src="js/postprocessing/EffectComposer.js"></script>
<script src="js/postprocessing/RenderPass.js"></script> <script src="js/postprocessing/RenderPass.js"></script>
<script src="js/postprocessing/ShaderPass.js"></script> <script src="js/postprocessing/ShaderPass.js"></script>
<script src="js/postprocessing/MaskPass.js"></script> <script src="js/postprocessing/MaskPass.js"></script>
<script src="js/postprocessing/BloomPass.js"></script>
<script> <script>
...@@ -114,6 +116,11 @@ ...@@ -114,6 +116,11 @@
var container = document.getElementById( 'container' ); var container = document.getElementById( 'container' );
container.appendChild( renderer.domElement ); container.appendChild( renderer.domElement );
// effects
var bloomEffect = new THREE.BloomPass( 0.75 );
renderer.addEffect( bloomEffect );
// camera // camera
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR ); camera = new THREE.PerspectiveCamera( VIEW_ANGLE, WIDTH / HEIGHT, NEAR, FAR );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册