public StencilSolidEffect(Effect effect) { _effect = effect; _pass = _effect.CurrentTechnique.Passes[0]; _projection = effect.Parameters["Projection"]; _transformation = effect.Parameters["Transformation"]; }
public override void LoadContent() { this.pointLightEffect = this.Content.Load<Effect>("System/Effects/PointLight"); this.pointLightEffect.CurrentTechnique = this.pointLightEffect.Techniques[0]; this.pointLightModel = this.Content.Load<Model>("System/Models/PointLight"); }
public override void Draw(SpriteBatch sb, Effect effect) { if (myModel != null)//don't do anything if the model is null { // Copy any parent transforms. Matrix worldMatrix = Matrix.CreateScale(scale) * Matrix.CreateTranslation(Position); // Draw the model. A model can have multiple meshes, so loop. foreach (ModelMesh mesh in myModel.Meshes) { // This is where the mesh orientation is set, as well as our camera and projection. foreach (ModelMeshPart part in mesh.MeshParts) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { part.Effect = effect; effect.Parameters["World"].SetValue(mesh.ParentBone.Transform * worldMatrix); effect.Parameters["ModelTexture"].SetValue(myTexture); Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * worldMatrix)); } } // Draw the mesh, using the effects set above. mesh.Draw(); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="key">key name</param> /// <param name="assetName">asset name</param> /// <param name="resource">effect resource</param> public GameResourceEffect(string key, string assetName, Effect resource) : base(key, assetName) { this.effect = resource; this.resource = (object)this.effect; }
public WheelMenu( MenuScreen screen, Camera camera, float wheelScale, float screenScale, float startX, float activeX, float finishX, float y) : base(screen, Vector2.Zero) { this.wheelScale = wheelScale; scaleMatrix = Matrix.CreateScale( wheelScale ); this.camera = camera; angle = MathHelper.PiOver4; TransitionOnPosition = new Vector2( startX, y ); Position = new Vector2( activeX, y ); TransitionOffPosition = new Vector2( finishX, y ); rotateSpring = new SpringInterpolater( 1, 50, SpringInterpolater.GetCriticalDamping( 50 ) ); lastX = startX; ContentManager content = screen.ScreenManager.Game.Content; entryEffect = content.Load<Effect>( "Effects/basic" ).Clone( Screen.ScreenManager.GraphicsDevice ); entryEffect.CurrentTechnique = entryEffect.Techniques["DiffuseColor"]; entryEffect.Parameters["LightingEnabled"].SetValue( false ); entryWorldEffectParameter = entryEffect.Parameters["World"]; entryViewEffectParameter = entryEffect.Parameters["View"]; entryProjectionEffectParameter = entryEffect.Parameters["Projection"]; entryDiffuseEffectParameter = entryEffect.Parameters["DiffuseMap"]; wheelModel = content.Load<CustomModel>( "Models/hamsterWheel" ); foreach ( CustomModel.ModelPart part in wheelModel.ModelParts ) { part.Effect.CurrentTechnique = part.Effect.Techniques["Color"]; part.Effect.Parameters["Color"].SetValue( new Color( Color.LightGray, 0 ).ToVector4() ); } }
public void LoadContent() { #if gradient generateTextureEffect = game.Content.Load<Effect>(@"effects\GenerateTerrainTextureGradient"); gradientTexture = game.Content.Load<Texture2D>(@"textures\gradient_01"); generateTextureEffect.Parameters["gradient"].SetValue(gradientTexture); #else string[] textureNames = { "dirt_01", "dirt_03", "sand_02", "sand_03", "grass_01", "grass_02", "grass_03", "water_01", "stone_02", "stone_03", "snow_01", "snow_03" }; generateTextureEffect = game.Content.Load<Effect>(@"effects\GenerateTerrainTexturePack"); slopemapTexture = game.Content.Load<Texture2D>(@"textures\slopemap"); // load diffuse textures textures = new Texture2D[textureNames.Length]; for (int i = 0; i < textures.Length; i++) textures[i] = game.Content.Load<Texture2D>(@"textures\" + textureNames[i]); #endif // texture declaration vertexPositionTexture = VertexPositionTexture.VertexDeclaration; // new VertexDeclaration(device, VertexPositionTexture.VertexElements); }
public CloudLayerRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); if (graphicsService.GraphicsDevice.GraphicsProfile == GraphicsProfile.Reach) throw new NotSupportedException("The CloudLayerRenderer does not support the Reach profile."); _effect = graphicsService.Content.Load<Effect>("DigitalRune/Sky/CloudLayer"); _parameterView = _effect.Parameters["View"]; _parameterProjection = _effect.Parameters["Projection"]; _parameterSunDirection = _effect.Parameters["SunDirection"]; _parameterSkyCurvature = _effect.Parameters["SkyCurvature"]; _parameterTextureMatrix = _effect.Parameters["Matrix0"]; _parameterNumberOfSamples = _effect.Parameters["NumberOfSamples"]; _parameterSampleDistance = _effect.Parameters["SampleDistance"]; _parameterScatterParameters = _effect.Parameters["ScatterParameters"]; _parameterHorizonFade = _effect.Parameters["HorizonFade"]; _parameterSunLight = _effect.Parameters["SunLight"]; _parameterAmbientLight = _effect.Parameters["AmbientLight"]; _parameterTexture = _effect.Parameters["NoiseTexture0"]; _passCloudRgbLinear = _effect.Techniques[0].Passes["CloudRgbLinear"]; _passCloudAlphaLinear = _effect.Techniques[0].Passes["CloudAlphaLinear"]; _passCloudRgbGamma = _effect.Techniques[0].Passes["CloudRgbGamma"]; _passCloudAlphaGamma = _effect.Techniques[0].Passes["CloudAlphaGamma"]; _passOcclusionRgb = _effect.Techniques[0].Passes["OcclusionRgb"]; _passOcclusionAlpha = _effect.Techniques[0].Passes["OcclusionAlpha"]; // We render a spherical patch into the sky. But any mesh which covers the top // hemisphere works too. //_submesh = MeshHelper.CreateSpherePatch(graphicsService.GraphicsDevice, 1, 1.1f, 10); _submesh = MeshHelper.CreateBox(graphicsService.GraphicsDevice); _queryGeometry = new Vector3F[4]; }
public Terrain(GraphicsDevice gd, GraphicsDeviceManager gdm, Effect e, MazeGame m) { device = gd; graphics = gdm; effect = e; instance = m; }
public void SetSpotLightParameters(SpotLight light, Microsoft.Xna.Framework.Graphics.Effect effect, Vector3 cameraPos) { bool shadowed = light.Shadowed && this.shadowMapIndices.ContainsKey(light); effect.CurrentTechnique = effect.Techniques[shadowed ? "SpotLightShadowed" : "SpotLight"]; if (shadowed) { effect.Parameters["ShadowMap" + Model.SamplerPostfix].SetValue(this.spotShadowMaps[this.shadowMapIndices[light]]); effect.Parameters["ShadowMapSize"].SetValue(this.spotShadowMapSize); } float horizontalScale = (float)Math.Sin(light.FieldOfView * 0.5f) * light.Attenuation; float depthScale = (float)Math.Cos(light.FieldOfView * 0.5f) * light.Attenuation; effect.Parameters["SpotLightViewProjectionMatrix"].SetValue(Matrix.CreateTranslation(cameraPos) * light.ViewProjection); effect.Parameters["SpotLightPosition"].SetValue(light.Position - cameraPos); Matrix rotation = Matrix.CreateFromQuaternion(light.Orientation); rotation.Forward *= -1.0f; effect.Parameters["SpotLightDirection"].SetValue(rotation.Forward); effect.Parameters["WorldMatrix"].SetValue(Matrix.CreateScale(horizontalScale, horizontalScale, depthScale) * rotation * Matrix.CreateTranslation(light.Position - cameraPos)); effect.Parameters["SpotLightRadius"].SetValue(depthScale); effect.Parameters["SpotLightColor"].SetValue(light.Color); effect.Parameters["Cookie" + Model.SamplerPostfix].SetValue(light.CookieTexture); }
static Effect GetSharedEffect(GraphicsDevice graphics) { if (sharedEffect == null) sharedEffect = new Effect(graphics, effectCode); return sharedEffect; }
public void Draw(SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Effect effect) { foreach (Effect e in m_lAllEffects) { e.Draw(batch, effect); } }
public static void Draw_Box(Vector2 position, float width, float height, Color c, SpriteBatch b, float rotation = 0, byte alpha = 255, Effect e = null, bool wrong = false) { Vector2 topLeft = new Vector2(position.X - (width / 2), position.Y - (height / 2)); Vector2 bottomRight = new Vector2(position.X + (width / 2), position.Y + (height / 2)); Draw_Box(topLeft, bottomRight, c, b, rotation, alpha, e, wrong); }
public Terrain(float CellSize, float Height, float TextureTiling, int size, Vector3 Position, Vector3 LightDirection, GraphicsDevice GraphicsDevice, Effect effect, Texture2D BaseTexture, Type type = Type.Flat, float terrainOffset = 0, Texture2D RedTexture = null, Texture2D GreenTexture = null, Texture2D WeightTexture = null) { this.type = type; this.size = this.width = this.length = size; this.cellSize = CellSize; this.height = Height; this.Position = Position; this.baseTexture = BaseTexture; this.redTexture = RedTexture; this.greenTexture = GreenTexture; this.weightTexture = WeightTexture; this.textureTiling = TextureTiling; this.lightDirection = LightDirection; this.terrainOffset = terrainOffset; this.PersistantRot = Matrix.Identity; //this.GraphicsDevice = GraphicsDevice; this.LightPosition = new Vector3(0, -2500000f, 0); this.waterSphere = new BoundingSphere(Vector3.Zero, PlanetRadius + Planet.HeightMag); nVertices = width * length; //2 tris per cell, 3 indices per tris nIndices = (width - 1) * (length - 1) * 6; this.effect = effect; //vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionNormalTexture), nVertices, BufferUsage.WriteOnly); //indexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, nIndices, BufferUsage.WriteOnly); }
//-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="CubeMapShadowMaskRenderer"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public CubeMapShadowMaskRenderer(IGraphicsService graphicsService) { if (graphicsService == null) throw new ArgumentNullException("graphicsService"); _effect = graphicsService.Content.Load<Effect>("DigitalRune/Deferred/CubeMapShadowMask"); _parameterViewInverse = _effect.Parameters["ViewInverse"]; _parameterFrustumCorners = _effect.Parameters["FrustumCorners"]; _parameterGBuffer0 = _effect.Parameters["GBuffer0"]; _parameterParameters0 = _effect.Parameters["Parameters0"]; _parameterParameters1 = _effect.Parameters["Parameters1"]; _parameterParameters2 = _effect.Parameters["Parameters2"]; _parameterLightPosition = _effect.Parameters["LightPosition"]; _parameterShadowView = _effect.Parameters["ShadowView"]; _parameterJitterMap = _effect.Parameters["JitterMap"]; _parameterShadowMap = _effect.Parameters["ShadowMap"]; _parameterSamples = _effect.Parameters["Samples"]; Debug.Assert(_parameterSamples.Elements.Count == _samples.Length); // TODO: Use struct parameter. Not yet supported in MonoGame. // Struct effect parameters are not yet supported in the MonoGame effect processor. //var parameterShadow = _effect.Parameters["ShadowParam"]; //_parameterNear = parameterShadow.StructureMembers["Near"]; //... }
public void InitTerrain(Texture2D terrainHeightMap, Effect terrainEffect) { TerrainEffect = terrainEffect; SetHeightData(terrainHeightMap); SetVerts(); SetIndices(); }
public DepthMapEffect(Effect cloneSource) : base(cloneSource) { world = Parameters["World"]; view = Parameters["View"]; projection = Parameters["Projection"]; }
public InstancedModelDrawer(Game game) : base(game) { var resourceContentManager = new ResourceContentManager(game.Services, DrawerResource.ResourceManager); #if WINDOWS instancingEffect = resourceContentManager.Load<Effect>("InstancedEffect"); #else instancingEffect = resourceContentManager.Load<Effect>("InstancedEffectXbox"); #endif //instancingEffect = game.Content.Load<Effect>("InstancedEffect"); worldTransformsParameter = instancingEffect.Parameters["WorldTransforms"]; textureIndicesParameter = instancingEffect.Parameters["TextureIndices"]; viewParameter = instancingEffect.Parameters["View"]; projectionParameter = instancingEffect.Parameters["Projection"]; instancingEffect.Parameters["LightDirection1"].SetValue(Vector3.Normalize(new Vector3(.8f, -1.5f, -1.2f))); instancingEffect.Parameters["DiffuseColor1"].SetValue(new Vector3(.66f, .66f, .66f)); instancingEffect.Parameters["LightDirection2"].SetValue(Vector3.Normalize(new Vector3(-.8f, 1.5f, 1.2f))); instancingEffect.Parameters["DiffuseColor2"].SetValue(new Vector3(.3f, .3f, .5f)); instancingEffect.Parameters["AmbientAmount"].SetValue(.5f); instancingEffect.Parameters["Colors"].SetValue(colors); }
public Emitter(List<Texture2D> texture, Vector2 pos, Texture2D EmitterTexture, Effect color, Vector2 particelSize, Vector2 particelPower, List<Vector2> emitterAngel, Vector2 emitterRange, float particelAmount, float spawnTime, float startParticel, Vector2 lifeDrain, Vector2 lifeTime, Vector2 stayOnMax, Bewegungsprofile bewegung, Spawnprofile spawnprofile) { this.ParticelStayOnMax = stayOnMax; this.spawnprofile = spawnprofile; this.startParticel = startParticel; this.bewegung = new BewegungsHandler(); this.ParticelLifeTime = lifeTime; this.ParticelLifeDrain = lifeDrain; this.EmitterAngel = emitterAngel; this.EmitterRange = emitterRange; this.EmitterTexture = EmitterTexture; this.Position = pos; this.ParticelSize = particelSize; this.ParticelTexture = texture; this.particels = new List<Particel>(); this.PerticelPower = particelPower; this.ParticelSize = particelSize; this.r = new Random(); this.color = color; this.EmitterMaxParticel = particelAmount; this.EmitterUpdate = spawnTime; this.Origin = new Vector2(this.EmitterTexture.Width / 2, this.EmitterTexture.Height / 2); this.bewegungsprofil = bewegung; this.go = false; Start(); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); bloomExtractEffect = this._assetManager.BloomExtractEffect; bloomCombineEffect = this._assetManager.BloomCombineEffect; gaussianBlurEffect = this._assetManager.GaussianBlurEffect; // Look up the resolution and format of our main backbuffer. PresentationParameters pp = GraphicsDevice.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; SurfaceFormat format = pp.BackBufferFormat; // Create a texture for rendering the main scene, prior to applying bloom. sceneRenderTarget = new RenderTarget2D(GraphicsDevice, width, height, false, format, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); // Create two rendertargets for the bloom processing. These are half the // size of the backbuffer, in order to minimize fillrate costs. Reducing // the resolution in this way doesn't hurt quality, because we are going // to be blurring the bloom images in any case. width /= 2; height /= 2; renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, false, format, DepthFormat.None); renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, false, format, DepthFormat.None); }
public NegatizeEffect(PostProcessor processor) : base(processor) { negatizeEffect = processor.Content.Load<Effect>("Effects/Negatize"); negatizeEffect.Parameters["halfPixel"].SetValue(new Vector2(0.5f / (float)processor.Device.PresentationParameters.BackBufferWidth, 0.5f / (float)processor.Device.PresentationParameters.BackBufferHeight)); }
protected void sync_effect_matrices(Effect e) { var e_ = e as BasicEffect; e_.View = camera.view; e_.Projection = camera.projection; e_.World = world; }
public Hole(Texture2D texture, List<List<Vector3>> points, Effect e) { this.texture = texture; // worldRectangle = new Rectangle((int)WorldPosition.X, (int)WorldPosition.Y, texture.Width, texture.Height); effect = e; setUpVertices(points); }
public void SetPointLightParameters(PointLight light, Microsoft.Xna.Framework.Graphics.Effect effect, Vector3 cameraPos) { effect.Parameters["WorldMatrix"].SetValue(Matrix.CreateScale(light.Attenuation) * Matrix.CreateTranslation(light.Position - cameraPos)); effect.Parameters["PointLightPosition"].SetValue(light.Position - cameraPos); effect.Parameters["PointLightRadius"].SetValue(light.Attenuation); effect.Parameters["PointLightColor"].SetValue(light.Color); }
public void LoadContent() { generateTerrainEffect = game.Content.Load<Effect>(@"effects\GenerateSphereNode"); // texture declaration vertexPositionTexture = VertexPositionTexture.VertexDeclaration; // new VertexDeclaration(device, VertexPositionTexture.VertexElements); }
/// <summary> /// Creates an InstanceFactory used to create new InstanceEntity instances. /// </summary> /// <param name="source">The mesh data information used to create InstanceEntity instances.</param> /// <param name="shader">The shader shared accross all instances</param> /// <returns></returns> public InstanceFactory CreateInstanceFactory(IInstanceSource source, Effect shader) { var instanceFactory = new InstanceFactory(SunBurnCoreSystem.Instance.GraphicsDeviceManager.GraphicsDevice, source, shader); _instanceFactories.Add(instanceFactory); return instanceFactory; }
public void Draw(Effect effect, Space space) { contactLines.Clear(); int contactCount = 0; foreach (var pair in space.NarrowPhase.Pairs) { var pairHandler = pair as CollidablePairHandler; if (pairHandler != null) { foreach (ContactInformation information in pairHandler.Contacts) { contactCount++; contactLines.Add(new VertexPositionColor(information.Contact.Position, Color.White)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * information.Contact.PenetrationDepth, Color.Red)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * information.Contact.PenetrationDepth, Color.White)); contactLines.Add(new VertexPositionColor(information.Contact.Position + information.Contact.Normal * (information.Contact.PenetrationDepth + .3f), Color.White)); } } } if (contactCount > 0) { foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, contactLines.Elements, 0, contactLines.Count / 2); } } }
public Edge(SpriteBatch spriteBatch, Settings settings, Effect normalDepthMapEffect, Effect edgeEffect) : base(spriteBatch) { if (settings == null) throw new ArgumentNullException("settings"); if (normalDepthMapEffect == null) throw new ArgumentNullException("normalDepthMapEffect"); if (edgeEffect == null) throw new ArgumentNullException("edgeEffect"); this.settings = settings; var pp = GraphicsDevice.PresentationParameters; var width = (int) (pp.BackBufferWidth * settings.MapScale); var height = (int) (pp.BackBufferHeight * settings.MapScale); //---------------------------------------------------------------- // エフェクト // 法線深度マップ this.normalDepthMapEffect = new NormalDepthMapEffect(normalDepthMapEffect); // エッジ強調 this.edgeEffect = new EdgeEffect(edgeEffect); this.edgeEffect.MapWidth = width; this.edgeEffect.MapHeight = height; //---------------------------------------------------------------- // レンダ ターゲット normalDepthMap = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Vector4, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents); }
public InstancedModelDrawer(Game game) : base(game) { instancingEffect = game.Content.Load<Effect>("InstancedEffect"); worldTransformsParameter = instancingEffect.Parameters["WorldTransforms"]; textureIndicesParameter = instancingEffect.Parameters["TextureIndices"]; viewParameter = instancingEffect.Parameters["View"]; projectionParameter = instancingEffect.Parameters["Projection"]; instancingEffect.Parameters["LightDirection1"].SetValue(Vector3.Normalize(new Vector3(.8f, -1.5f, -1.2f))); instancingEffect.Parameters["DiffuseColor1"].SetValue(new Vector3(.66f, .66f, .66f)); instancingEffect.Parameters["LightDirection2"].SetValue(Vector3.Normalize(new Vector3(-.8f, 1.5f, 1.2f))); instancingEffect.Parameters["DiffuseColor2"].SetValue(new Vector3(.3f, .3f, .5f)); instancingEffect.Parameters["AmbientAmount"].SetValue(.5f); instancingEffect.Parameters["Texture0"].SetValue(textures[0]); instancingEffect.Parameters["Texture1"].SetValue(textures[1]); instancingEffect.Parameters["Texture2"].SetValue(textures[2]); instancingEffect.Parameters["Texture3"].SetValue(textures[3]); instancingEffect.Parameters["Texture4"].SetValue(textures[4]); instancingEffect.Parameters["Texture5"].SetValue(textures[5]); instancingEffect.Parameters["Texture6"].SetValue(textures[6]); instancingEffect.Parameters["Texture7"].SetValue(textures[7]); //This vertex declaration could be compressed or made more efficient, but such optimizations weren't critical. instancingVertexDeclaration = new VertexDeclaration(new[] {new VertexElement(0, VertexElementFormat.Single, VertexElementUsage.TextureCoordinate, 1)}); }
public ParticleEffect(Effect _fx, ParticleEffectConfig conf) { fx = _fx; fx.CurrentTechnique = fx.Techniques[0]; fxPassSimple = fx.CurrentTechnique.Passes[conf.PassSimple]; fxpVP = fx.Parameters[conf.ParamVP]; fxpTime = fx.Parameters[conf.ParamTime]; fxpMapSize = fx.Parameters[conf.ParamMapSize]; fxPassLightning = fx.CurrentTechnique.Passes[conf.PassLightning]; fxpLSplits = fx.Parameters[conf.ParamSplits]; fxPassFire = fx.CurrentTechnique.Passes[conf.PassFire]; fxpFRates = fx.Parameters[conf.ParamRates]; fxpFScales = fx.Parameters[conf.ParamScales]; fxpFOff1 = fx.Parameters[conf.ParamOffset1]; fxpFOff2 = fx.Parameters[conf.ParamOffset2]; fxpFOff3 = fx.Parameters[conf.ParamOffset3]; fxpFDistortScale = fx.Parameters[conf.ParamDistortScale]; fxpFDistortBias = fx.Parameters[conf.ParamDistortBias]; fxPassAlert = fx.CurrentTechnique.Passes[conf.PassAlert]; // Set Default Values LightningSplits = DEFAULT_SPLITS; FireDistortScale = DEFAULT_DISTORT_SCALE; FireDistortBias = DEFAULT_DISTORT_BIAS; FireOffset1 = DEFAULT_OFFSET; FireOffset2 = DEFAULT_OFFSET; FireOffset3 = DEFAULT_OFFSET; FireRates = DEFAULT_RATES; FireScales = DEFAULT_SCALES; }
public object Get(string refName, ContentType type) { object resource = null; switch (type) { case ContentType.Texture: Texture2D texture = null; if (_textures.TryGetValue(refName, out texture)) { resource = texture; } break; case ContentType.Font: SpriteFont font = null; if (_fonts.TryGetValue(refName, out font)) { resource = font; } break; case ContentType.Effect: Microsoft.Xna.Framework.Graphics.Effect effect = null; if (_effects.TryGetValue(refName, out effect)) { resource = effect; } break; } return(resource); }
public ModelLoader(ContentManager contentManager, GraphicsDevice graphicsDevice) { content = contentManager; graphics = graphicsDevice; modelEffect = contentManager.Load<Effect>("EffectFiles/model"); }
/// <summary> /// Load your graphics content. /// </summary> public void Load(GraphicsDevice device, ContentManager content) { GraphicsDevice = device; spriteBatch = new SpriteBatch(GraphicsDevice); bloomExtractEffect = content.Load<Effect>("BloomExtract"); bloomCombineEffect = content.Load<Effect>("BloomCombine"); gaussianBlurEffect = content.Load<Effect>("GaussianBlur"); // Look up the resolution and format of our main backbuffer. PresentationParameters pp = GraphicsDevice.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; SurfaceFormat format = pp.BackBufferFormat; // Create a texture for reading back the backbuffer contents. resolveTarget = new ResolveTexture2D(GraphicsDevice, width, height, 1, format); // Create two rendertargets for the bloom processing. These are half the // size of the backbuffer, in order to minimize fillrate costs. Reducing // the resolution in this way doesn't hurt quality, because we are going // to be blurring the bloom images in any case. width /= 4; height /= 4; renderTarget1 = new RenderTarget2D(GraphicsDevice, width, height, 1, format); renderTarget2 = new RenderTarget2D(GraphicsDevice, width, height, 1, format); }
protected override void LoadContent() { spriteBatch = new SpriteBatch(device); //Load the fx files extractEffect = Game.Content.Load<Effect>("BloomExtract"); combineEffect = Game.Content.Load<Effect>("BloomCombine"); gaussBlurEffect = Game.Content.Load<Effect>("GaussBlur"); // Look up the resolution and format of our main backbuffer. PresentationParameters pp = device.PresentationParameters; int width = pp.BackBufferWidth; int height = pp.BackBufferHeight; SurfaceFormat format = pp.BackBufferFormat; //Set how the bloom will behave setBloomSetting(0.25f, 4f, 2f, 1f, 2f, 0f); // Create a texture for reading back the backbuffer contents. resolveTarget = new ResolveTexture2D(device, width, height, 1, format); //Can make the backbuffers smaller to increase efficiency, makes bloom less pronounced /** width /= 2; height /= 2; */ //for example renderTarget1 = new RenderTarget2D(device, width, height, 1, format); renderTarget2 = new RenderTarget2D(device, width, height, 1, format); }
public void Draw(Effect effect) { for (int i = 0; i < this.listEntity.Count; i++) { this.listEntity[i].Draw(this.graphics, effect); } }
public HxMaterial(HxMaterial material) { Effect = material.Effect; Color = material.Color; MainTexture = material.MainTexture; Tiling = material.Tiling; Offset = material.Offset; }
public void Draw(SpriteBatch batch, Microsoft.Xna.Framework.Graphics.Effect effect) { batch.Begin(SpriteSortMode.BackToFront, m_eBlendType, null, null, null, effect); foreach (Particle p in m_allParticles) { p.Draw(batch); } batch.End(); }
/// <summary> /// Creates a new instance of <see cref="XNAEffectImplementation"/>. /// </summary> /// <param name="renderer">The XNA renderer.</param> /// <param name="byteCode">The compiled byte code.</param> internal XNAEffectImplementation(XNARenderer renderer, byte[] byteCode) { _renderer = renderer; _graphicsDevice = renderer.GraphicsDevice; _cachedByteCode = byteCode; _effect = new XFG.Effect(_graphicsDevice, byteCode); base.SetParameters(new XNAEffectParameterCollection(_effect.Parameters)); base.SetTechniques(new XNAEffectTechniqueCollection(_effect.Techniques)); _currentTechnique = (XNAEffectTechnique)base.Techniques[0]; }
public GenericEffect(Microsoft.Xna.Framework.Graphics.Effect effect, GraphicsDevice graphics) { this.Effect = effect; this.GraphicsDevice = graphics; _renderTarget = new RenderTarget2D( GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); }
public DrawStackFrame(SpriteSortMode sortMode, BlendState blendState, SamplerState samplerState, Matrix transform, Matrix projection, Microsoft.Xna.Framework.Graphics.Effect shader, Action <Matrix, Matrix> shaderSetup) { SortMode = sortMode; BlendState = blendState; SamplerState = samplerState; Transform = transform; Projection = projection; Shader = shader; ShaderSetup = shaderSetup; }
/// <summary> /// Helper for drawing a texture into the current rendertarget, /// using a custom shader to apply postprocessing effects. /// </summary> internal static void DrawFullscreenQuad(GraphicsDevice graphics, Texture2D texture, int width, int height, Microsoft.Xna.Framework.Graphics.Effect effect) { using (SpriteBatch spriteBatch = new SpriteBatch(graphics)) { spriteBatch.Begin(0, BlendState.Opaque, null, null, null, effect); spriteBatch.Draw(texture, new Rectangle(0, 0, width, height), Color.White); spriteBatch.End(); } }
private void LoadEffects() { _ExtractEffect = (Microsoft.Xna.Framework.Graphics.Effect)ContentManager.Instance.Load( @"Data\shaders\Bloom.mgfxo", "Bloom", ContentType.Effect); _BlurEffect = (Microsoft.Xna.Framework.Graphics.Effect)ContentManager.Instance.Load( @"Data\shaders\GaussianBlur.mgfxo", "Blur", ContentType.Effect); _CombineEffect = (Microsoft.Xna.Framework.Graphics.Effect)ContentManager.Instance.Load( @"Data\shaders\Combine.mgfxo", "Combine", ContentType.Effect); }
public static Microsoft.Xna.Framework.Graphics.Effect LoadEffectStream(Stream stream, GraphicsDevice device) { Microsoft.Xna.Framework.Graphics.Effect effect = null; using (var reader = new BinaryReader(stream)) { effect = new Microsoft.Xna.Framework.Graphics.Effect(device, ReadAllBytes(reader)); } return(effect); }
public static Microsoft.Xna.Framework.Graphics.Effect LoadEffectFromFile(string filename, GraphicsDevice device) { Microsoft.Xna.Framework.Graphics.Effect effect = null; using (var stream = TitleContainer.OpenStream(filename)) { effect = LoadEffectStream(stream, device); } return(effect); }
/// <summary> /// Helper for drawing a texture into a rendertarget, using /// a custom shader to apply postprocessing effects. /// </summary> internal static void DrawFullscreenQuad(GraphicsDevice graphics, Texture2D texture, RenderTarget2D renderTarget, Microsoft.Xna.Framework.Graphics.Effect effect) { graphics.SetRenderTarget(renderTarget); DrawFullscreenQuad( graphics, texture, renderTarget.Width, renderTarget.Height, effect); }
/// <summary> /// Loads a pixel shader from shaderCode member variable /// </summary> protected override void LoadFromShaderCode() { #if SILVERLIGHT using (var shaderStream = new MemoryStream()) { shaderStream.Write(shaderCode, 0, shaderCode.Length); effect = new XFG.Effect(); effect.VertexShader(XFG.VertexShader.FromStream(device, shaderStream)); } #else effect = new XFG.Effect(device, shaderCode); #endif }
private Microsoft.Xna.Framework.Graphics.Effect LoadEffect(Stream stream, string refName) { Microsoft.Xna.Framework.Graphics.Effect effect = null; // Use Case: User calls load but this particular resources has already // been loaded. So, check the dictionary first for our resource before // trying to add it as a new resource. if (!_effects.TryGetValue(refName, out effect)) { effect = Utilities.LoadEffectStream(stream, this.Graphics); _effects.Add(refName, effect); } return(effect); }
public TilemapFilter(IRenderer renderer, SpriteBatch spriteBatch, Effect effect, int tileSize) { _renderer = renderer; _spriteBatch = spriteBatch; _effect = effect; _tileMapParam = _effect.Parameters["Texture"]; _superTilesetParam = _effect.Parameters["texIndex"]; _tileSizeParam = _effect.Parameters["tileSize"]; _inverseSuperTilesetSizeParam = _effect.Parameters["inverseIndexTexSize"]; _tileMapSizeParam = _effect.Parameters["mapSize"]; _effectPass = _effect.CurrentTechnique.Passes[0]; _tileSizeParam.SetValue(new Vector2(tileSize, tileSize)); _tileSize = tileSize; }
public SceneFadeEffect(Microsoft.Xna.Framework.Graphics.Effect effect, IScene previousScene, float duration, GraphicsDevice graphics) { Effect = effect; PreviousScene = previousScene; FadeDuration = duration; GraphicsDevice = graphics; _renderTarget = new RenderTarget2D( GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); _snapshotTarget = new RenderTarget2D( GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); }
public override void SetUp() { base.SetUp(); _spriteBatch = new SpriteBatch(gd); _texture = content.Load <Texture2D> (Paths.Texture("MonoGameIcon")); _texture2 = content.Load <Texture2D>(Paths.Texture("Surge")); _texture3 = content.Load <Texture2D> (Paths.Texture("lines-64")); _effect = new BasicEffect(gd) { VertexColorEnabled = true, TextureEnabled = true, View = Matrix.Identity, World = Matrix.Identity }; _effect2 = content.Load <Microsoft.Xna.Framework.Graphics.Effect>(Paths.CompiledEffect("Grayscale")); }
public void Apply(RenderTarget2D sceneTexture, Microsoft.Xna.Framework.Graphics.Effect finalEffect) { RenderTarget2D output = sceneTexture; foreach (KeyValuePair <int, IPostProcessEffect> pair in _ActiveEffects) { output = pair.Value.RenderToTexture(output); } GraphicsDevice.SetRenderTarget(null); DrawFullscreenQuad( GraphicsDevice, output, output.Width, output.Height, finalEffect); }
public void Render(IRenderArgs args, Microsoft.Xna.Framework.Graphics.Effect effect) { var count = ElementCount; if (!Definition.NeverRender && Rendered && count > 0) { ((IEffectMatrices)effect).World = WorldMatrix; foreach (var pass in effect.CurrentTechnique.Passes) { pass?.Apply(); args.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, StartIndex, count / 3); } } foreach (var child in Children) { child.Render(args, effect); } }
/// <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 new SpriteBatch, which can be used to draw textures. activeBatch = new SpriteBatch(GraphicsDevice); overlayBatch = new SpriteBatch(GraphicsDevice); Timeless = Content.Load <SpriteFont>("Timeless"); mEffectManager.LoadContent(Content); //shader stuff gSimple = Content.Load <Microsoft.Xna.Framework.Graphics.Effect>("redTint"); gWaveEffect = Content.Load <Microsoft.Xna.Framework.Graphics.Effect>("waveEffect"); gSeconds = gWaveEffect.Parameters["time"]; gHorizon = graphics.PreferredBackBufferHeight / 3; //horizon at 1/3 of screen //Texture Loading............................................................................ loadTextures(); //Unit Loading............................................................................... loadUnits(); tempTarget = new RenderTarget2D(GraphicsDevice, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); }
public void SetGlobalLightParameters(Microsoft.Xna.Framework.Graphics.Effect effect, Camera camera, Vector3 cameraPos) { effect.Parameters["DirectionalLightDirections"].SetValue(this.directionalLightDirections); effect.Parameters["DirectionalLightColors"].SetValue(this.directionalLightColors); effect.Parameters["EnvironmentColor"].SetValue(this.EnvironmentColor); effect.Parameters["Environment" + Model.SamplerPostfix].SetValue(this.environmentMap); effect.Parameters["CloudShadow"].SetValue(this.directionalLightCloudShadow); effect.Parameters["CloudOffset"].SetValue(this.directionalLightCloudVelocity * (this.main.TotalTime / 60.0f)); effect.Parameters["CameraPosition"].SetValue(cameraPos); if (this.EnableGlobalShadowMap) { effect.Parameters["ShadowViewProjectionMatrix"].SetValue(Matrix.CreateTranslation(cameraPos) * this.GlobalShadowViewProjection); effect.Parameters["ShadowMapSize"].SetValue(this.globalShadowMapSize); effect.Parameters["ShadowMap" + Model.SamplerPostfix].SetValue(this.GlobalShadowMap); if (this.EnableDetailGlobalShadowMap) { effect.Parameters["DetailShadowViewProjectionMatrix"].SetValue(Matrix.CreateTranslation(cameraPos) * this.DetailGlobalShadowViewProjection); effect.Parameters["DetailShadowMapSize"].SetValue(this.detailGlobalShadowMapSize); effect.Parameters["DetailShadowMap" + Model.SamplerPostfix].SetValue(this.DetailGlobalShadowMap); } } }
//objects with texture and alpha but no specular or emmissive /// <summary> /// Constructor for EffectParameters object used by any DrawnActor3D /// </summary> /// <param name="effect">Basic effect</param> public OurEffectParameters(Microsoft.Xna.Framework.Graphics.Effect effect) { Effect = effect; }
public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, Rectangle clientBounds) { graphicsDevice.SetRenderTarget(renderTarget); graphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin( transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Immediate); mapRenderer.Draw(camera.GetViewMatrix()); spriteBatch.End(); if (IsMyTurn) { spriteBatch.Begin( transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Texture); if (selectedCharacter != null && selectedCard == null && movingPoint == null) { data.Characters.SingleOrDefault(character => character == selectedCharacter && character.HasRemainingMoves && character.OwnerPlayerId == data.GetPlayerId())?.DrawMovementRange(spriteBatch); } else if (selectedCard != null && targetingPoint == null) { selectedCard.DrawEffectRange(spriteBatch); } else if (movingPoint != null) { var movingPointScreen = movingPoint.GetScreenPosition(); var distanceOverlay = content.DistanceOverlay; spriteBatch.Draw(distanceOverlay, new Rectangle((int)movingPointScreen.X - MapPoint.TileWidth_Half, (int)movingPointScreen.Y, distanceOverlay.Width, distanceOverlay.Height), Color.DarkGreen * 0.5f); } else if (targetingPoint != null) { var targetingPointScreen = targetingPoint.GetScreenPosition(); var distanceOverlay = content.DistanceOverlay; spriteBatch.Draw(distanceOverlay, new Rectangle((int)targetingPointScreen.X - MapPoint.TileWidth_Half, (int)targetingPointScreen.Y, distanceOverlay.Width, distanceOverlay.Height), Color.DarkBlue * 0.5f); } spriteBatch.End(); } Effect effectForDrawable(IDrawable drawable) { return(!(drawable is Character character) ? null : character == selectedCharacter ? content.Highlight : character.ActivatedThisRound ? content.Shade : null); } Effect currentEffect = null; var startedSpriteBatch = false; foreach (var drawable in entities.Drawables) { var characterEffect = effectForDrawable(drawable); if (!startedSpriteBatch || currentEffect != characterEffect) { if (startedSpriteBatch) { spriteBatch.End(); } spriteBatch.Begin( transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, effect: characterEffect); currentEffect = characterEffect; startedSpriteBatch = true; } if (drawable == lockedInCharacter) { lockedInCharacter.DrawLock(spriteBatch); } drawable.DrawWithEffect(spriteBatch); } spriteBatch.End(); spriteBatch.Begin( transformMatrix: camera.GetViewMatrix(), samplerState: SamplerState.PointClamp, blendState: BlendState.AlphaBlend, sortMode: SpriteSortMode.Texture); foreach (var drawable in entities.Drawables) { drawable.DrawWithoutEffect(spriteBatch); } spriteBatch.End(); // Draw a characters hand of cards if player is playing that side if (selectedCharacter != null && selectedCharacter.OwnerPlayerId == data.GetPlayerId()) { handOfCards.Draw(spriteBatch, clientBounds, selectedCharacter.CurrentHand, selectedCard); } // Draw UI spriteBatch.Begin(); if (IsMyTurn) { endTurnButton.X = playerSidePanel.Width + (2 * gridSpacing); endTurnButton.Draw(spriteBatch); } statusPanel.X = graphicsDevice.PresentationParameters.BackBufferWidth - statusPanel.MeasureContent().X - (2 * gridSpacing); statusPanel.Draw(spriteBatch); playerSidePanel.Draw(spriteBatch); if (data.IsTestMode) { winGameNowButton.X = endTurnButton.Width + playerSidePanel.Width + (3 * gridSpacing); winGameNowButton.Draw(spriteBatch); } gameLogPanel.Y = endTurnButton.Height + (2 * gridSpacing); gameLogPanel.Draw(spriteBatch); if (selectedCharacter != null) { selectedPlayerStatsPanel.X = gameLogPanel.Width + (2 * gridSpacing); selectedPlayerStatsPanel.Y = endTurnButton.Height + (2 * gridSpacing); selectedPlayerStatsPanel.Draw(spriteBatch); } if (showGameLogEntryPanel) { heldGameLogEntryPanel.Draw(spriteBatch); } if (showAppliedConditionDetailsPanel) { appliedConditionDetailsPanel.Draw(spriteBatch); } spriteBatch.End(); graphicsDevice.SetRenderTarget(null); spriteBatch.Begin(); spriteBatch.Draw(renderTarget, Vector2.Zero, Color.White); spriteBatch.End(); }
public void PushSpriteBatch(SpriteSortMode?sortMode = null, BlendState blendState = null, SamplerState samplerState = null, Matrix?transform = null, Matrix?projection = null, Microsoft.Xna.Framework.Graphics.Effect shader = null, Action <Matrix, Matrix> shaderSetup = null) { var lastState = SpriteBatchStack.Any() ? SpriteBatchStack.Peek() : null; if (sortMode == null) { sortMode = lastState?.SortMode ?? SpriteSortMode.Deferred; } if (blendState == null) { blendState = lastState?.BlendState ?? NonPremultiplied; } if (samplerState == null) { samplerState = lastState?.SamplerState ?? SamplerState.PointClamp; } if (transform == null) { transform = lastState?.Transform ?? Matrix.Identity; } if (projection == null) { projection = lastState?.Projection ?? Matrix.Identity; } if (shaderSetup == null) { shaderSetup = SetupNormal; } var newState = new DrawStackFrame(sortMode.Value, blendState, samplerState, transform.Value, projection.Value, shader, shaderSetup); if (!SpriteBatchStack.Empty()) { SpriteBatch.End(); } newState.Apply(this); SpriteBatchStack.Push(newState); }
public override void Draw(Camera cam, Microsoft.Xna.Framework.Graphics.Effect effect, GameTime gameTime) { }
public void SetRenderParameters(Microsoft.Xna.Framework.Graphics.Effect effect, RenderParameters parameters) { }
public void SetCompositeParameters(Microsoft.Xna.Framework.Graphics.Effect effect) { effect.Parameters["AmbientLightColor"].SetValue(this.ambientLightColor); }
/// <summary> /// Computes sample weightings and texture coordinate offsets /// for one pass of a separable gaussian blur filter. /// </summary> void SetBlurEffectParameters(Microsoft.Xna.Framework.Graphics.Effect gaussianBlurEffect, float dx, float dy, float blurAmount) { // Look up the sample weight and offset effect parameters. EffectParameter weightsParameter, offsetsParameter; weightsParameter = gaussianBlurEffect.Parameters["SampleWeights"]; offsetsParameter = gaussianBlurEffect.Parameters["SampleOffsets"]; // Look up how many samples our gaussian blur effect supports. int sampleCount = weightsParameter.Elements.Count; // Create temporary arrays for computing our filter settings. float[] sampleWeights = new float[sampleCount]; Vector2[] sampleOffsets = new Vector2[sampleCount]; // The first sample always has a zero offset. sampleWeights[0] = ComputeGaussian(0, blurAmount); sampleOffsets[0] = new Vector2(0); // Maintain a sum of all the weighting values. float totalWeights = sampleWeights[0]; // Add pairs of additional sample taps, positioned // along a line in both directions from the center. for (int i = 0; i < sampleCount / 2; i++) { // Store weights for the positive and negative taps. float weight = ComputeGaussian(i + 1, blurAmount); sampleWeights[i * 2 + 1] = weight; sampleWeights[i * 2 + 2] = weight; totalWeights += weight * 2; // To get the maximum amount of blurring from a limited number of // pixel shader samples, we take advantage of the bilinear filtering // hardware inside the texture fetch unit. If we position our texture // coordinates exactly halfway between two texels, the filtering unit // will average them for us, giving two samples for the price of one. // This allows us to step in units of two texels per sample, rather // than just one at a time. The 1.5 offset kicks things off by // positioning us nicely in between two texels. float sampleOffset = i * 2 + 1.5f; Vector2 delta = new Vector2(dx, dy) * sampleOffset; // Store texture coordinate offsets for the positive and negative taps. sampleOffsets[i * 2 + 1] = delta; sampleOffsets[i * 2 + 2] = -delta; } // Normalize the list of sample weightings, so they will always sum to one. for (int i = 0; i < sampleWeights.Length; i++) { sampleWeights[i] /= totalWeights; } // Tell the effect about our new filter settings. weightsParameter.SetValue(sampleWeights); offsetsParameter.SetValue(sampleOffsets); }