shadowhelper/projector help

Started by IZACIZAC, January 26, 2014, 09:29:50 PM

Previous topic - Next topic

IZACIZAC

I'm trying to use the shadowhelper and projector by following the advanced example on the wiki but can't get it right. Part of my models dissapears and part becomes invisible.

I have a cube (the player) that a light follows. - this is my only light source, ambient light is 0.

Then I have 2 objects3Ds,
-the level that is rendered and is a reciever of shadows
-a large box (from primitives) that casts shadows



This is my code

        projector = new Projector();
        projector.setFOV(1.5f);
projector.setYFOV(1.5f);

        sh = new ShadowHelper(world, buffer, projector, 2048);
        sh.setCullingMode(false);
        sh.setAmbientLight(new Color(30, 30, 30));
        sh.setLightMode(true);
        //sh.setLightMode(false); neither makes any difference
        sh.setBorder(1);

        sh.addCaster(shadowbox);

        sh.addReceiver(level)


then


            projector.setPosition(player.getTransformedCenter());            //player is object3d that light follows
            projector.lookAt(level.getTransformedCenter());
            sh.updateShadowMap();


It sort of works on occasion, but parts of level are becoming transparent and looking bizzare. Am I doing something wrong with the code?

EgonOlsen

Not sure what you are trying to do there... you set the projector right into the player's center. That's a not a good idea. The projector is meant to be something light the sun or a light source. The player usually doesn't glow from within and if that's the same entity that is supposed to cast the shadow...well, that won't too well, i think. Have you tried to move the projector away from the player just like the advanced example does it?

If it still doesn't work, a screen shot of the problem might help.

IZACIZAC

The light in this case does glow from within the player, but the player does not cast a shadow.


Light source is roughly where the red dot is, hovering above the ground. In this case, the grey box on the right of each picture is a caster, and the surrounding room is the reciever.
Left picture shows with shadows, its making the wall transparent. Right picture is without shadows.

I'm just confused I think, I don't know what the projector really does, and how I should set it up for this situation (if its even possible). Should my Projector instead be in the same position as the Camera?

EgonOlsen

No, your use of the projector seems fine then. Can you post your complete render loop, i.e. the whole thing from updateShadowMap to display?

IZACIZAC

#4
I had commented out shadowHelper.drawScene() 

>.>. That sorted the dissapearing bit



My final problem is that it is casting a shadow in two areas. The box outlined in blue is the only caster, and the light is at the yellow dot. Why do I get a second shadow by the red question mark?

Here is a 2nd image without that 'player' box for clarification

EgonOlsen

That's caused by the way projective textures are implemented in the GL pipeline. For each projection into the direction of the projector, you'll get a mirrored one on the other side of the projector. You can avoid this by moving the projector out of the geometry, if that's an option.

IZACIZAC

: /  I can but it just means the shadow no longer looks right, warped depending on where I move the projector, or placed on the wrong side if I move the projector out of the model sideways. I guess I cant use shadows this way... Wanted it to be like my player was holding a lamp as he moved around

EgonOlsen

I see the problem, but i don't see a solution to this. At least not with the way in which the ShadowHelper is implemented (by using the means that OpenGL offers for shadow mapping) ATM. One could create a shader based solution to solve this, but currently there is none. I'm still planning on doing this for the Android version and that will most likely port back to the desktop version, but there's no fixed schedule for this. I actually wanted to have it in the next release, but that's not going to make it.

IZACIZAC

Alright, I'm just going to ignore the issue for now and decide what to do later. Thanks for your help