/// <summary> /// Looks up shortcut references to our effect parameters. /// </summary> void CacheEffectParameters(EnvironmentMapEffect cloneSource) { textureParam = Parameters["Texture"]; environmentMapParam = Parameters["EnvironmentMap"]; environmentMapAmountParam = Parameters["EnvironmentMapAmount"]; environmentMapSpecularParam = Parameters["EnvironmentMapSpecular"]; fresnelFactorParam = Parameters["FresnelFactor"]; diffuseColorParam = Parameters["DiffuseColor"]; emissiveColorParam = Parameters["EmissiveColor"]; eyePositionParam = Parameters["EyePosition"]; fogColorParam = Parameters["FogColor"]; fogVectorParam = Parameters["FogVector"]; worldParam = Parameters["World"]; worldInverseTransposeParam = Parameters["WorldInverseTranspose"]; worldViewProjParam = Parameters["WorldViewProj"]; light0 = new DirectionalLight(Parameters["DirLight0Direction"], Parameters["DirLight0DiffuseColor"], null, (cloneSource != null) ? cloneSource.light0 : null); light1 = new DirectionalLight(Parameters["DirLight1Direction"], Parameters["DirLight1DiffuseColor"], null, (cloneSource != null) ? cloneSource.light1 : null); light2 = new DirectionalLight(Parameters["DirLight2Direction"], Parameters["DirLight2DiffuseColor"], null, (cloneSource != null) ? cloneSource.light2 : null); }
/// <summary> /// Initializes this instance. /// </summary> /// <param name="ginfo"></param> /// <param name="factory"></param> /// <param name="obj"></param> public override void Initialize(GraphicInfo ginfo, GraphicFactory factory, IObject obj) { effect = factory.GetEnvironmentMapEffect(); if(enableLightining) effect.EnableDefaultLighting(); effect.EnvironmentMapAmount = amountDiffuse; base.Initialize(ginfo,factory,obj); }
private static void ApplyMaterial(EnvironmentMapEffect effect, Material material) { effect.DiffuseColor = material.DiffuseColor; effect.EmissiveColor = material.EmissiveColor; if (material.Texture.IsNotNull() && effect.Texture.IsNull()) effect.Texture = material.Texture; }
protected EnvironmentMapEffect(EnvironmentMapEffect cloneSource) : base((Effect)cloneSource) { this.CacheEffectParameters(cloneSource); this.fogEnabled = cloneSource.fogEnabled; this.fresnelEnabled = cloneSource.fresnelEnabled; this.specularEnabled = cloneSource.specularEnabled; this.world = cloneSource.world; this.view = cloneSource.view; this.projection = cloneSource.projection; this.diffuseColor = cloneSource.diffuseColor; this.emissiveColor = cloneSource.emissiveColor; this.ambientLightColor = cloneSource.ambientLightColor; this.alpha = cloneSource.alpha; this.fogStart = cloneSource.fogStart; this.fogEnd = cloneSource.fogEnd; }
private void CacheEffectParameters(EnvironmentMapEffect cloneSource) { this.textureParam = this.Parameters["Texture"]; this.environmentMapParam = this.Parameters["EnvironmentMap"]; this.environmentMapAmountParam = this.Parameters["EnvironmentMapAmount"]; this.environmentMapSpecularParam = this.Parameters["EnvironmentMapSpecular"]; this.fresnelFactorParam = this.Parameters["FresnelFactor"]; this.diffuseColorParam = this.Parameters["DiffuseColor"]; this.emissiveColorParam = this.Parameters["EmissiveColor"]; this.eyePositionParam = this.Parameters["EyePosition"]; this.fogColorParam = this.Parameters["FogColor"]; this.fogVectorParam = this.Parameters["FogVector"]; this.worldParam = this.Parameters["World"]; this.worldInverseTransposeParam = this.Parameters["WorldInverseTranspose"]; this.worldViewProjParam = this.Parameters["WorldViewProj"]; this.light0 = new DirectionalLight(this.Parameters["DirLight0Direction"], this.Parameters["DirLight0DiffuseColor"], (EffectParameter)null, cloneSource != null ? cloneSource.light0 : (DirectionalLight)null); this.light1 = new DirectionalLight(this.Parameters["DirLight1Direction"], this.Parameters["DirLight1DiffuseColor"], (EffectParameter)null, cloneSource != null ? cloneSource.light1 : (DirectionalLight)null); this.light2 = new DirectionalLight(this.Parameters["DirLight2Direction"], this.Parameters["DirLight2DiffuseColor"], (EffectParameter)null, cloneSource != null ? cloneSource.light2 : (DirectionalLight)null); }
/// <summary> /// Creates a new EnvironmentMapEffect by cloning parameter settings from an existing instance. /// </summary> protected EnvironmentMapEffect(EnvironmentMapEffect cloneSource) : base(cloneSource) { CacheEffectParameters(cloneSource); fogEnabled = cloneSource.fogEnabled; fresnelEnabled = cloneSource.fresnelEnabled; specularEnabled = cloneSource.specularEnabled; world = cloneSource.world; view = cloneSource.view; projection = cloneSource.projection; diffuseColor = cloneSource.diffuseColor; emissiveColor = cloneSource.emissiveColor; ambientLightColor = cloneSource.ambientLightColor; alpha = cloneSource.alpha; fogStart = cloneSource.fogStart; fogEnd = cloneSource.fogEnd; }
public override void LoadContent() { base.LoadContent(); // To hacked for now if (!_environmentTextureLoaded && _environmentTextureNames != null) { // Detect the texture size if it doesn't specified if (_environmentTextureSize == 0) { Texture2D firstTexture = YnG.Content.Load<Texture2D>(_environmentTextureNames[0]); _environmentTextureSize = Math.Min(firstTexture.Width, firstTexture.Height); } // Create the environment texture _environmentTexture = new TextureCube(YnG.GraphicsDevice, _environmentTextureSize, _enableTextureMipmap, SurfaceFormat.Color); Texture2D texture = null; // Temp texture Color[] textureData; // Temp textureData array string[] tempTextureNames = new string[6]; // If the texture array has not a size of 6, we replace empty texture by the latest int nbTextures = _environmentTextureNames.Length; for (int i = 0; i < 6; i++) { if (i < nbTextures) // Texture tempTextureNames[i] = _environmentTextureNames[i]; else // Copied texture tempTextureNames[i] = _environmentTextureNames[nbTextures - 1]; // Load the texture and add it to the TextureCube texture = YnG.Content.Load<Texture2D>(tempTextureNames[i]); textureData = new Color[texture.Width * texture.Height]; texture.GetData<Color>(textureData); _environmentTexture.SetData<Color>((CubeMapFace)i, textureData); } // Update the texture names array _environmentTextureNames = tempTextureNames; _environmentTextureLoaded = true; // If the first texture is null we create a dummy texture with the same size of environment texture if (_texture == null) { _texture = YnGraphics.CreateTexture(Color.White, _environmentTextureSize, _environmentTextureSize); _textureLoaded = true; } } if (!_effectLoaded) { _effect = new EnvironmentMapEffect(YnG.GraphicsDevice); _effectLoaded = true; } }
private void CacheEffectParameters(EnvironmentMapEffect cloneSource) { this.textureParam = this.Parameters["Texture"]; this.environmentMapParam = this.Parameters["EnvironmentMap"]; this.environmentMapAmountParam = this.Parameters["EnvironmentMapAmount"]; this.environmentMapSpecularParam = this.Parameters["EnvironmentMapSpecular"]; this.fresnelFactorParam = this.Parameters["FresnelFactor"]; this.diffuseColorParam = this.Parameters["DiffuseColor"]; this.emissiveColorParam = this.Parameters["EmissiveColor"]; this.eyePositionParam = this.Parameters["EyePosition"]; this.fogColorParam = this.Parameters["FogColor"]; this.fogVectorParam = this.Parameters["FogVector"]; this.worldParam = this.Parameters["World"]; this.worldInverseTransposeParam = this.Parameters["WorldInverseTranspose"]; this.worldViewProjParam = this.Parameters["WorldViewProj"]; this.light0 = new DirectionalLight(this.Parameters["DirLight0Direction"], this.Parameters["DirLight0DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light0 : (DirectionalLight) null); this.light1 = new DirectionalLight(this.Parameters["DirLight1Direction"], this.Parameters["DirLight1DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light1 : (DirectionalLight) null); this.light2 = new DirectionalLight(this.Parameters["DirLight2Direction"], this.Parameters["DirLight2DiffuseColor"], (EffectParameter) null, cloneSource != null ? cloneSource.light2 : (DirectionalLight) null); }
protected EnvironmentMapEffect(EnvironmentMapEffect cloneSource) : base((Effect) cloneSource) { this.CacheEffectParameters(cloneSource); this.fogEnabled = cloneSource.fogEnabled; this.fresnelEnabled = cloneSource.fresnelEnabled; this.specularEnabled = cloneSource.specularEnabled; this.world = cloneSource.world; this.view = cloneSource.view; this.projection = cloneSource.projection; this.diffuseColor = cloneSource.diffuseColor; this.emissiveColor = cloneSource.emissiveColor; this.ambientLightColor = cloneSource.ambientLightColor; this.alpha = cloneSource.alpha; this.fogStart = cloneSource.fogStart; this.fogEnd = cloneSource.fogEnd; }
/// <summary> /// Prepare a BasicEffect for rendering /// </summary> /// <param name="effect"></param> protected void PrepareEffect(EnvironmentMapEffect effect) { // Apply the texture if we have one and it differs from the active texture if (effect.Texture != ObjectTexture && ObjectTexture != null) effect.Texture = ObjectTexture; // Set the color and alpha effect.DiffuseColor = ObjectColor.ToVector3(); effect.EmissiveColor = EmissiveColor.ToVector3(); effect.Alpha = (float)ObjectColor.A / 255.0f; // Set other effect properties // Do we have a valid texture? if (effect.Texture != null) { // Yes, so apply the other environment map properties as normal effect.EnvironmentMapAmount = EnvironmentMapAmount; effect.EnvironmentMapSpecular = EnvironmentMapSpecular.ToVector3(); effect.FresnelFactor = FresnelFactor; } else { // No, so make the object completely reflective. // Any texture set by other objects will remain but will be entirely hidden by the environment map effect.EnvironmentMapAmount = 1.0f; effect.EnvironmentMapSpecular = Vector3.Zero; effect.FresnelFactor = 0.0f; } // Apply the transformation matrix effect.World = Transformation; // Now the effect is ready for the derived class to actually draw the object }
public override void Load() { base.Load(); #if DEBUG Engine.Core.Graphics.Utils.BoundingSphereRenderer.InitializeGraphics(Scene.GraphicsDevice, Id); Engine.Core.Graphics.Utils.TrianglesRenderer.InitializeGraphics(Scene.GraphicsDevice, Triangles, Id); #endif _effect = new EnvironmentMapEffect(Scene.GraphicsDevice); _environment = Scene.Content.Load<TextureCube>(_environmentTextureAssetName); }
private DefaultShaderType DetermineEffect( bool createNewEffect, Effect effectToTest ) { #region Determine precendence between effects float skinningPrecedence = mPrecedenceTable["SkinnedEffect"]; float dualTexturePrecedence = mPrecedenceTable["DualTextureEffect"]; float environmentMappingPrecedence = mPrecedenceTable["EnvironmentMapEffect"]; float basicEffectPrecedence = mPrecedenceTable["BasicEffect"]; #endregion #region Determining the possible types of Effect #region Check for key information for determining possible effect types Texture2D tex = Texture2; Matrix[] transforms = BoneTransforms; #if !MONOGAME TextureCube cube = CubeMap; #endif if (tex == null) { dualTexturePrecedence = float.MinValue; } #if !MONOGAME if (cube == null) { environmentMappingPrecedence = float.MinValue; } #endif if (transforms == null) { skinningPrecedence = float.MinValue; } #endregion // Three possible outcomes. If its a lower precedence than any // of it's competitors, it will lose out. // If it's greater than the others, it will win, // If it's equal to one another, well in technical terms, we guess. // ... // WELCOME TO IF STATEMENT HELL #if !MONOGAME #region Skinning Shader determination... Don't look. Ever. //... I said don't look. Sigh if( skinningPrecedence >= environmentMappingPrecedence ) { if( skinningPrecedence >= dualTexturePrecedence ) { if( skinningPrecedence > basicEffectPrecedence ) { if( createNewEffect ) { // Create a skinning shader mSkinnedEffect = new SkinnedEffect( FlatRedBallServices.GraphicsDevice ); SetSkinningEffectParameters(); } return DefaultShaderType.Skinned; } } } #endregion #region Environment Mapping Determination if( environmentMappingPrecedence >= dualTexturePrecedence ) { if( environmentMappingPrecedence >= basicEffectPrecedence ) { if( createNewEffect ) { // Create Environment map mEnvironmentMapEffect = new EnvironmentMapEffect(FlatRedBallServices.GraphicsDevice); SetEnvironmentMapEffectParameters(); } return DefaultShaderType.EnvironmentMapped; } } #endregion #region Dual Texture determination if( dualTexturePrecedence >= basicEffectPrecedence ) { // Create Dual Texture if( createNewEffect ) { mDualTextureEffect = new DualTextureEffect( FlatRedBallServices.GraphicsDevice ); SetDualTextureEffectParameters(); } return DefaultShaderType.DualTexture; } #endregion #endif #region Basic Shader determination // Create a basic Shader if( createNewEffect ) { mBasicEffect = new BasicEffect(FlatRedBallServices.GraphicsDevice); SetBasicEffectParameters(); } return DefaultShaderType.Basic; #endregion #endregion }
public GenericEffect( Effect effectToAssimilate ) :this() { /* DefaultShaderType type = DetermineEffect( false, effectToAssimilate ); if( type == DefaultShaderType.Basic ) { mBasicEffect = (BasicEffect)effectToAssimilate; } else if( type == DefaultShaderType.DualTexture ) { mDualTextureEffect = (DualTextureEffect)effectToAssimilate; } else if( type == DefaultShaderType.EnvironmentMapped ) { mEnvironmentMapEffect = (EnvironmentMapEffect)effectToAssimilate; } else if( type == DefaultShaderType.Skinned ) { mSkinnedEffect = (SkinnedEffect)effectToAssimilate; } */ if ( effectToAssimilate is BasicEffect ) { mBasicEffect = effectToAssimilate as BasicEffect; } else if (effectToAssimilate is AlphaTestEffect) { mAlphaTestEffect = effectToAssimilate as AlphaTestEffect; } #if !MONOGAME else if (effectToAssimilate is DualTextureEffect) { mDualTextureEffect = effectToAssimilate as DualTextureEffect; } else if (effectToAssimilate is EnvironmentMapEffect) { mEnvironmentMapEffect = effectToAssimilate as EnvironmentMapEffect; } else if (effectToAssimilate is SkinnedEffect) { mSkinnedEffect = effectToAssimilate as SkinnedEffect; } #endif }
public GenericEffect( DefaultShaderType type ) :this() { if( type != DefaultShaderType.Determine ) { if( type == DefaultShaderType.Basic ) { mBasicEffect = new BasicEffect( FlatRedBallServices.GraphicsDevice ); } else if (type == DefaultShaderType.AlphaTest) { mAlphaTestEffect = new AlphaTestEffect(FlatRedBallServices.GraphicsDevice); } else if (type == DefaultShaderType.DualTexture) { #if MONOGAME throw new NotImplementedException(); #else mDualTextureEffect = new DualTextureEffect(FlatRedBallServices.GraphicsDevice); #endif } else if (type == DefaultShaderType.EnvironmentMapped) { #if MONOGAME throw new NotImplementedException(); #else mEnvironmentMapEffect = new EnvironmentMapEffect(FlatRedBallServices.GraphicsDevice); #endif } else if (type == DefaultShaderType.Skinned) { #if MONOGAME throw new NotImplementedException(); #else mSkinnedEffect = new SkinnedEffect(FlatRedBallServices.GraphicsDevice); #endif } } }