Objects multiple worlds?

Started by lawless_c, October 12, 2015, 06:06:29 PM

Previous topic - Next topic

lawless_c

Is it possible to add the same instances of an Object3d to many worlds?

Would there be disposal or other issues?

I'm thinking of creating a another World object in which objects are added and the results are used to create a glowing effect.

If i could get these objects in the other world instance to use a different shader that would be even better. Maybe if i used the render-hook to switch them.
I could then use some combination of additive blending to overlay the result on the frame-buffer.

lawless_c

Actually I may be able to do both in one world instance :-)

EgonOlsen

Quote from: lawless_c on October 12, 2015, 06:06:29 PM
Is it possible to add the same instances of an Object3d to many worlds?
No, that's not possible, I'm afraid.

lawless_c

Does this sound reasonable?

1. I do a glow render, ie all objects are either strongly coloured if glowing or completely black
2.This render is sent to a texture an object3d is using.(can we change textures on an object for each render?)
3.This object3d has a renderhook/shader attached so it covers whole screen, and applies a blur (fullscreen quad)
4.We render again but this time to the frame-buffer.

I'm going to try out and will let you know if it works.

EgonOlsen

Yes, you can change textures on each render. But I'm not sure why you want to for a glow effect... ???

The rest of the process sounds reasonable. Instead of blurring actively by a shader, you could render into a low-res texture and let the bilinear filtering do the blurring.

lawless_c

Quote from: EgonOlsen on October 13, 2015, 08:52:25 AM
But I'm not sure why you want to for a glow effect... ???

If it works i may be able to use if for other kinds of effects or post processing.

If im sending framebuffer data to the texture instead will it be automatically updated for Object3d's using that texture? I.E the next time they're drawn they'll use it?

I'm not entirely clear on guaranteeing a texture is updated/changed.


EgonOlsen

Yes. If you render into a texture, this happens on the GPU. There's no need to set it again or anything.
Just make sure that you are using OpenGL ES 2.0 mode for this. Render to texture on 1.x suffers some buggy drivers. Also keep in mind that the rendered image will usually be upside-down.

lawless_c

Sorry to bother you again but should what would be the best way to implement/update this?

I mean creating a texture that is linked to an object3d that gets updated.

At the moment i have the frame buffer setRenderTarget    to a texture which i have set as a texture for an object3d , but that texture is just looking black.
It doesn't seem to update as it should.

EgonOlsen

That's actually the way to do it. Are you using OpenGL ES 2.0?

lawless_c

yeah. I briefly got some weird effects , on the texture , will keep fiddling with it.

EgonOlsen

Are you rendering the object with the target texture in the same frame in which you render into the target? If so, try not to do that and see if that works. Having a texture bound while rendering that is actually the target of the rendering itself won't work.

lawless_c

My code for it

toProcess is  the texture object

theRenderspot is the object3d

public void doPostProcess(FrameBuffer fb) {

        switchToGlowRender = true;

        fb.setRenderTarget(toProcess);
        world.renderScene(fb);
        world.draw(fb);
        fb.display();

       // tm.
        fb.removeRenderTarget();

        tm.replaceTexture("postprocess", toProcess);
       // theRenderspot.setTexture("postprocess");


        switchToGlowRender = false;

    }



Checked the config at the start so im definitely using opengl es 2.0

EgonOlsen

As said, tm.replaceTexture("postprocess", toProcess); isn't needed. But you can't use the render target as a texture in the same frame that will be rendered into the target.

lawless_c

#13
 8) Got it, might need some adjustments but it sorta works.

 





Heres the code for it, i've commented out the parts related to an Object3d and my attempts to use shaders as a post processing effect(naming convention is a mess too).
when "switchToGlowRender" is  set to 'true' some Objects will be rendered completely black via their glsl fragment shaders, Others will be properly rendered.
In the case of the Aura effect im attempting it's only rendered during the glow render.




public class GlowProcessHandler {

    public NPOTTexture toProcess;
    World world;
    public Boolean switchToGlowRender = false;
    //Object3D theRenderspot = null;

   // GLSLShader renderShader = null;
  //  PostProcessingRenderHook renderHook = null;
    TextureManager tm = TextureManager.getInstance();
    int divRatio;


    public GlowProcessHandler(World world, Resources res, FrameBuffer bf) {

       // this.theRenderspot = Primitives.getPlane(6, 8);
        divRatio=32;


      //  renderShader = new GLSLShader(Loader.loadTextFile(res.openRawResource(R.raw.postprocess_vert)),
       //         Loader.loadTextFile(res.openRawResource(R.raw.postprocess_frag)));


        this.world = world;

        toProcess = new NPOTTexture(bf.getWidth()/divRatio , bf.getHeight()/divRatio, RGBColor.BLACK);
        toProcess.setFiltering(true);
        toProcess.setMipmap(false);
        tm.addTexture("postprocess", toProcess);
       // theRenderspot.setTexture("postprocess");


        //theRenderspot.setTransparency(3);
        //theRenderspot.setCulling(false);


        //renderHook = new PostProcessingRenderHook(theRenderspot, renderShader);
        //renderHook.setCurrentShader(renderShader);


//        theRenderspot.setOrigin(new SimpleVector(10, 0, 0));
//        theRenderspot.setShader(renderShader);
//        theRenderspot.setRenderHook(renderHook);

    }


    public void doPostProcess(FrameBuffer fb) {
        switchToGlowRender = true;

        fb.setRenderTarget(toProcess);
        fb.clear(Color.BLACK);
        world.renderScene(fb);
        world.draw(fb);
        fb.display();
        fb.removeRenderTarget();

        switchToGlowRender = false;
    }


    public void doBlit(FrameBuffer fb)
    {
       fb.blit(toProcess, 0, 0, 0, fb.getHeight(),
       fb.getWidth()/divRatio, fb.getHeight()/divRatio, fb.getWidth(), -fb.getHeight(), 44, true, null);

    }
}