Hi.
I can't say anything about your specific problems, but I had wrong shadows
when small objects were outside larget objects, i.e. if there's a plane and
a ball, and ball is outside the plane, the shadows were sometimes wrong.
To test my assumption, you can add a model with a plane that is underneath
*everything* in the scene and a wall that is heigher than *everything* in
the scene.
2017-06-27 23:14 GMT+07:00 Bris Li :
> Hi all,
>
> It's a problem with osgShadow.
> I hava a scene with multiple pagedLOD models bundled in a group. The
> models are tiles of a city, and each tile is a single model (buildings are
> not separeted with terrain).
> I uses the code in the osgShadow example for shadowing, and put a point
> light in _shadowedScene. The models shadow on themselves.
>
> As the attached image shows, the shadow result is partially correct. In
> some particular angle range from the light source, the correct shadow is
> casted. But in the other range, shadow is not cast correctly, but some
> strange shadows appear which I guess is casted from the model at the other
> side.
> Also, if I put the light on one side of the building, the other side of it
> is still lit, no shadow showing.
> I have tried different shadow implementations, but the results remain
> almost the same.
>
> I can't figure out what is happening since the shadow is just 'partially'
> abnormal. Stuck here for days.
>
> Thanks.
>
> Regards,
> tqjxlm.
>
> osg version 3.4.0.
> code:
>
>
> -
> *Shadow*
> // arguments
> char* argv[] = {
> "--vdsm",
> "--positionalLight",
> "--ortho",
> "--parallel-split",
> "--num-sm",
> "4",
> "--cascaded"
> };
>
> int argc = sizeof(argv) / sizeof(argv[0]);
>
> // use an ArgumentParser object to manage the program arguments
> osg::ArgumentParser arguments(, argv);
>
> // get the viewer
> osgViewer::View& viewer = getViewer();
>
> // init shadowed scene
> _shadowedScene = new osgShadow::ShadowedScene;
> osgShadow::ShadowSettings* settings = _shadowedScene->getShadowSettings();
> settings->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
> settings->setCastsShadowTraversalMask(CastsShadowTraversalMask);
>
> double distance;
> if (arguments.read("--max-shadow-distance", distance))
> {
> settings->setMaximumShadowMapDistance(distance);
> }
>
> // choose shadow map implementation
> osg::ref_ptr msm = NULL;
> if (arguments.read("--no-shadows"))
> {
> OSG_NOTICE << "Not using a ShadowTechnique" << std::endl;
> _shadowedScene->setShadowTechnique(0);
> }
> else if (arguments.read("--stsm"))
> {
> osg::ref_ptr st = new
> osgShadow::StandardShadowMap;
> _shadowedScene->setShadowTechnique(st.get());
> }
> else if (arguments.read("--pssm"))
> {
> int mapcount = 3;
> while (arguments.read("--mapcount", mapcount));
> osg::ref_ptr pssm = new
> osgShadow::ParallelSplitShadowMap(NULL, mapcount);
>
> int mapres = 1024;
> while (arguments.read("--mapres", mapres))
> pssm->setTextureResolution(mapres);
>
> while (arguments.read("--debug-color")) { pssm->setDebugColorOn(); }
>
>
> int minNearSplit = 0;
> while (arguments.read("--minNearSplit", minNearSplit))
> if (minNearSplit > 0) {
> pssm->setMinNearDistanceForSplits(minNearSplit);
> }
>
> int maxfardist = 0;
> while (arguments.read("--maxFarDist", maxfardist))
> if (maxfardist > 0) {
> pssm->setMaxFarDistance(maxfardist);
> std::cout << "ParallelSplitShadowMap : setMaxFarDistance(" << maxfardist
> << ")" << std::endl;
> }
>
> int moveVCamFactor = 0;
> while (arguments.read("--moveVCamFactor", moveVCamFactor))
> if (maxfardist > 0) {
> pssm->setMoveVCamBehindRCamFactor(moveVCamFactor);
> }
>
> double polyoffsetfactor = pssm->getPolygonOffset().x();
> double polyoffsetunit = pssm->getPolygonOffset().y();
> while (arguments.read("--PolyOffset-Factor", polyoffsetfactor));
> while (arguments.read("--PolyOffset-Unit", polyoffsetunit));
> pssm->setPolygonOffset(osg::Vec2(polyoffsetfactor, polyoffsetunit));
>
> _shadowedScene->setShadowTechnique(pssm.get());
> }
> else if (arguments.read("--ssm"))
> {
> osg::ref_ptr sm = new osgShadow::SoftShadowMap;
> _shadowedScene->setShadowTechnique(sm.get());
> }
> else if (arguments.read("--vdsm"))
> {
> while (arguments.read("--debugHUD")) settings->setDebugDraw(true);
> if (arguments.read("--persp")) settings->setShadowMapProjecti
> onHint(osgShadow::ShadowSettings::PERSPECTIVE_SHADOW_MAP);
> if (arguments.read("--ortho")) settings->setShadowMapProjecti
> onHint(osgShadow::ShadowSettings::ORTHOGRAPHIC_SHADOW_MAP);
>
> unsigned int unit = 1;
> if (arguments.read("--unit", unit)) settings->setBaseShadowTexture
> Unit(unit);
>
> double n = 0.0;
> if (arguments.read("-n", n)) settings->setMinimumShadowMapNearFarRatio(n);
>
> unsigned int numShadowMaps;
> if (arguments.read("--num-sm", numShadowMaps))
>