ShadowHelper - shadows cast close to receiver

Started by dcfingerprint, October 27, 2016, 09:53:33 PM

Previous topic - Next topic

dcfingerprint

Hi there,

Been trying out ShadowHelper in the new JPCT-AE along with some animated characters. 
Generally works great!  However, I have noticed some artifacts where shadows do not appear to render properly on the receiver when the casting object (in this case a bones character) is very close. 

In particular, you can see in the images below, the feet of the characters result in a "hole" in the shadow when the feet are near or on the floor.   I've tried experimenting with raising the object further up off the floor - and then it looks OK at some point (no "holes"), however then the scene of course doesn't look right since the character appears floating above the floor, instead of standing on it. 

All objects/meshes from the character are added as casters, and the floor is the single receiver.


                ShadowHelper.setShadowMode(GLSLShadowInjector.PCF_FILTERED_SHADOWS);

                Projector projector = new Projector();
                sh = new ShadowHelper(mRenderer.mFrameBuffer, projector, 1024);

                projector.setClippingPlanes(1f, 1000f);
                projector.setFOVLimits(0, 999);
                float fov = projector.convertDEGAngleIntoFOV((float) fieldOfView);
                projector.setFOV(fov);
                projector.setYFOV(fov);

                projector.setPosition(sv);
                projector.lookAt(caster.getTransformedCenter());

                sh.setLightSource(projector);

                int intColor = Utils.parseColor(shadowColor);
                int red = Color.red(intColor);
                int green = Color.green(intColor);
                int blue = Color.blue(intColor);
                sh.setAmbientLight(new RGBColor(red, green, blue));
                sh.addCaster(caster);

                AnimatedGroup group = getGroup(casterName);
                if (group != null) {
                    for (Animated3D a : group) {
                        sh.addCaster(a);
                    }
                }

                sh.addReceiver(receiver);

Any ideas for config or anything else I may be doing wrong?  Example image attached.

Thanks!

dcfingerprint

More examples attached.  See area around foot nearest floor.

EgonOlsen

#2
That's caused by a bias that's applied to the depth to prevent other artifacts. You can play around with it by using the ShadowHelper constructor that actually takes the bias as an additional parameter. You might want to try to change the culling mode of the ShadowHelper as well to see if that does any good.

dcfingerprint

Thanks!  A combination of reducing the bias and using setCullingMode(false) addressed the issue for this case.   Much appreciated.