OGRE版本1.7.1的Sample里包含了地形的示例,且用到了PSSM+LiSPSM。
今天尝试把Character的Sinbad模型摆到地形上,不过模型的材质本身不支持PSSM。
看了下地形示例的实现,发现它在给Shader传PSSM分界点数据时,用了把模板材质clone一份,再设置diffusemap和pssm分界点的方法,相当让人无语....
MaterialPtr ret = MaterialManager::getSingleton().getByName(matName); MaterialPtr baseMat = MaterialManager::getSingleton().getByName("Ogre/shadow/depth/integrated/pssm"); ret = baseMat->clone(matName); Pass* p = ret->getTechnique(0)->getPass(0); p->getTextureUnitState("diffuse")->setTextureName(textureName); Vector4 splitPoints; const PSSMShadowCameraSetup::SplitPointList& splitPointList = static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints(); for (int i = 0; i < 3; ++i) { splitPoints[i] = splitPointList[i]; } p->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints);
如果有几百种不同贴图的物件,就得在代码里手动为每一个物件设置diffusemap和pssm分界点,前者其实在材质脚本中可以用继承来覆盖,后者其实整个场景用到的数据都是一样的。好在OGRE增加了shared_params,可以多个shader共享相同的参数,在代码里只设置一遍就可以了。
修改后的fp:
shared_params pssm_params { shared_param_named pssmSplitPoints float4 } fragment_program Ogre/shadow/receiver/depth/pssm3/fp cg { source depthshadowobject.cg profiles ps_2_x arbfp1 entry_point main_fp compile_arguments -DSHADOWCASTER=0 -DDEPTH_SHADOWCASTER=0 -DDEPTH_SHADOWRECEIVER=1 default_params { param_named_auto materialAmbient derived_ambient_light_colour // shadow samplers are indexes 1/2/3 param_named_auto inverseShadowmapSize0 inverse_texture_size 1 param_named_auto inverseShadowmapSize1 inverse_texture_size 2 param_named_auto inverseShadowmapSize2 inverse_texture_size 3 //SET THIS MANUALLY! //param_named pssmSplitPoints 0 0 0 0 shared_params_ref pssm_params } }
c++:
Vector4 splitPoints; const PSSMShadowCameraSetup::SplitPointList& splitPointList = static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints(); for (int i = 0; i < 3; ++i) { splitPoints[i] = splitPointList[i]; } GpuSharedParametersPtr p = GpuProgramManager::getSingleton().getSharedParameters("pssm_params"); p->setNamedConstant("pssmSplitPoints", splitPoints);
http://blog.csdn.net/cometeor/archive/2010/06/09/5657168.aspx