Welcome, Guest! Log In | Create Account

Changeset 1896

Show
Ignore:
Timestamp:
11/17/09 22:29:58 (3 months ago)
Author:
borrillis
Message:

Ticket #81
- SceneManager?

+ Added EnsureShadowTexturesCreated? method

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Projects/Axiom/Engine/Core/SceneManager.cs

    r1894 r1896  
    469469        /// <summary> 
    470470        ///         The default implementation of texture shadows uses a fixed-function  
    471         ///     colour texture projection approach for maximum compatibility, and  
     471        ///     color texture projection approach for maximum compatibility, and  
    472472        ///     as such cannot support self-shadowing. However, if you decide to  
    473473        ///         implement a more complex shadowing technique using  
     
    489489        protected bool shadowUseInfiniteFarPlane; 
    490490 
     491        /// <summary> 
     492        ///             If true, shadow volumes will be visible in the scene. 
     493        /// </summary> 
     494        protected bool showDebugShadows; 
     495 
     496        protected bool shadowTextureConfigDirty; 
     497        protected List<ShadowTextureConfig> shadowTextureConfigList = new List<ShadowTextureConfig>(); 
     498        protected Texture nullShadowTexture; 
     499        protected Dictionary<Camera, Light> shadowCameraLightMapping = new Dictionary<Camera, Light>(); 
     500 
    491501        /// <summary>Flag that specifies whether scene nodes will have their bounding boxes rendered as a wire frame.</summary> 
    492502        protected bool showBoundingBoxes; 
    493503 
    494         /// <summary> 
    495         ///             If true, shadow volumes will be visible in the scene. 
    496         /// </summary> 
    497         protected bool showDebugShadows; 
    498504 
    499505        protected Entity[] skyBoxEntities = new Entity[6]; 
     
    36293635        } 
    36303636 
     3637        protected virtual void EnsureShadowTexturesCreated() 
     3638        { 
     3639            if ( shadowTextureConfigDirty ) 
     3640            { 
     3641                DestroyShadowTextures(); 
     3642                ShadowTextureManager.Instance.GetShadowTextures( shadowTextureConfigList, shadowTextures ); 
     3643 
     3644                // clear shadow cam - light mapping 
     3645                shadowCameraLightMapping.Clear(); 
     3646 
     3647 
     3648                // Recreate shadow textures 
     3649                foreach ( Texture shadowTexture in shadowTextures ) 
     3650                { 
     3651                    // Camera names are local to SM  
     3652                    String camName = shadowTexture.Name + "Cam"; 
     3653                    // Material names are global to SM, make specific 
     3654                    String matName = shadowTexture.Name + "Mat" + this.Name; 
     3655 
     3656                    RenderTexture shadowRTT = shadowTexture.GetBuffer().GetRenderTarget(); 
     3657 
     3658                    // Create camera for this texture, but note that we have to rebind 
     3659                    // in PrepareShadowTextures to coexist with multiple SMs 
     3660                    Camera cam = CreateCamera( camName ); 
     3661                    cam.AspectRatio = shadowTexture.Width / (Real)shadowTexture.Height; 
     3662                    shadowTextureCameras.Add( cam ); 
     3663 
     3664                    // Create a viewport, if not there already 
     3665                    if ( shadowRTT.ViewportCount == 0 ) 
     3666                    { 
     3667                        // Note camera assignment is transient when multiple SMs 
     3668                        Viewport v = shadowRTT.AddViewport( cam ); 
     3669                        v.ClearEveryFrame = true; 
     3670                        // remove overlays 
     3671                        v.ShowOverlays = false; 
     3672                    } 
     3673 
     3674                    // Don't update automatically - we'll do it when required 
     3675                    shadowRTT.IsAutoUpdated = false; 
     3676 
     3677                    // Also create corresponding Material used for rendering this shadow 
     3678                    Material mat = (Material)MaterialManager.Instance[ matName ]; 
     3679                    if ( mat == null ) 
     3680                    { 
     3681                        mat = (Material)MaterialManager.Instance.Create( matName, ResourceGroupManager.InternalResourceGroupName ); 
     3682                    } 
     3683                    Pass p = mat.GetTechnique( 0 ).GetPass( 0 ); 
     3684                    if ( p.TextureUnitStageCount != 1 /* || 
     3685                         p.GetTextureUnitState( 0 ).GetTexture( 0 ) != shadowTexture */ ) 
     3686                    { 
     3687                        mat.GetTechnique( 0 ).GetPass( 0 ).RemoveAllTextureUnitStates(); 
     3688                        // create texture unit referring to render target texture 
     3689                        TextureUnitState texUnit = p.CreateTextureUnitState( shadowTexture.Name ); 
     3690                        // set projective based on camera 
     3691                        texUnit.SetProjectiveTexturing( !p.HasVertexProgram, cam ); 
     3692                        // clamp to border colour 
     3693                        texUnit.TextureAddressing = TextureAddressing.Border; 
     3694                        texUnit.TextureBorderColor = ColorEx.White; 
     3695                        mat.Touch(); 
     3696 
     3697                    } 
     3698 
     3699                    // insert dummy camera-light combination 
     3700                    shadowCameraLightMapping.Add( cam, null ); 
     3701 
     3702                    // Get null shadow texture 
     3703                    nullShadowTexture = shadowTextureConfigList.Count == 0 ? 
     3704                                        null : 
     3705                                        ShadowTextureManager.Instance.GetNullShadowTexture( shadowTextureConfigList[ 0 ].format ); 
     3706                } 
     3707                shadowTextureConfigDirty = false; 
     3708            } 
     3709        } 
     3710 
    36313711        #endregion 
    36323712