Author Topic: shadowhelper/projector help  (Read 1114 times)

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
shadowhelper/projector help
« on: January 26, 2014, 09:29:50 pm »
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
Code: [Select]
        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

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: shadowhelper/projector help
« Reply #1 on: January 26, 2014, 09:41:01 pm »
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.

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
Re: shadowhelper/projector help
« Reply #2 on: January 26, 2014, 11:11:18 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: shadowhelper/projector help
« Reply #3 on: January 26, 2014, 11:36:02 pm »
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?

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
Re: shadowhelper/projector help
« Reply #4 on: January 26, 2014, 11:56:53 pm »
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
« Last Edit: January 27, 2014, 03:08:53 am by IZACIZAC »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: shadowhelper/projector help
« Reply #5 on: January 27, 2014, 08:34:51 pm »
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.

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
Re: shadowhelper/projector help
« Reply #6 on: January 27, 2014, 09:28:15 pm »
: /  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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: shadowhelper/projector help
« Reply #7 on: January 27, 2014, 11:36:36 pm »
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.

Offline IZACIZAC

  • byte
  • *
  • Posts: 19
    • View Profile
Re: shadowhelper/projector help
« Reply #8 on: January 28, 2014, 01:11:32 am »
Alright, I'm just going to ignore the issue for now and decide what to do later. Thanks for your help