Author Topic: Objects multiple worlds?  (Read 4841 times)

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Objects multiple worlds?
« on: October 12, 2015, 06:06:29 pm »
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.
« Last Edit: October 12, 2015, 06:17:07 pm by lawless_c »

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #1 on: October 12, 2015, 07:17:18 pm »
Actually I may be able to do both in one world instance :-)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #2 on: October 12, 2015, 09:29:38 pm »
Is it possible to add the same instances of an Object3d to many worlds?
No, that's not possible, I'm afraid.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #3 on: October 12, 2015, 11:31:39 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #4 on: October 13, 2015, 08:52:25 am »
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.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #5 on: October 13, 2015, 06:07:22 pm »
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.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #6 on: October 13, 2015, 07:16:51 pm »
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.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #7 on: October 15, 2015, 12:01:28 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #8 on: October 15, 2015, 03:52:16 pm »
That's actually the way to do it. Are you using OpenGL ES 2.0?

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #9 on: October 15, 2015, 04:13:21 pm »
yeah. I briefly got some weird effects , on the texture , will keep fiddling with it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #10 on: October 15, 2015, 05:26:39 pm »
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.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #11 on: October 15, 2015, 06:14:19 pm »
My code for it

toProcess is  the texture object

theRenderspot is the object3d

Code: [Select]
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Objects multiple worlds?
« Reply #12 on: October 15, 2015, 07:14:38 pm »
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.

Offline lawless_c

  • int
  • **
  • Posts: 96
    • View Profile
Re: Objects multiple worlds?
« Reply #13 on: October 17, 2015, 01:35:18 am »
 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.




Code: [Select]
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);

    }
}
« Last Edit: October 17, 2015, 01:44:39 am by lawless_c »