Rendering pass: Single geometry to texture

Hi guys,



I have been working on a post processing filter for the last few days, but there is one crucial aspect that I haven’t managed to solve. The first pass of the filter would simply render a single geometry to a separate framebuffer ( to be used by the next passes ), the next passes then perform some blur and other operations. I have gotten the whole filter working, but only when rendering the whole scene to my first buffer, so my question is:



How do I make a pass that only renders a single geometry to it’s framebuffer? (To be used by subsequent passes)



Note: I made most of my filter by reverse engineering the bloom filter and it’s shaders, so that is a good reference for me. Passing framebuffers between passes is not a problem.



I made this attempt setting up the initial render pass:

[java]

@Override

protected void postQueue(RenderManager renderManager, ViewPort viewPort) {

backupColor = viewPort.getBackgroundColor();

viewPort.setBackgroundColor( ColorRGBA.Black );



// Render to a frame buffer:

renderManager.getRenderer().setFrameBuffer( this.extractPass.getRenderFrameBuffer() );

renderManager.getRenderer().clearBuffers( true, true, true );



// Render the target(s):

if( selection == null ){

// Renders the whole scene:

renderManager.renderViewPortQueues( viewPort, false );

} else {

// Renders only a single geometry:

renderManager.renderGeometry( selection );

}



// Undo changes:

viewPort.setBackgroundColor( backupColor );

renderManager.getRenderer().setFrameBuffer( viewPort.getOutputFrameBuffer() );

}

[/java]



This is my actual extraction pass:

[java]

extractMat = new Material( manager, “MatDefs/Post/ExtractGeometry.j3md” );

extractPass = new Pass() {



@Override

public boolean requiresSceneAsTexture() {

return true;

}



@Override

public void beforeRender() {

}

};

extractPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, extractMat);

postRenderPasses.add( extractPass );



[/java]



This does not work however, actually java seem to just stall, no stack trace, nothing.

Just a note, I did a similar thing earlier, making a Screen processor that would render a selected geometrys’ wireframe:

[java]

public void postQueue( RenderQueue rq ) {

if( selection != null ){



// Swap rendering mode:

Mesh mesh = this.selection.getMesh();

Mesh.Mode mode = mesh.getMode();

float width = mesh.getLineWidth();

mesh.setLineWidth( 5 );

selection.getMesh().setMode( Mesh.Mode.Lines );

// selection.



// Render the material:

renderManager.setForcedMaterial( this.wireMaterial );

renderManager.renderGeometry( selection );

renderManager.setForcedMaterial( null );



// Revert rendering mode:

selection.getMesh().setMode( mode );



}

// renderManager.setForcedMaterial( wireMaterial );

}

[/java]



This rendered the single geometry without problem… See here ( The torus is currently the selected geometry, but I can switch back and forth realtime ):

http://i.imgur.com/Q7Qo5.png

you attempt looks good to me, what do you mean by “stall” you mean it stops?

did you try to run it in debug mode and see what happens?

Hi,



The stall has stopped and it is rendering the scene. When I leave postQueue empty it correctly applies the filter to the whole scene, but if I leave my code there the filter is empty for the whole scene and noisy for the geometry. :confused:



Is there a way to initialize a pass and specify what should be rendered?

[java]

extractPass.init(renderManager.getRenderer(), screenWidth, screenHeight, Format.RGBA8, Format.Depth, 1, extractMat);

[/java]

A way to specify that this pass only applies to a single node?

Okay, so I got it working now, but I cannot quite explain why it is working…



Why does this work:

[java]

@Override

protected void postQueue(RenderManager renderManager, ViewPort viewPort) {

// Render to a frame buffer:

renderManager.getRenderer().setFrameBuffer(this.extractPass.getRenderFrameBuffer());

renderManager.getRenderer().clearBuffers(true, true, true);



// Renders only one selection:

if (selection != null ) {

renderManager.renderGeometry(selection);

}



// Undo changes:

renderManager.setForcedTechnique(null);

renderManager.getRenderer().setFrameBuffer(viewPort.getOutputFrameBuffer());

}

[/java]



When this completely cancels out the post processing filter:

[java]

@Override

protected void postQueue(RenderManager renderManager, ViewPort viewPort) {

backupColor = viewPort.getBackgroundColor();

viewPort.setBackgroundColor( ColorRGBA.Black );



// Render to a frame buffer:

renderManager.getRenderer().setFrameBuffer( this.extractPass.getRenderFrameBuffer() );

renderManager.getRenderer().clearBuffers( true, true, true );



// Render the target(s):

if( selection != null ){

// Renders only a single geometry:

renderManager.renderGeometry( selection );

}



// Undo changes:

viewPort.setBackgroundColor( backupColor );

renderManager.getRenderer().setFrameBuffer( viewPort.getOutputFrameBuffer() );

}

[/java]



As you can see the only difference is swapping around background colors…

I can’t tell really.



you don’t need this btw

[java]

renderManager.setForcedTechnique(null);

[/java]

Yes, I realized that. It’s a bit of clutter left behind by all the semi-random testing I resorted to to fix this… :S



Thank you for having a look. :slight_smile:

//Are you sure there are not any other changes outside of that function that have been made as well?