internal static void SetTexture(this Effect effect, Texture2D texture) { if (effect is BasicEffect) { BasicEffect source = effect as BasicEffect; source.Texture = texture; source.TextureEnabled = texture != null; } else if (effect is SkinnedEffect) { SkinnedEffect source = effect as SkinnedEffect; source.Texture = texture; } else if (effect is EnvironmentMapEffect) { EnvironmentMapEffect source = effect as EnvironmentMapEffect; source.Texture = texture; } else if (effect is DualTextureEffect) { DualTextureEffect source = effect as DualTextureEffect; source.Texture = texture; } else if (effect is AlphaTestEffect) { AlphaTestEffect source = effect as AlphaTestEffect; source.Texture = texture; } }
public override void Awake() { base.Awake(); renderQueue /= 10; UInt32 uTile = 0; bool hasLightMaps = false; for (UInt32 v = 0; v < tilesV; ++v) { for (UInt32 u = 0; u < tilesU; ++u) { if (quadTreeTiles[uTile].vertices != null && quadTreeTiles[uTile].indices != null) { hasLightMaps |= quadTreeTiles[uTile].useLightMap; quadTreeTiles[uTile].InitializeBuffers(Application.Instance.GraphicsDevice); if (sharedMaterials.Length > quadTreeTiles[uTile].indexBuffer.Length) { throw new Exception("The static batch renderer does not have enough submeshes for all materials!"); } } ++uTile; } } if (Application.Instance != null) { if (dtEffect == null) { dtEffect = new DualTextureEffect(Application.Instance.GraphicsDevice); dtEffect.VertexColorEnabled = false; } } }
internal static Texture2D GetTexture(this Effect sourceEffect) { Texture2D texture = null; if (sourceEffect is BasicEffect) { BasicEffect source = sourceEffect as BasicEffect; texture = source.Texture; } else if (sourceEffect is SkinnedEffect) { SkinnedEffect source = sourceEffect as SkinnedEffect; texture = source.Texture; } else if (sourceEffect is EnvironmentMapEffect) { EnvironmentMapEffect source = sourceEffect as EnvironmentMapEffect; texture = source.Texture; } else if (sourceEffect is DualTextureEffect) { DualTextureEffect source = sourceEffect as DualTextureEffect; texture = source.Texture; } else if (sourceEffect is AlphaTestEffect) { AlphaTestEffect source = sourceEffect as AlphaTestEffect; texture = source.Texture; } return(texture); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a SpriteBatch and Font for Text rendering spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load <SpriteFont>("Font"); // Create a BasicEffect, which will be used to render the primitive. pitchBasicEffect = new BasicEffect(GraphicsDevice); pitchBasicEffect.LightingEnabled = false; pitchBasicEffect.PreferPerPixelLighting = false; pitchBasicEffect.FogEnabled = false; pitchBasicEffect.VertexColorEnabled = false; // With a tiling stripe texture, we can tile in any direction Vector2 Tiling1 = new Vector2(PLANE_TILING / 3.0f, PLANE_TILING / 3.0f); Vector2 Tiling2 = new Vector2(PLANE_TILING, PLANE_TILING); pitchPrimitive = new PlanePrimitiveDualTextured(GraphicsDevice, PLANE_SIZE, Tiling1, Tiling2); pitchStripePrimitive = new PlanePrimitiveTextured(GraphicsDevice, PLANE_SIZE); pitchDualTextureEffect = new DualTextureEffect(GraphicsDevice); pitchStripeEffect = new AlphaTestEffect(GraphicsDevice); spherePrimitive = new SpherePrimitiveTextured(GraphicsDevice, SOCCERBALL_DIAMETER, 6); // Acquire the textures for the pitch // using the content manager (this.Content) to load game content here pitchBaseTexture = Content.Load <Texture2D>("Base"); pitchDetailTexture = Content.Load <Texture2D>("Detail"); pitchStripeTexture = Content.Load <Texture2D>("Stripe2"); soccerballTexture = Content.Load <Texture2D>("Soccerball"); // The eye and eyeBall views are constant (we just lerp between them) so set them up here. eyeAtStart = new Vector3(0.0f, PLANE_SIZE / 10.0f, -PLANE_SIZE * 0.75f); eyeAtBall = new Vector3(0.0f, 3 * SOCCERBALL_DIAMETER, -SOCCERBALL_DIAMETER * 0.75f); // Setup Transparent White for blending transparentWhite = Color.White; transparentWhite.A = 250; // 250 provides a pleasing additive blend. // Create a RasterizerState object for Shadow rendering with depth biasing shadowRasterizerState = new RasterizerState(); shadowRasterizerState.DepthBias = -SOCCERBALL_DEPTH_OFFSET; // Initialize the projection matrix here as it never changes float aspect = GraphicsDevice.Viewport.AspectRatio; projection = Matrix.CreatePerspectiveFieldOfView( (float)(System.Math.PI) / 4.0F, aspect, 2.0F, FAR_CLIP); // Clean up any load time generated garbage GC.Collect(); }
public override void LoadContent() { base.LoadContent(); if (!_secondTextureLoaded && _secondTextureName != String.Empty) { _secondTexture = YnG.Content.Load <Texture2D>(_secondTextureName); _secondTextureLoaded = true; } if (!_effectLoaded) { _effect = new DualTextureEffect(YnG.GraphicsDevice); _effectLoaded = true; } }
public override void SetParameters(Camera3D camera) { DualTextureEffect bEffect = this.Effect as DualTextureEffect; bEffect.View = camera.View; bEffect.Projection = camera.Projection; bEffect.DiffuseColor = this.DiffuseColor.ToVector3(); bEffect.Alpha = this.Alpha; if (this.Texture != null && this.texture2 != null) { bEffect.Texture = this.Texture; bEffect.Texture2 = this.texture2; } base.SetParameters(camera); }
private void DesenharModelo(Model m, Matrix world, DualTextureEffect be) { be.World = world; be.CurrentTechnique.Passes[0].Apply(); foreach (ModelMesh mm in m.Meshes) { foreach (ModelMeshPart mmp in mm.MeshParts) { GraphicsDevice.SetVertexBuffer(mmp.VertexBuffer, mmp.VertexOffset); GraphicsDevice.Indices = mmp.IndexBuffer; GraphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, mmp.NumVertices, mmp.StartIndex, mmp.PrimitiveCount); } } }
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 RendererXNA(GraphicsDevice device) { this.modelMatrixStack.Push(Matrix.Identity); this.projMat = Matrix.Identity; this.viewMat = Matrix.Identity; this.basicEffect = new BasicEffect(device); this.multiTexture = new DualTextureEffect(device); this.skinnedEffect = new SkinnedEffect(device); this.skinnedEffect.WeightsPerVertex = 4; this.alphaTestEffect = new AlphaTestEffect(device); this.device = device; this.numTex = 0; this.m_cachedFog = (Fog)null; this.initBlendStates(); this.initRasterStates(); this.initDepthStates(); this.initSamplerStates(); }
public override void Update(BaseCamera camera, ref Matrix world) { // Update matrices base.Update(camera, ref world); DualTextureEffect dualTextureEffect = (DualTextureEffect)_effect; // Fog UpdateFog(dualTextureEffect); // Textures dualTextureEffect.Texture = _texture; dualTextureEffect.Texture2 = _secondTexture; // Lights dualTextureEffect.DiffuseColor = new Vector3(_diffuseColor.X, _diffuseColor.Y, _diffuseColor.Z) * _diffuseIntensity; dualTextureEffect.Alpha = _alphaColor; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Calculate the screen aspect ratio float aspectRatio = (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height; // Create a projection matrix Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000.0f); // Calculate a view matrix (where we are looking from and to) Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero, Vector3.Up); // Create and initialize the effect _effect = new DualTextureEffect(GraphicsDevice); _effect.VertexColorEnabled = false; _effect.Projection = projection; _effect.View = view; _effect.World = Matrix.Identity; base.Initialize(); }
/// <summary> /// Creates a new DualTextureEffect by cloning parameter settings from an existing instance. /// </summary> protected DualTextureEffect(DualTextureEffect cloneSource) : base(cloneSource) { CacheEffectParameters(); fogEnabled = cloneSource.fogEnabled; vertexColorEnabled = cloneSource.vertexColorEnabled; world = cloneSource.world; view = cloneSource.view; projection = cloneSource.projection; diffuseColor = cloneSource.diffuseColor; alpha = cloneSource.alpha; fogStart = cloneSource.fogStart; fogEnd = cloneSource.fogEnd; }
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 } } }
/// <summary> /// Prepare a BasicEffect for rendering /// </summary> /// <param name="effect"></param> protected void PrepareEffect(DualTextureEffect effect) { if (effect.Texture != ObjectTexture) { effect.Texture = ObjectTexture; } if (effect.Texture2 != ObjectTexture2) { effect.Texture2 = ObjectTexture2; } // Set the color and alpha effect.DiffuseColor = ObjectColor.ToVector3(); effect.Alpha = (float)ObjectColor.A / 255.0f; // Apply the transformation matrix effect.World = Transformation; // Now the effect is ready for the derived class to actually draw the object }
/// <summary> /// Draws the primitive model, using a DualTextureEffect shader. /// </summary> public void DrawDualTextured(DualTextureEffect dtEffect, Matrix world, Matrix view, Matrix projection, Color color) { // Set DrawDualTextured effect parameters. dtEffect.World = world; dtEffect.View = view; dtEffect.Projection = projection; dtEffect.DiffuseColor = color.ToVector3(); dtEffect.Alpha = color.A / 255.0f; if (color.A < 255) { dtEffect.GraphicsDevice.DepthStencilState = DepthStencilState.None; dtEffect.GraphicsDevice.BlendState = BlendState.Additive; } else { dtEffect.GraphicsDevice.DepthStencilState = DepthStencilState.Default; dtEffect.GraphicsDevice.BlendState = BlendState.Opaque; } // Draw the model, using DualTextureEffect. Draw(dtEffect); }
public DualTextureMaterial(GraphicsDevice graphics) { GraphicsDevice = graphics; effect = GraphicsResources <DualTextureEffect> .GetInstance(graphics, typeof(DualTextureMaterial)); }
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 }
/// <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.GetDualTextureEffect(); base.Initialize(ginfo, factory, obj); }
internal static void CopyMaterialsFrom(this Effect effect, Effect sourceEffect) { if (effect == null || sourceEffect == null) { return; } Vector3 DiffuseColor = Vector3.One; Vector3 SpecularColor = Vector3.Zero; Vector3 EmissiveColor = Vector3.Zero; float SpecularPower = 16; float Alpha = 1; Texture2D Texture = sourceEffect.GetTexture(); if (Texture != null) { effect.SetTexture(Texture); } // Extract from source if (sourceEffect is BasicEffect) { BasicEffect source = sourceEffect as BasicEffect; DiffuseColor = source.DiffuseColor; EmissiveColor = source.EmissiveColor; SpecularColor = source.SpecularColor; SpecularPower = source.SpecularPower; Alpha = source.Alpha; } else if (sourceEffect is SkinnedEffect) { SkinnedEffect source = sourceEffect as SkinnedEffect; DiffuseColor = source.DiffuseColor; EmissiveColor = source.EmissiveColor; SpecularColor = source.SpecularColor; SpecularPower = source.SpecularPower; Alpha = source.Alpha; } else if (sourceEffect is EnvironmentMapEffect) { EnvironmentMapEffect source = sourceEffect as EnvironmentMapEffect; DiffuseColor = source.DiffuseColor; EmissiveColor = source.EmissiveColor; Alpha = source.Alpha; } else if (sourceEffect is DualTextureEffect) { DualTextureEffect source = sourceEffect as DualTextureEffect; DiffuseColor = source.DiffuseColor; Alpha = source.Alpha; } else if (sourceEffect is AlphaTestEffect) { AlphaTestEffect source = sourceEffect as AlphaTestEffect; DiffuseColor = source.DiffuseColor; Alpha = source.Alpha; } // Apply to target if (effect is BasicEffect) { BasicEffect target = effect as BasicEffect; target.DiffuseColor = DiffuseColor; target.EmissiveColor = EmissiveColor; target.SpecularColor = SpecularColor; target.SpecularPower = SpecularPower; target.Alpha = Alpha; } else if (effect is SkinnedEffect) { SkinnedEffect target = effect as SkinnedEffect; target.DiffuseColor = DiffuseColor; target.EmissiveColor = EmissiveColor; target.SpecularColor = SpecularColor; target.SpecularPower = SpecularPower; target.Alpha = Alpha; } else if (effect is EnvironmentMapEffect) { EnvironmentMapEffect target = effect as EnvironmentMapEffect; target.DiffuseColor = DiffuseColor; target.EmissiveColor = EmissiveColor; target.Alpha = Alpha; } else if (effect is DualTextureEffect) { DualTextureEffect target = effect as DualTextureEffect; target.DiffuseColor = DiffuseColor; target.Alpha = Alpha; } else if (effect is AlphaTestEffect) { AlphaTestEffect target = effect as AlphaTestEffect; target.DiffuseColor = DiffuseColor; target.Alpha = Alpha; } }