Changeset 657 for OGRE/trunk/ogre_changes/OgreMain/src/OgreSceneManager.cpp
- Timestamp:
- 02/20/06 19:06:03 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OGRE/trunk/ogre_changes/OgreMain/src/OgreSceneManager.cpp
r343 r657 375 375 // Subclasses could do something smarter 376 376 destList.clear(); 377 Real squaredRadius = radius * radius;378 377 379 378 SceneLightList::iterator i, iend; … … 396 395 // only add in-range lights 397 396 Real range = lt->getAttenuationRange(); 398 if ((lt->tempSquareDist - squaredRadius) <= (range * range)) 397 Real maxDist = range + radius; 398 if (lt->tempSquareDist <= Math::Sqr(maxDist)) 399 399 { 400 400 destList.push_back(lt); … … 554 554 mSkyBoxEnabled = mSkyPlaneEnabled = mSkyDomeEnabled = false; 555 555 556 // Clear render queue, empty completely 557 if (mRenderQueue) 558 mRenderQueue->clear(true); 559 556 560 } 557 561 //----------------------------------------------------------------------- … … 593 597 AutoTrackingSceneNodes::iterator ai, aiend; 594 598 aiend = mAutoTrackingSceneNodes.end(); 595 for (ai = mAutoTrackingSceneNodes.begin(); ai != aiend; ++ai) 596 { 597 SceneNode* n = *ai; 599 for (ai = mAutoTrackingSceneNodes.begin(); ai != aiend; ) 600 { 601 // Pre-increment incase we delete 602 AutoTrackingSceneNodes::iterator curri = ai++; 603 SceneNode* n = *curri; 598 604 // Tracking this node 599 605 if (n->getAutoTrackTarget() == i->second) … … 601 607 // turn off, this will notify SceneManager to remove 602 608 n->setAutoTracking(false); 603 // no need to reset iterator since set erase does not invalidate604 609 } 605 610 // node is itself a tracker 606 611 else if (n == i->second) 607 612 { 608 mAutoTrackingSceneNodes.erase( ai);613 mAutoTrackingSceneNodes.erase(curri); 609 614 } 610 615 } … … 814 819 if (thisFrameNumber != lastFrameNumber) 815 820 { 821 // Update controllers 822 ControllerManager::getSingleton().updateAllControllers(); 816 823 // Update animations 817 824 _applySceneAnimations(); 818 // Update controllers819 ControllerManager::getSingleton().updateAllControllers();820 825 lastFrameNumber = thisFrameNumber; 821 826 } … … 868 873 } 869 874 875 // Tell params about viewport 876 mAutoParamDataSource.setCurrentViewport(vp); 870 877 // Set the viewport 871 878 setViewport(vp); … … 1409 1416 { 1410 1417 // Someone requested we skip this queue 1411 continue;1418 break; 1412 1419 } 1413 1420 … … 1713 1720 mShadowReceiverPass->_load(); 1714 1721 1715 if (l->getCastShadows() && pGroup->getShadowsEnabled())1722 if (l->getCastShadows()) 1716 1723 { 1717 1724 renderTextureShadowReceiverQueueGroupObjects(pGroup); … … 1876 1883 { 1877 1884 // Ordinary pass 1885 if (pGroup->getShadowsEnabled()) 1878 1886 renderModulativeTextureShadowedQueueGroupObjects(pGroup); 1887 else 1888 renderBasicQueueGroupObjects(pGroup); 1879 1889 } 1880 1890 } … … 2118 2128 { 2119 2129 mAmbientLight = colour; 2120 mDestRenderSystem->setAmbientLight(colour.r, colour.g, colour.b);2121 2130 } 2122 2131 //----------------------------------------------------------------------- … … 2656 2665 { 2657 2666 createShadowTextures(mShadowTextureSize, mShadowTextureCount, mShadowTextureFormat); 2667 } 2668 else 2669 { 2670 // Destroy shadow textures to optimise resource usage 2671 destroyShadowTextures(); 2658 2672 } 2659 2673 … … 2764 2778 const Vector3* corners = camera->getWorldSpaceCorners(); 2765 2779 Vector3 min, max; 2766 Vector3 extrude = light->getD irection() * -mShadowDirLightExtrudeDist;2780 Vector3 extrude = light->getDerivedDirection() * -mShadowDirLightExtrudeDist; 2767 2781 // do first corner 2768 2782 min = max = corners[0]; … … 2792 2806 else 2793 2807 { 2794 Sphere s(light->get Position(), light->getAttenuationRange());2808 Sphere s(light->getDerivedPosition(), light->getAttenuationRange()); 2795 2809 // eliminate early if camera cannot see light sphere 2796 2810 if (camera->isVisible(s)) … … 2875 2889 { 2876 2890 mShadowDebugPass = matDebug->getTechnique(0)->getPass(0); 2891 2892 if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM)) 2893 { 2894 mInfiniteExtrusionParams = mShadowDebugPass->getVertexProgramParameters(); 2895 } 2877 2896 } 2878 2897 } … … 2915 2934 { 2916 2935 mShadowStencilPass = matStencil->getTechnique(0)->getPass(0); 2936 2937 if (mDestRenderSystem->getCapabilities()->hasCapability(RSC_VERTEX_PROGRAM)) 2938 { 2939 mFiniteExtrusionParams = mShadowStencilPass->getVertexProgramParameters(); 2940 } 2917 2941 } 2918 2942 } … … 3029 3053 Pass* SceneManager::deriveShadowCasterPass(Pass* pass) 3030 3054 { 3055 Pass* retPass = 0; 3031 3056 switch (mShadowTechnique) 3032 3057 { 3033 3058 case SHADOWTYPE_TEXTURE_MODULATIVE: 3034 if (mShadowTextureCustomCasterPass) 3059 retPass = mShadowTextureCustomCasterPass ? 3060 mShadowTextureCustomCasterPass : mShadowCasterPlainBlackPass; 3061 3062 3063 // Special case alpha-blended passes 3064 if ((pass->getSourceBlendFactor() == SBF_SOURCE_ALPHA && 3065 pass->getDestBlendFactor() == SBF_ONE_MINUS_SOURCE_ALPHA) 3066 || pass->getAlphaRejectFunction() != CMPF_ALWAYS_PASS) 3035 3067 { 3036 // Caster pass has been customised 3068 // Alpha blended passes must retain their transparency 3069 retPass->setAlphaRejectSettings(pass->getAlphaRejectFunction(), 3070 pass->getAlphaRejectValue()); 3071 retPass->setSceneBlending(pass->getSourceBlendFactor(), pass->getDestBlendFactor()); 3072 retPass->getParent()->getParent()->setTransparencyCastsShadows(true); 3073 3074 // So we allow the texture units, but override the colour functions 3075 // Copy texture state, shift up one since 0 is shadow texture 3076 size_t origPassTUCount = pass->getNumTextureUnitStates(); 3077 for (size_t t = 0; t < origPassTUCount; ++t) 3078 { 3079 TextureUnitState* tex; 3080 if (retPass->getNumTextureUnitStates() <= t) 3081 { 3082 tex = retPass->createTextureUnitState(); 3083 } 3084 else 3085 { 3086 tex = retPass->getTextureUnitState(t); 3087 } 3088 // copy base state 3089 (*tex) = *(pass->getTextureUnitState(t)); 3090 // override colour function 3091 tex->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 3092 mShadowColour); 3093 3094 } 3095 // Remove any extras 3096 while (retPass->getNumTextureUnitStates() > origPassTUCount) 3097 { 3098 retPass->removeTextureUnitState(origPassTUCount); 3099 } 3100 3101 } 3102 else 3103 { 3104 // reset 3105 retPass->setSceneBlending(SBF_ONE, SBF_ZERO); 3106 retPass->setAlphaRejectFunction(CMPF_ALWAYS_PASS); 3107 while (retPass->getNumTextureUnitStates() > 0) 3108 { 3109 retPass->removeTextureUnitState(0); 3110 } 3111 } 3112 3113 // Propagate culling modes 3114 retPass->setCullingMode(pass->getCullingMode()); 3115 retPass->setManualCullingMode(pass->getManualCullingMode()); 3116 3037 3117 3038 3118 if (!pass->getShadowCasterVertexProgramName().empty()) 3039 3119 { 3040 3120 // Have to merge the shadow caster vertex program in 3041 mShadowTextureCustomCasterPass->setVertexProgram(3121 retPass->setVertexProgram( 3042 3122 pass->getShadowCasterVertexProgramName()); 3043 const GpuProgramPtr& prg = mShadowTextureCustomCasterPass->getVertexProgram();3123 const GpuProgramPtr& prg = retPass->getVertexProgram(); 3044 3124 // Load this program if not done already 3045 3125 if (!prg->isLoaded()) 3046 3126 prg->load(); 3047 3127 // Copy params 3048 mShadowTextureCustomCasterPass->setVertexProgramParameters(3128 retPass->setVertexProgramParameters( 3049 3129 pass->getShadowCasterVertexProgramParameters()); 3130 if (retPass == mShadowTextureCustomCasterPass) 3131 { 3050 3132 // mark that we've overridden the standard 3051 3133 mShadowTextureCasterVPDirty = true; 3134 } 3052 3135 // Also have to hack the light autoparams, that is done later 3053 3136 } 3054 else if (mShadowTextureCasterVPDirty) 3137 else 3138 { 3139 retPass->setVertexProgram(StringUtil::BLANK); 3140 if (mShadowTextureCasterVPDirty) 3055 3141 { 3056 3142 // reset … … 3065 3151 mShadowTextureCasterVPDirty = false; 3066 3152 } 3067 return mShadowTextureCustomCasterPass;3068 3153 } 3069 else 3070 { 3071 // Standard pass 3072 if (pass->hasVertexProgram()) 3073 { 3074 // Have to merge the shadow caster vertex program in 3075 // This may in fact be blank, in which case it falls back on 3076 // fixed function 3077 mShadowCasterPlainBlackPass->setVertexProgram( 3078 pass->getShadowCasterVertexProgramName()); 3079 // Did this result in a new vertex program? 3080 if (mShadowCasterPlainBlackPass->hasVertexProgram()) 3081 { 3082 const GpuProgramPtr& prg = mShadowCasterPlainBlackPass->getVertexProgram(); 3083 // Load this program if not done already 3084 if (!prg->isLoaded()) 3085 prg->load(); 3086 // Copy params 3087 mShadowCasterPlainBlackPass->setVertexProgramParameters( 3088 pass->getShadowCasterVertexProgramParameters()); 3089 } 3090 // Also have to hack the light autoparams, that is done later 3091 } 3092 else if (mShadowCasterPlainBlackPass->hasVertexProgram()) 3093 { 3094 // reset 3095 mShadowCasterPlainBlackPass->setVertexProgram(""); 3096 } 3097 return mShadowCasterPlainBlackPass; 3098 } 3154 return retPass; 3099 3155 default: 3100 3156 return pass; … … 3301 3357 { 3302 3358 ShadowCaster* caster = *si; 3303 bool zfailAlgo = false;3359 bool zfailAlgo = camera->isCustomNearClipPlaneEnabled(); 3304 3360 unsigned long flags = 0; 3305 3361 … … 3705 3761 3706 3762 // destroy existing 3707 ShadowTextureList::iterator i, iend; 3708 iend = mShadowTextures.end(); 3709 for (i = mShadowTextures.begin(); i != iend; ++i) 3710 { 3711 RenderTexture* r = *i; 3712 // remove camera and destroy texture 3713 removeCamera(r->getViewport(0)->getCamera()); 3714 mDestRenderSystem->destroyRenderTexture(r->getName()); 3715 } 3716 mShadowTextures.clear(); 3763 destroyShadowTextures(); 3717 3764 3718 3765 // Recreate shadow textures … … 3762 3809 3763 3810 } 3811 } 3812 //--------------------------------------------------------------------- 3813 void SceneManager::destroyShadowTextures(void) 3814 { 3815 ShadowTextureList::iterator i, iend; 3816 iend = mShadowTextures.end(); 3817 for (i = mShadowTextures.begin(); i != iend; ++i) 3818 { 3819 RenderTexture* r = *i; 3820 // remove camera and destroy texture 3821 removeCamera(r->getViewport(0)->getCamera()); 3822 mDestRenderSystem->destroyRenderTexture(r->getName()); 3823 } 3824 mShadowTextures.clear(); 3764 3825 } 3765 3826 //---------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.