A few questions about shadows

Started by raft, March 11, 2013, 01:33:00 AM

Previous topic - Next topic

raft

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.

EgonOlsen

Quote from: raft on March 12, 2013, 11:33:14 PM
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.

raft

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:
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:
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..


EgonOlsen

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.

raft

Quote from: EgonOlsen 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?

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 ;)

raft

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.

EgonOlsen

Quote from: raft on March 14, 2013, 04:07:29 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

EgonOlsen

Quote from: raft 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?

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.