Author Topic: A few questions about shadows  (Read 8680 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: A few questions about shadows
« Reply #15 on: March 12, 2013, 11:33:14 pm »
I'm reading about shadow maps. please correct me if I'm wrong:

what ShadowHelper does:
1. first and once add a second layer texture to all receivers
2. render the world from projector's point into shadow texture
3. update second layer uv's according to projector's space*

rest is basic multi-texture rendering

if this is the case, after step 3, I can change 2nd layer uv's of tiles which I dont want to receive shadows. possible?

*btw, how do you do that? there is no setTextureUV or getTextureInfo method in PolygonManager. since ShadowHelper is in another package, it must be doing this via public API.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A few questions about shadows
« Reply #16 on: March 13, 2013, 07:16:03 am »
if this is the case, after step 3, I can change 2nd layer uv's of tiles which I dont want to receive shadows. possible?
No, because the projection happens inside the graphics chip. It's nothing that is done in Java code. You just issue a gl command and the chip does some magic when rendering the polygons.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: A few questions about shadows
« Reply #17 on: March 14, 2013, 04:57:33 am »
I've implemented as I described. it's not perfect as seen in the video below but i'm satisfied with the result. there are many few scenes where this flaw will be noticable:

http://www.aptalkarga.com/tmp/shadow-shortcoming.avi

however, with the current api this implementation is not heap friendly.

this is how to disable shadows for a polygon:
Code: [Select]
SimpleVector uv0 = pm.getTextureUV(i, 0);
SimpleVector uv1 = pm.getTextureUV(i, 1);
SimpleVector uv2 = pm.getTextureUV(i, 2);

TextureInfo ti = new TextureInfo(pm.getPolygonTexture(i), uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
pm.setPolygonTexture(i, ti);

and to re-enable it:
Code: [Select]
SimpleVector uv0 = pm.getTextureUV(i, 0);
SimpleVector uv1 = pm.getTextureUV(i, 1);
SimpleVector uv2 = pm.getTextureUV(i, 2);

TextureInfo ti = new TextureInfo(pm.getPolygonTexture(i), uv0.x, uv0.y, uv1.x, uv1.y, uv2.x, uv2.y);
ti.add(shadowTexture, TextureInfo.MODE_MODULATE);

pm.setPolygonTexture(i, ti);

as can be seen, many objects are created during this process. same TextureInfo can be used many times but I suppose a method like PolygonManager.getTextureUV(polyID, vertexNumber, SimpleVector) is required (unless of course there is another way)

another detail is, there is no direct way of retrieving texture id of shadow map. I get it via a receiver object's polygon manager as: pm.getPolygonTextures(i)[1]. A dedicated method may be nice, although not strictly necessary.

-- o --

please see the image below. shadow of the ball is visible on the bottom side of tile. is this the way it's supposed to be? there is a culling setting in ShadowHelper which makes me think shadows should not be visible on culled faces. (it has no effect on this)

thanks..


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A few questions about shadows
« Reply #18 on: March 14, 2013, 11:51:08 am »
Can't you store the SimpleVectors returned by getTextureUV()? Or are they supposed to change at runtime?

About the shadow on back faces: That's caused by the way the texture projection works. There's no way around this. The culling setting in the ShadowHelper only specifies which part of the object will write into the depth map, the front faces or the back faces.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: A few questions about shadows
« Reply #19 on: March 14, 2013, 04:07:29 pm »
Can't you store the SimpleVectors returned by getTextureUV()? Or are they supposed to change at runtime?

no, they dont change. sure I can do that, but I guess it will be a waste of memory. and the other way will be much easy ;D also I suppose someone will eventually need it ;)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: A few questions about shadows
« Reply #20 on: March 14, 2013, 06:45:32 pm »
I've found that shadows are rendered weird or not rendered at all when caster is close to receiver, as seen in the videos below. I just move ball temporarily up to overcome this, is there another setting?

http://aptalkarga.com/tmp/shadow-caster-too-close-1.avi
http://aptalkarga.com/tmp/shadow-caster-too-close-2.avi

there is Config.glShadowZBias but not sure if related to this.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A few questions about shadows
« Reply #21 on: March 14, 2013, 06:57:46 pm »
no, they dont change. sure I can do that, but I guess it will be a waste of memory. and the other way will be much easy ;D also I suppose someone will eventually need it ;)
Ok. here you go: http://jpct.de/download/beta/jpct.jar and http://jpct.de/download/beta/jpct_ae.jar

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: A few questions about shadows
« Reply #22 on: March 14, 2013, 06:59:44 pm »
I've found that shadows are rendered weird or not rendered at all when caster is close to receiver, as seen in the videos below. I just move ball temporarily up to overcome this, is there another setting?

there is Config.glShadowZBias but not sure if related to this.
It's either the offset (just play around with that value), the culling (try another culling mode for the ShadowHelper) or some inaccuracy of the GPU.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com