void DestroyReflectionTexture() { //remove reflectionTexture from material if( material != null ) material.RemoveReflectionMapFromMaterial(); if( reflectionViewport != null ) { reflectionViewport.Dispose(); reflectionViewport = null; } if( reflectionCamera != null ) { reflectionCamera.Dispose(); reflectionCamera = null; } if( renderTargetListener != null ) { reflectionRenderTexture.RemoveListener( renderTargetListener ); renderTargetListener.Dispose(); renderTargetListener = null; } reflectionRenderTexture = null; if( reflectionTexture != null ) { reflectionTexture.Dispose(); reflectionTexture = null; } }
void CreateReflectionTexture() { DestroyReflectionTexture(); Vec2i textureSize = GetRequiredReflectionTextureSize(); //create render texture string textureName = TextureManager.Instance.GetUniqueName( "WaterPlaneReflection" ); bool hdr = RendererWorld.Instance.DefaultViewport.GetCompositorInstance( "HDR" ) != null; reflectionTexture = TextureManager.Instance.Create( textureName, Texture.Type.Type2D, textureSize, 1, 0, hdr ? PixelFormat.Float16RGB : PixelFormat.R8G8B8, Texture.Usage.RenderTarget ); reflectionRenderTexture = reflectionTexture.GetBuffer().GetRenderTarget(); //create camera reflectionCamera = SceneManager.Instance.CreateCamera(); reflectionCamera.AllowFrustumTestMode = true; //add viewport reflectionViewport = reflectionRenderTexture.AddViewport( reflectionCamera ); reflectionViewport.ShadowsEnabled = false; reflectionViewport.MaterialScheme = MaterialSchemes.Low.ToString(); //add listener renderTargetListener = new ReflectionRenderTargetListener( this ); reflectionRenderTexture.AddListener( renderTargetListener ); reflectionRenderTexture.AutoUpdate = Visible; }