Does jPCT-AE support shadow?

Started by kiffa, August 01, 2012, 08:36:40 AM

Previous topic - Next topic

drdla

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
mShadowHelper.addReceiver(table);

And how I can initialize buffer whitch is parametr of ShadowHelper?
This example from wiki donĀ“t work.

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!

EgonOlsen

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.

drdla

Can you post an example please?

Thank you.


maggie

Quote from: EgonOlsen on April 27, 2016, 12:47:27 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?

EgonOlsen

It's always needed to set a proper orientation for the projector. That's not related to Vuforia.

maggie

I mean in this particular example, projector orientation is not set explicitly. Perhaps because it's already set by the lib?
Quote from: EgonOlsen on May 05, 2016, 09:37:36 PM
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?

EgonOlsen

It should point to the object IMHO. Think of it as a spot light.

maggie

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.


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?

EgonOlsen

Looks like as if that teapot model isn't closed at the top. Try ShadowHelper.setCullingMode(true); and see if that helps.

maggie

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?  :-\

EgonOlsen

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.