Author Topic: Does jPCT-AE support shadow?  (Read 6158 times)

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #15 on: April 27, 2016, 12:33:34 pm »
Thank you.
I understand that it's not documented, but is there any sample of use shadows?
 
And is there any way to use it with Vuforia and get shadow on real table for example?
Something like
Code: [Select]
mShadowHelper.addReceiver(table);
And how I can initialize buffer whitch is parametr of ShadowHelper?
This example from wiki donīt work.
Code: [Select]
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL, IRenderer.MODE_OPENGL);
buffer.setPaintListener(this);

Thank you!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #16 on: April 27, 2016, 12:47:27 pm »
Yes, there is an example, but I can't access it right now. I'll post it later.

About the table...yes, in theory. But it would require that you model the table in the scene. You can't project a shadow on nothing and a table in a 2D camera image is actually nothing to a 3D engine.

The FrameBuffer is the normal FrameBuffer of your app. You just have to make sure to use OpenGL ES 2.0, not 1.x.

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #17 on: May 05, 2016, 09:22:44 am »
Can you post an example please?

Thank you.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net

Offline maggie

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #19 on: May 13, 2016, 05:13:12 pm »
About the table...yes, in theory. But it would require that you model the table in the scene. You can't project a shadow on nothing and a table in a 2D camera image is actually nothing to a 3D engine.

In vuforia case, is it necessary to set the orientation of the projector for the shadow?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #20 on: May 13, 2016, 05:36:11 pm »
It's always needed to set a proper orientation for the projector. That's not related to Vuforia.

Offline maggie

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #21 on: May 14, 2016, 12:42:25 am »
I mean in this particular example, projector orientation is not set explicitly. Perhaps because it's already set by the lib?
This should help: http://www.jpct.net/forum2/index.php/topic,4333.msg32272.html#msg32272

So generally, how the projector should be treated to make the shadow works with vuforia marker/image target?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #22 on: May 14, 2016, 10:28:29 am »
It should point to the object IMHO. Think of it as a spot light.

Offline maggie

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #23 on: May 17, 2016, 08:48:05 pm »
So I tried to integrate the shadow with vuforia, without any advanced customization. Just like how the example does it, I put the projector in the sun's location and look at to the ground.

Code: [Select]
public Constructor() {
   sun = new Light(world);
   sun.setIntensity(250, 250, 250);
   
   ...
   ...

   object = Object3D.mergeAll(Loader.loadOBJ(
mActivity.getAssets().open("teapot.obj"), null, 250f));
   object.build();

   world.addObject(object);
   
   // Shadow receiver
   ground = ExtendedPrimitives.createPlane(100, 10);
   ground.setAdditionalColor(new RGBColor(255, 255, 255));
   ground.setTransparency(20);
   ground.build();
   ground.rotateX( (float) Math.PI/2f );
   
   world.addObject(ground);
   cam = world.getCamera();

   SimpleVector sv = new SimpleVector();
   sv.set(ground.getTransformedCenter());
   sv.x += 50;
   sv.z += 400;
   sun.setPosition(sv);
   
}

public void onDrawFrame(GL10 gl) {
   ...
   sh.updateShadowMap(fb, world);
   ...
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
        ...   
       
     // set projector and shadow
    Projector projector = new Projector();
projector.setClippingPlanes(0.75f, 3000f);
float fov = projector.convertDEGAngleIntoFOV(90);
projector.setFOV(fov);
projector.setYFOV(fov);

projector.setPosition( sun.getPosition() );
projector.lookAt(ground.getTransformedCenter());

sh = new ShadowHelper(fb, projector, 1024);
sh.setAmbientLight(new RGBColor(50, 50, 50));
sh.addCaster(object);
sh.addReceiver(ground);

    ...
}

Here is the screen capture:


It looks like not mapped correctly.. any idea what possibly went wrong?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #24 on: May 17, 2016, 11:19:16 pm »
Looks like as if that teapot model isn't closed at the top. Try ShadowHelper.setCullingMode(true); and see if that helps.

Offline maggie

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #25 on: June 10, 2016, 08:58:13 pm »
Hi again, just have time now to follow up this one ;D
So I modified my code a bit, by adding sh.setCullingMode(true) as suggested, and set the sun+projector position 400 unit above the ground, while (x,y) remains (0,0). Having this value, I think the shadow should be exactly below the teapot. But here is what I got on Xperia M:


Also, with the same code, I'm not sure why I got different shadow behaviour when I run my code on Nexus 9 tablet:


any idea why?  :-\

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #26 on: June 11, 2016, 09:48:21 am »
I think this has something to do with the fact that you are doing this camera/AR thing somehow...I don't know how it's related, but the shadow calculations themselves are deterministic, so if the input parameters are actually the same, the output should be as well. Try to position the projector based on the teapots Position in world space every frame and see if that changes something.