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

Chaining Effect Composers in THREEjs r60 is destroying the buffer from the first Composer - Volumetric Light #4682

Closed
bbiswas opened this issue Apr 15, 2014 · 3 comments

Comments

@bbiswas
Copy link

bbiswas commented Apr 15, 2014

I'm porting BkCore's Volumetric light example to THREE r60.
Here are the steps-
1.building the main scene,
2.cloning the main scene as the occlusion scene,
3. do a few shader passes on the occlusion scene - (i.e. the godray pass ) - Effect Composer #1
4. pass the result of the godray pass as a texture to an additive blend shader that will finally blend in the godray pass with the render pass for the main scene. - Effect Composer #2

Using two effect composers to retain depth buffers. When I render the final scene, only the main scene is rendered and the results of the godray pass from Effect Composer #1 just does not show up.

If I save the EC#1 results into a texture and add it to the main scene, then I can see it. That's not the effect I want but it means EC#1 is working.

If I move my additive blend shader inside EC#1, I see the godrays. Which means the passing of the rendertarget1 from EC#1 as texture into the additive shader is also working.

It's only when I use a separate Effect Composer for the main scene, that the results of the previous composer gets lost.

I've tried with renderer.PreserveDrawingBuffer = true but that didn't work. I've tried setting autoclear to false but that wasn't it.

If I render EC#1 after EC#2 turning the godray shader's output-to-screen to true, then I can see the godrays but no models and vice versa if I swap it other way.

Looks like maybe the framebuffer is getting detroyed?

Kinda out of ideas...
Thanks!

// COMPOSERS
//-------------------
var renderTargetParameters = { minFilter: THREE.LinearFilter, magFilter: THREE.LinearFilter, format: THREE.RGBAFormat, stencilBufer: false };

renderTargetOcl = new THREE.WebGLRenderTarget( SCREEN_WIDTH/2, SCREEN_HEIGHT/2, renderTargetParameters );

hblur = new THREE.ShaderPass( THREE.ShaderExtras[ "horizontalBlur" ] );
vblur = new THREE.ShaderPass( THREE.ShaderExtras[ "verticalBlur" ] );
var bluriness = 2;

hblur.uniforms[ 'h' ].value = bluriness / SCREEN_WIDTH*2;
vblur.uniforms[ 'v' ].value = bluriness / SCREEN_HEIGHT*2;

var renderModel = new THREE.RenderPass( scene, camera );
var renderModelOcl = new THREE.RenderPass( oclscene, oclcamera );

grPass = new THREE.ShaderPass( THREE.Extras.Shaders.Godrays );
grPass.needsSwap = true;
grPass.renderToScreen = false;

oclcomposer = new THREE.EffectComposer( renderer, renderTargetOcl );

oclcomposer.addPass( renderModelOcl );
oclcomposer.addPass( hblur );
oclcomposer.addPass( vblur );
oclcomposer.addPass( grPass );

var finalPass = new THREE.ShaderPass( THREE.Extras.Shaders.Additive );
finalPass.needsSwap = true;
finalPass.renderToScreen = true;
finalPass.uniforms[ 'tAdd' ].texture = oclcomposer.renderTarget1;

renderTarget = new THREE.WebGLRenderTarget( SCREEN_WIDTH, SCREEN_HEIGHT, renderTargetParameters );
finalcomposer = new THREE.EffectComposer( renderer, renderTarget );

finalcomposer.addPass( renderModel );
finalcomposer.addPass( finalPass );

//RENDER
//-----------
oclcomposer.render(0.1);
finalcomposer.render( 0.1 );


//ADDITIVE SHADER
    Additive: {
        uniforms: {
            tDiffuse: { type: "t", value: 0, texture: null },
            tAdd: { type: "t", value: 1, texture: null },
            fCoeff: { type: "f", value: 1.0 }
        },

        vertexShader: [
            "varying vec2 vUv;",

            "void main() {",

                "vUv = uv;",
                "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",

            "}"
        ].join("\n"),

        fragmentShader: [
            "uniform sampler2D tDiffuse;",
            "uniform sampler2D tAdd;",
            "uniform float fCoeff;",

            "varying vec2 vUv;",

            "void main() {",

                "vec4 texel = texture2D( tDiffuse, vUv );",
                "vec4 add = texture2D( tAdd, vUv );",
                "gl_FragColor = texel + add * fCoeff;",

            "}"
        ].join("\n")
    }
@bbiswas bbiswas changed the title Chaining Effect Composers in THREEjs seems to destroy the framebuffer Chaining Effect Composers in THREEjs r60 is destroying the buffer from the first Composer - Volumetric Light Apr 15, 2014
@kumavis
Copy link
Contributor

kumavis commented Apr 15, 2014

Please wrap your code example in triple backticks for readibility (formatting guide)

@bbiswas
Copy link
Author

bbiswas commented Apr 15, 2014

Thanks for that Kumavis...this is my first post here. Appreciate the link to the guide.

@bbiswas
Copy link
Author

bbiswas commented Apr 16, 2014

Figured it out - It works now

finalPass.uniforms[ 'tAdd' ].texture = oclcomposer.renderTarget1;

needed to be

finalPass.uniforms[ 'tAdd' ].value = oclcomposer.renderTarget1;

@bbiswas bbiswas closed this as completed Apr 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants