protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); VegetationMaterial source = (VegetationMaterial)sourceMaterial; waveOnlyInVerticalPosition = source.waveOnlyInVerticalPosition; receiveObjectsPositionsFromVertices = source.receiveObjectsPositionsFromVertices; }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); SimpleExampleMaterial source = (SimpleExampleMaterial)sourceMaterial; diffuseMap = source.ConvertToFullPath(source.diffuseMap); }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); VegetationMaterial source = (VegetationMaterial)sourceMaterial; waveOnlyInVerticalPosition = source.waveOnlyInVerticalPosition; receiveObjectsPositionsFromVertices = source.receiveObjectsPositionsFromVertices; }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); DefaultShadowCasterMaterial source = (DefaultShadowCasterMaterial)sourceMaterial; LightType = source.LightType; AtiHardwareShadows = source.AtiHardwareShadows; NvidiaHardwareShadows = source.NvidiaHardwareShadows; }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); DefaultShadowCasterMaterial source = (DefaultShadowCasterMaterial)sourceMaterial; LightType = source.LightType; AtiHardwareShadows = source.AtiHardwareShadows; NvidiaHardwareShadows = source.NvidiaHardwareShadows; }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); VegetationMaterial source = (VegetationMaterial)sourceMaterial; receiveObjectsPositionsFromVertices = source.receiveObjectsPositionsFromVertices; windEffectFactor = source.windEffectFactor; detailBending = source.detailBending; bendScale = source.bendScale; bendVariation = source.bendVariation; bendFrequency = source.bendFrequency; branchAmplitude = source.branchAmplitude; leafAmplitude = source.leafAmplitude; branchFrequency = source.branchFrequency; leafFrequency = source.leafFrequency; }
protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); SimpleExampleMaterial source = (SimpleExampleMaterial)sourceMaterial; diffuseMap = source.diffuseMap; }
protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); }
protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); VegetationMaterial source = (VegetationMaterial)sourceMaterial; receiveObjectsPositionsFromVertices = source.receiveObjectsPositionsFromVertices; windEffectFactor = source.windEffectFactor; detailBending = source.detailBending; bendScale = source.bendScale; bendVariation = source.bendVariation; bendFrequency = source.bendFrequency; branchAmplitude = source.branchAmplitude; leafAmplitude = source.leafAmplitude; branchFrequency = source.branchFrequency; leafFrequency = source.leafFrequency; }
/////////////////////////////////////////// public override void OnSceneManagementUpdateShadowSettings() { ShadowTechniques needShadowTechnique = Map.Instance.ShadowTechnique; PixelFormat textureFormatForDirectionalLight = PixelFormat.L8; PixelFormat textureFormatForSpotLight = PixelFormat.L8; PixelFormat textureFormatForPointLight = PixelFormat.L8; HighLevelMaterial[] defaultCasterMaterials = new HighLevelMaterial[ 3 ]; bool textureSelfShadow = false; bool renderBackFaces = false; bool pssm = false; float[] pssmSplitDistances = new float[ 0 ]; int directionalLightMaxTextureCount = Map.Instance.ShadowDirectionalLightMaxTextureCount; int spotLightMaxTextureCount = Map.Instance.ShadowSpotLightMaxTextureCount; int pointLightMaxTextureCount = Map.Instance.ShadowPointLightMaxTextureCount; int maxTextureSize = RenderSystem.Instance.Capabilities.MaxTextureSize; Vec2[] shadowLightBiasDirectionalLight = new Vec2[ 3 ]; Vec2 shadowLightBiasPointLight = Vec2.Zero; Vec2 shadowLightBiasSpotLight = Vec2.Zero; //no shadows for OpenGL ES. if( RenderSystem.Instance.IsOpenGLES() ) needShadowTechnique = ShadowTechniques.None; bool shadowMap = needShadowTechnique == ShadowTechniques.ShadowmapLow || needShadowTechnique == ShadowTechniques.ShadowmapMedium || needShadowTechnique == ShadowTechniques.ShadowmapHigh || needShadowTechnique == ShadowTechniques.ShadowmapLowPSSM || needShadowTechnique == ShadowTechniques.ShadowmapMediumPSSM || needShadowTechnique == ShadowTechniques.ShadowmapHighPSSM; if( shadowMap ) { bool atiHardwareShadows = false; bool nvidiaHardwareShadows = false; { if( ( RenderSystem.Instance.IsDirect3D() || RenderSystem.Instance.IsOpenGL() ) && RenderSystem.Instance.IsDepthShadowmapSupported() && RenderSystem.Instance.HasShaderModel3() && TextureManager.Instance.IsFormatSupported( Texture.Type.Type2D, PixelFormat.Depth24, Texture.Usage.RenderTarget ) ) { if( RenderSystem.Instance.Capabilities.Vendor == GPUVendors.ATI ) atiHardwareShadows = true; if( RenderSystem.Instance.Capabilities.Vendor == GPUVendors.NVidia ) nvidiaHardwareShadows = true; } } if( RenderSystem.Instance.IsDepthShadowmapSupported() ) { //set texture formats textureFormatForDirectionalLight = PixelFormat.Float32R; textureFormatForSpotLight = PixelFormat.Float32R; textureFormatForPointLight = PixelFormat.Float32R; if( nvidiaHardwareShadows ) { textureFormatForDirectionalLight = PixelFormat.Depth24; textureFormatForSpotLight = PixelFormat.Depth24; } //create material for each light type for( int nLightType = 0; nLightType < 3; nLightType++ ) { RenderLightType lightType = (RenderLightType)nLightType; string materialName = string.Format( "__(system)DefaultShadowCaster_{0}Light", lightType ); if( lightType == RenderLightType.Directional || lightType == RenderLightType.Spot ) { if( atiHardwareShadows ) materialName += "_AtiHardwareShadows"; if( nvidiaHardwareShadows ) materialName += "_NvidiaHardwareShadows"; } DefaultShadowCasterMaterial material = (DefaultShadowCasterMaterial) HighLevelMaterialManager.Instance.GetMaterialByName( materialName ); if( material == null ) { material = (DefaultShadowCasterMaterial)HighLevelMaterialManager.Instance. CreateMaterial( materialName, typeof( DefaultShadowCasterMaterial ).Name ); material.LightType = lightType; if( lightType == RenderLightType.Directional || lightType == RenderLightType.Spot ) { material.AtiHardwareShadows = atiHardwareShadows; material.NvidiaHardwareShadows = nvidiaHardwareShadows; } } //set default caster material for scene manager defaultCasterMaterials[ (int)lightType ] = material; } textureSelfShadow = true; if( RenderSystem.Instance.HasShaderModel3() ) { if( needShadowTechnique == ShadowTechniques.ShadowmapLowPSSM || needShadowTechnique == ShadowTechniques.ShadowmapMediumPSSM || needShadowTechnique == ShadowTechniques.ShadowmapHighPSSM ) { pssm = true; pssmSplitDistances = new float[ 4 ]; pssmSplitDistances[ 0 ] = Map.Instance.NearFarClipDistance.Minimum; pssmSplitDistances[ 1 ] = Map.Instance.ShadowPSSMSplitFactors[ 0 ] * Map.Instance.ShadowFarDistance; pssmSplitDistances[ 2 ] = Map.Instance.ShadowPSSMSplitFactors[ 1 ] * Map.Instance.ShadowFarDistance; pssmSplitDistances[ 3 ] = Map.Instance.ShadowFarDistance; if( pssmSplitDistances[ 1 ] > pssmSplitDistances[ 2 ] ) pssmSplitDistances[ 1 ] = pssmSplitDistances[ 2 ] - .001f; } } if( !RenderSystem.Instance.HasShaderModel3() ) needShadowTechnique = ShadowTechniques.ShadowmapLow; //PSSM is not supported for OpenGL at this time. if( RenderSystem.Instance.IsOpenGL() ) { if( needShadowTechnique == ShadowTechniques.ShadowmapLowPSSM || needShadowTechnique == ShadowTechniques.ShadowmapMediumPSSM || needShadowTechnique == ShadowTechniques.ShadowmapHighPSSM ) { Log.Warning( "At this time Parallel-Split Shadow Map is not supported for OpenGL." ); needShadowTechnique = ShadowTechniques.ShadowmapLow; } } } else if( RenderSystem.Instance.Capabilities.HardwareRenderToTexture ) { needShadowTechnique = ShadowTechniques.ShadowmapLow; ColorValue shadowColor = Map.Instance.ShadowColor; if( shadowColor.Red == shadowColor.Green && shadowColor.Red == shadowColor.Blue ) { textureFormatForDirectionalLight = PixelFormat.L8; textureFormatForSpotLight = PixelFormat.L8; textureFormatForPointLight = PixelFormat.L8; } else { textureFormatForDirectionalLight = PixelFormat.X8R8G8B8; textureFormatForSpotLight = PixelFormat.X8R8G8B8; textureFormatForPointLight = PixelFormat.X8R8G8B8; } //no point light shadows for ffp pointLightMaxTextureCount = 0; //for old card compatibility if( !RenderSystem.Instance.Capabilities.FragmentProgram ) maxTextureSize = 1024; //if( !RenderSystem.Instance.Capabilities.HardwareRenderToTexture ) // maxTextureSize = 512; renderBackFaces = true; } else { needShadowTechnique = ShadowTechniques.None; } //bias { //good idea to adapt bias for each project. float qualityFactor; { if( needShadowTechnique == ShadowTechniques.ShadowmapHigh || needShadowTechnique == ShadowTechniques.ShadowmapHighPSSM || needShadowTechnique == ShadowTechniques.ShadowmapMedium || needShadowTechnique == ShadowTechniques.ShadowmapMediumPSSM ) { qualityFactor = 1.5f; } else { qualityFactor = 1; } } if( RenderSystem.Instance.HasShaderModel3() && RenderSystem.Instance.IsDirect3D() ) { //directional light { //NVIDIA: Depth24 texture format //ATI: Float32 texture format float[] factors = null; switch( needShadowTechnique ) { case ShadowTechniques.ShadowmapLow: factors = new float[] { 1.0f }; break; case ShadowTechniques.ShadowmapMedium: factors = new float[] { 1.5f }; break; case ShadowTechniques.ShadowmapHigh: factors = new float[] { 1.5f }; break; case ShadowTechniques.ShadowmapLowPSSM: factors = new float[] { 1.0f, 1.0f, 1.0f }; break; case ShadowTechniques.ShadowmapMediumPSSM: factors = new float[] { 1.5f, 1.0f, 1.0f }; break; case ShadowTechniques.ShadowmapHighPSSM: factors = new float[] { 1.5f, 1.5f, 1.0f }; break; } float iterationCount = pssm ? 3 : 1; for( int index = 0; index < iterationCount; index++ ) { if( nvidiaHardwareShadows ) { //Depth24 texture format shadowLightBiasDirectionalLight[ index ] = new Vec2( .0001f + .00005f * (float)index, factors[ index ] ); } else { //Float32 texture format shadowLightBiasDirectionalLight[ index ] = new Vec2( .0001f + .00005f * (float)index, factors[ index ] ); } } } //point light { //Float32 texture format (both for NVIDIA and ATI) shadowLightBiasPointLight = new Vec2( .05f * qualityFactor, 0 ); //shadowLightBiasPointLight = new Vec2( .2f * qualityFactor, .5f * qualityFactor ); } //spot light { if( nvidiaHardwareShadows ) { //Depth24 texture format float textureSize = Map.Instance.GetShadowSpotLightTextureSizeAsInteger(); float textureSizeFactor = 1024.0f / textureSize; shadowLightBiasSpotLight = new Vec2( .001f * qualityFactor * textureSizeFactor, .001f * qualityFactor ); } else { //Float32 texture format shadowLightBiasSpotLight = new Vec2( .1f * qualityFactor, 1.0f * qualityFactor ); } } } else { shadowLightBiasDirectionalLight[ 0 ] = new Vec2( .0003f * qualityFactor, 0 ); shadowLightBiasPointLight = new Vec2( .15f * qualityFactor, 0 ); shadowLightBiasSpotLight = new Vec2( .15f * qualityFactor, 0 ); } } } //apply settings to scene manager SceneManager.Instance.ShadowColor = Map.Instance.ShadowColor; SceneManager.Instance.ShadowFarDistance = Map.Instance.ShadowFarDistance; SceneManager.Instance.ShadowCasterRenderBackFaces = renderBackFaces; SceneManager.Instance.ShadowTextureFadeStart = .9f; if( shadowMap ) { SceneManager.Instance.SetShadowTextureSettings( textureFormatForDirectionalLight, Math.Min( Map.Instance.GetShadowDirectionalLightTextureSizeAsInteger(), maxTextureSize ), directionalLightMaxTextureCount, pssm ? 3 : 1, pssmSplitDistances, textureFormatForSpotLight, Math.Min( Map.Instance.GetShadowSpotLightTextureSizeAsInteger(), maxTextureSize ), spotLightMaxTextureCount, textureFormatForPointLight, Math.Min( Map.Instance.GetShadowPointLightTextureSizeAsInteger(), maxTextureSize ), pointLightMaxTextureCount ); SceneManager.Instance.ShadowTextureSelfShadow = textureSelfShadow; for( int n = 0; n < shadowLightBiasDirectionalLight.Length; n++ ) { Vec2 value = shadowLightBiasDirectionalLight[ n ]; SceneManager.Instance.SetShadowLightBias( RenderLightType.Directional, n, value.X, value.Y ); } SceneManager.Instance.SetShadowLightBias( RenderLightType.Point, 0, shadowLightBiasPointLight.X, shadowLightBiasPointLight.Y ); SceneManager.Instance.SetShadowLightBias( RenderLightType.Spot, 0, shadowLightBiasSpotLight.X, shadowLightBiasSpotLight.Y ); } else { SceneManager.Instance.SetShadowTextureSettings( PixelFormat.X8R8G8B8, 8, 0, 0, new float[] { }, PixelFormat.X8R8G8B8, 8, 0, PixelFormat.X8R8G8B8, 8, 0 ); } SceneManager.Instance.ShadowTechnique = needShadowTechnique; //update default caster materials { foreach( HighLevelMaterial material in defaultCasterMaterials ) { if( material != null ) material.UpdateBaseMaterial(); } for( int n = 0; n < 3; n++ ) { HighLevelMaterial material = defaultCasterMaterials[ n ]; SceneManager.Instance.SetShadowTextureDefaultCasterMaterialName( (RenderLightType)n, material != null ? material.Name : "" ); } } }
protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); ShaderBaseMaterial source = (ShaderBaseMaterial)sourceMaterial; //General blending = source.blending; lighting = source.lighting; ambientLighting = source.ambientLighting; doubleSided = source.doubleSided; useNormals = source.useNormals; receiveShadows = source.receiveShadows; receiveSimpleShadows = source.receiveSimpleShadows; alphaRejectFunction = source.alphaRejectFunction; alphaRejectValue = source.alphaRejectValue; alphaToCoverage = source.alphaToCoverage; fadingByDistanceRange = source.fadingByDistanceRange; allowFog = source.allowFog; depthWrite = source.depthWrite; depthTest = source.depthTest; softParticles = source.softParticles; softParticlesFadingLength = source.softParticlesFadingLength; depthOffset = source.depthOffset; halfLambert = source.halfLambert; //Diffuse diffuseColor = source.diffuseColor; diffusePower = source.diffusePower; diffuseScaleDynamic = source.diffuseScaleDynamic; diffuseVertexColor = source.diffuseVertexColor; diffuse1Map.OnClone( source.diffuse1Map ); diffuse2Map.OnClone( source.diffuse2Map ); diffuse3Map.OnClone( source.diffuse3Map ); diffuse4Map.OnClone( source.diffuse4Map ); //Reflection reflectionColor = source.reflectionColor; reflectionPower = source.reflectionPower; reflectionScaleDynamic = source.reflectionScaleDynamic; reflectionMap.OnClone( source.reflectionMap ); reflectionSpecificCubemap = source.ConvertToFullPath( source.ReflectionSpecificCubemap ); reflectionBoxParallaxCorrectedCubemaps = source.reflectionBoxParallaxCorrectedCubemaps; //Emission emissionColor = source.emissionColor; emissionPower = source.emissionPower; emissionScaleDynamic = source.emissionScaleDynamic; emissionMap.OnClone( source.emissionMap ); //Specular specularColor = source.specularColor; specularPower = source.specularPower; specularScaleDynamic = source.specularScaleDynamic; specularMap.OnClone( source.specularMap ); specularShininess = source.specularShininess; //Translucency translucencyColor = source.translucencyColor; translucencyPower = source.translucencyPower; translucencyDynamic = source.translucencyDynamic; translucencyMap.OnClone( source.translucencyMap ); translucencyClearness = source.translucencyClearness; //Height normalMap.OnClone( source.normalMap ); heightMap.OnClone( source.heightMap ); heightFromNormalMapAlpha = source.heightFromNormalMapAlpha; displacementTechnique = source.displacementTechnique; heightScale = source.heightScale; }
protected override void OnClone(HighLevelMaterial sourceMaterial) { base.OnClone(sourceMaterial); }
protected override void OnClone( HighLevelMaterial sourceMaterial ) { base.OnClone( sourceMaterial ); ShaderBaseMaterial source = (ShaderBaseMaterial)sourceMaterial; //General blending = source.blending; lighting = source.lighting; culling = source.culling; useNormals = source.useNormals; receiveShadows = source.receiveShadows; alphaRejectFunction = source.alphaRejectFunction; alphaRejectValue = source.alphaRejectValue; alphaToCoverage = source.alphaToCoverage; fadingByDistanceRange = source.fadingByDistanceRange; allowFog = source.allowFog; depthWrite = source.depthWrite; depthTest = source.depthTest; //Diffuse diffuseColor = source.diffuseColor; diffusePower = source.diffusePower; diffuseScaleDynamic = source.diffuseScaleDynamic; diffuseVertexColor = source.diffuseVertexColor; diffuse1Map.OnClone( source.diffuse1Map ); diffuse2Map.OnClone( source.diffuse2Map ); diffuse3Map.OnClone( source.diffuse3Map ); diffuse4Map.OnClone( source.diffuse4Map ); //Reflection reflectionColor = source.reflectionColor; reflectionPower = source.reflectionPower; reflectionScaleDynamic = source.reflectionScaleDynamic; reflectionMap.OnClone( source.reflectionMap ); reflectionSpecificCubemap = source.reflectionSpecificCubemap; //Emission emissionColor = source.emissionColor; emissionPower = source.emissionPower; emissionScaleDynamic = source.emissionScaleDynamic; emissionMap.OnClone( source.emissionMap ); //Specular specularColor = source.specularColor; specularPower = source.specularPower; specularScaleDynamic = source.specularScaleDynamic; specularMap.OnClone( source.specularMap ); specularShininess = source.specularShininess; //Height normalMap.OnClone( source.normalMap ); heightMap.OnClone( source.heightMap ); heightFromNormalMapAlpha = source.heightFromNormalMapAlpha; heightScale = source.heightScale; }