<div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div>Hi all,</div><div><br></div><div>It's a problem with osgShadow.</div>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). <div>I uses the code in the osgShadow example for shadowing, and put a point light in _shadowedScene. The models shadow on themselves.</div><div><br><div>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.</div></div><div>Also, if I put the light on one side of the building, the other side of it is still lit, no shadow showing.</div><div>I have tried different shadow implementations, but the results remain almost the same.</div><div><br></div><div>I can't figure out what is happening since the shadow is just 'partially' abnormal. Stuck here for days.</div><div><br></div>Thanks. <br><br>Regards, <br>tqjxlm. <div><br></div><div>osg version 3.4.0.</div><div>code:</div><div><div>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>---------------</div></div><div><u>Shadow</u></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> // arguments<br></div><div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span> char* argv[] = {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> "--vdsm",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> "--positionalLight",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> "--ortho",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> "--parallel-split",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> "--num-sm",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> "4",</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> "--cascaded"</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> };</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> int argc = sizeof(argv) / sizeof(argv[0]);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> // use an ArgumentParser object to manage the program arguments</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span> osg::ArgumentParser arguments(&argc, argv);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> // get the viewer</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> osgViewer::View& viewer = getViewer();</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> // init shadowed scene</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> _shadowedScene = new osgShadow::ShadowedScene;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> osgShadow::ShadowSettings* settings = _shadowedScene->getShadowSetti<wbr>ngs();</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> settings->setReceivesShadowTra<wbr>versalMask(<wbr>ReceivesShadowTraversalMask);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span> settings->setCastsShadowTraver<wbr>salMask(CastsShadowTraversalMa<wbr>sk);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span> double distance;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> if (arguments.read("--max-shadow-<wbr>distance", distance))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> settings->setMaximumShadowMapD<wbr>istance(distance);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span> // choose shadow map implementation</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> osg::ref_ptr<osgShadow::Minima<wbr>lShadowMap> msm = NULL;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> if (arguments.read("--no-shadows"<wbr>))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> OSG_NOTICE << "Not using a ShadowTechnique" << std::endl;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> _shadowedScene->setShadowTechn<wbr>ique(0);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--stsm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> osg::ref_ptr<osgShadow::Standa<wbr>rdShadowMap> st = new osgShadow::StandardShadowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> _shadowedScene->setShadowTechn<wbr>ique(st.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--pssm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> int mapcount = 3;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> while (arguments.read("--mapcount", mapcount));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> osg::ref_ptr<osgShadow::Parall<wbr>elSplitShadowMap> pssm = new osgShadow::ParallelSplitShadow<wbr>Map(NULL, mapcount);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> int mapres = 1024;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> while (arguments.read("--mapres", mapres))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                 </span> pssm->setTextureResolution(map<wbr>res);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> while (arguments.read("--debug-color<wbr>")) { pssm->setDebugColorOn(); }</div><div><br></div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> int minNearSplit = 0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> while (arguments.read("--minNearSpli<wbr>t", minNearSplit))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                  </span> if (minNearSplit > 0) {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                           </span> pssm->setMinNearDistanceForSpl<wbr>its(minNearSplit);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                       </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> int maxfardist = 0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> while (arguments.read("--maxFarDist"<wbr>, maxfardist))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                      </span> if (maxfardist > 0) {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                             </span> pssm->setMaxFarDistance(maxfar<wbr>dist);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                           </span> std::cout << "ParallelSplitShadowMap : setMaxFarDistance(" << maxfardist << ")" << std::endl;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                    </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> int moveVCamFactor = 0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> while (arguments.read("--moveVCamFac<wbr>tor", moveVCamFactor))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                      </span> if (maxfardist > 0) {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                             </span> pssm->setMoveVCamBehindRCamFac<wbr>tor(moveVCamFactor);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                     </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> double polyoffsetfactor = pssm->getPolygonOffset().x();</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> double polyoffsetunit = pssm->getPolygonOffset().y();</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">             </span> while (arguments.read("--PolyOffset-<wbr>Factor", polyoffsetfactor));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> while (arguments.read("--PolyOffset-<wbr>Unit", polyoffsetunit));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> pssm->setPolygonOffset(osg::Ve<wbr>c2(polyoffsetfactor, polyoffsetunit));</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> _shadowedScene->setShadowTechn<wbr>ique(pssm.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--ssm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> osg::ref_ptr<osgShadow::SoftSh<wbr>adowMap> sm = new osgShadow::SoftShadowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> _shadowedScene->setShadowTechn<wbr>ique(sm.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--vdsm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> while (arguments.read("--debugHUD")) settings->setDebugDraw(true);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> if (arguments.read("--persp")) settings->setShadowMapProjecti<wbr>onHint(osgShadow::<wbr>ShadowSettings::PERSPECTIVE_<wbr>SHADOW_MAP);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> if (arguments.read("--ortho")) settings->setShadowMapProjecti<wbr>onHint(osgShadow::<wbr>ShadowSettings::ORTHOGRAPHIC_<wbr>SHADOW_MAP);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> unsigned int unit = 1;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> if (arguments.read("--unit", unit)) settings->setBaseShadowTexture<wbr>Unit(unit);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> double n = 0.0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> if (arguments.read("-n", n)) settings->setMinimumShadowMapN<wbr>earFarRatio(n);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> unsigned int numShadowMaps;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> if (arguments.read("--num-sm", numShadowMaps)) settings->setNumShadowMapsPerL<wbr>ight(numShadowMaps);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> if (arguments.read("--parallel-sp<wbr>lit") || arguments.read("--ps")) settings->setMultipleShadowMap<wbr>Hint(osgShadow::<wbr>ShadowSettings::PARALLEL_<wbr>SPLIT);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> if (arguments.read("--cascaded")) settings->setMultipleShadowMap<wbr>Hint(osgShadow::<wbr>ShadowSettings::CASCADED);</div><div><br></div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> int mapres = 1024;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> while (arguments.read("--mapres", mapres))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                 </span> settings->setTextureSize(osg::<wbr>Vec2s(mapres, mapres));</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> osg::ref_ptr<osgShadow::ViewDe<wbr>pendentShadowMap> vdsm = new osgShadow::ViewDependentShadow<wbr>Map;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> _shadowedScene->setShadowTechn<wbr>ique(vdsm.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--lispsm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> if (arguments.read("--ViewBounds"<wbr>))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                     </span> msm = new osgShadow::LightSpacePerspecti<wbr>veShadowMapVB;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> else if (arguments.read("--CullBounds"<wbr>))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span> msm = new osgShadow::LightSpacePerspecti<wbr>veShadowMapCB;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> else // if( arguments.read( "--DrawBounds" ) ) // default</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                  </span> msm = new osgShadow::LightSpacePerspecti<wbr>veShadowMapDB;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else if (arguments.read("--msm"))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> if (arguments.read("--ViewBounds"<wbr>))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                     </span> msm = new osgShadow::MinimalShadowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> else if (arguments.read("--CullBounds"<wbr>))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span> msm = new osgShadow::MinimalCullBoundsSh<wbr>adowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> else // if( arguments.read( "--DrawBounds" ) ) // default</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                  </span> msm = new osgShadow::MinimalDrawBoundsSh<wbr>adowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span> else /* if (arguments.read("--sm")) */</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> osg::ref_ptr<osgShadow::Shadow<wbr>Map> sm = new osgShadow::ShadowMap;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> _shadowedScene->setShadowTechn<wbr>ique(sm.get());</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> int mapres = 1024;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">           </span> while (arguments.read("--mapres", mapres))</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                 </span> sm->setTextureSize(osg::Vec2s(<wbr>mapres, mapres));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span> if (msm)// Set common MSM & LISPSM arguments</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> {</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> _shadowedScene->setShadowTechn<wbr>ique(msm.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> while (arguments.read("--debugHUD")) msm->setDebugDraw(true);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> float minLightMargin = 10.f;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> float maxFarPlane = 0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> unsigned int texSize = 1024;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">         </span> unsigned int baseTexUnit = 0;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> unsigned int shadowTexUnit = 1;</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">             </span> while (arguments.read("--moveVCamFac<wbr>tor", minLightMargin));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">             </span> while (arguments.read("--minLightMar<wbr>gin", minLightMargin));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">             </span> while (arguments.read("--maxFarDist"<wbr>, maxFarPlane));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> while (arguments.read("--mapres", texSize));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> while (arguments.read("--baseTexture<wbr>Unit", baseTexUnit));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span> while (arguments.read("--shadowTextu<wbr>reUnit", shadowTexUnit));</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">          </span> msm->setMinLightMargin(minLigh<wbr>tMargin);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> msm->setMaxFarPlane(maxFarPlan<wbr>e);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> msm->setTextureSize(osg::Vec2s<wbr>(texSize, texSize));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">             </span> msm->setShadowTextureCoordInde<wbr>x(shadowTexUnit);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">                </span> msm->setShadowTextureUnit(shad<wbr>owTexUnit);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">              </span> msm->setBaseTextureCoordIndex(<wbr>baseTexUnit);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">            </span> msm->setBaseTextureUnit(baseTe<wbr>xUnit);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span> // init light</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> osg::Vec4 lightpos(0.0, 0.0, 1, 0.0);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> bool spotlight = false;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span> while (arguments.read("--positionalL<wbr>ight")) { lightpos.set(0.5, 0.5, 1.5, 1.0); }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> while (arguments.read("--directional<wbr>Light")) { lightpos.set(0.0, 0.0, 1, 0.0); }</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> while (arguments.read("--spotLight")<wbr>) { lightpos.set(0.5, 0.5, 1.5, 1.0); spotlight = true; }</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> // set light position, create a light ball for visualization<br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span> osg::ref_ptr<osg::Geode> coord = createIndicator(_intersectedPo<wbr>int);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> _lsIndicator = dynamic_cast<osg::ShapeDrawabl<wbr>e*>(coord->getDrawable(0));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span> _worldRoot->addChild(coord);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> _ls = new osg::LightSource;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> _ls->getLight()->setPosition(l<wbr>ightpos);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span> _ls->getLight()->setAmbient(o<wbr>sg::Vec4(0.7, 0.7, 0.7, 1.0));</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> _ls->getLight()->setDiffuse(o<wbr>sg::Vec4(0.8, 0.8, 0.8, 1.0));</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> // set shadowed model</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> _model = _loadedModels;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span> _nodeMask = _model->getNodeMask();<br></div><div><span style="white-space:pre-wrap">         </span>_model->setNodeMask(_nodeMask | CastsShadowTraversalMask | ReceivesShadowTraversalMask);<br></div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span> _shadowedScene->addChild(_mode<wbr>l.get());</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span> _shadowedScene->addChild(_ls.g<wbr>et());</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">  </span> _root->addChild(_shadowedScen<wbr>e);</div></div><div>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>---------------</div><div><u>View initialization</u></div><div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       osg::StateSet* state = _root->getOrCreateStateSet();
        state->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);<br></span></div><div><br></div><div><span style="white-space:pre-wrap">    </span>osg::ref_ptr<osgViewer::View> view = new osgViewer::View;</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>osg::Camera* camera = view->getCamera();</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>camera->setGraphicsContext( gw );</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>const osg::GraphicsContext::Traits* traits = gw->getTraits();</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>camera->setClearColor( osg::Vec4(1.0, 1.0, 1.0, 1.0) );</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>camera->setProjectionMatrixAsP<wbr>erspective(</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">               </span>30.0f, static_cast<double>(traits->wi<wbr>dth)/static_cast<double>(trait<wbr>s->height), 0.1f, 100000.0f );</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>camera->setComputeNearFarMode(<wbr>osg::Camera::COMPUTE_NEAR_FAR_<wbr>USING_BOUNDING_VOLUMES);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>camera->setNearFarRatio(0.0000<wbr>02);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>GLuint buffer = gw->getTraits()->doubleBuffer ? GL_BACK : GL_FRONT;</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>camera->setReadBuffer(buffer);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>camera->setDrawBuffer(buffer);</div><div><br></div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>view->setSceneData( scene );</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">       </span>view->addEventHandler(new osgViewer::StatsHandler);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>view->addEventHandler(new osgViewer::ThreadingHandler);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>view->addEventHandler(new osgViewer::WindowSizeHandler);</div><div><span class="m_-4240251802089280156m_-6138407011493892366gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>view->addEventHandler(new osgViewer::LODScaleHandler);</div><div><div>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>------------------------------<wbr>---------------</div></div><div><br></div><div>And the screen shots:</div><div><br></div><div>Strange shadow on a square.</div><div><div><img src="https://i.imgbox.com/o570lsHN.png" width="562" height="322"><br><br></div><div><br></div><div>No shadow of the flag.</div><div><img src="https://i.imgbox.com/9i8kNVAi.png" style="margin-right: 0px;"><br><br></div><div><br></div><div>Change light position, flag is shadowed correctly.<br><img src="https://i.imgbox.com/htSoUnpB.png" style="margin-right: 0px;"><br><br></div><div><br></div><div>Light on a build wall.<br><img src="https://i.imgbox.com/4qAb648k.png" style="margin-right: 0px;"><br><br></div><div><br></div><div>The back side should not be lit.<br><img src="https://i.imgbox.com/AOReMIZV.png" style="margin-right: 0px;"><br><br>​<br></div></div></div></div>
</div><br></div>