internal Effect(Shader shader) { Shader = shader; ParameterData = new byte[Shader.ParametersSize]; EffectParameter[] parameters = new EffectParameter[Shader.Parameters.Count]; for (int i = 0; i < Shader.Parameters.Count; i++) parameters[i] = new EffectParameter(this, Shader.Parameters[i]); EffectPass[] passes = new EffectPass[Shader.Passes.Count]; for (int i = 0; i < Shader.Passes.Count; i++) passes[i] = new EffectPass(this, Shader.Passes[i]); Parameters = new EffectParameterCollection(parameters); Passes = new EffectPassCollection(passes); foreach (EffectParameter parameter in Parameters) { if (parameter.Class == EffectParameterClass.Sampler) { int count = parameter.Parameter.Count == 0 ? 1 : parameter.Parameter.Count; int[] units = new int[count]; for (int i = 0; i < count; i++) units[i] = parameter.Parameter.TextureUnit + i; parameter.SetValue(count); } } }
/// <summary> /// This is where it all happens. Grabs a scene that has already been rendered, /// and uses postprocess magic to add a glowing bloom effect over the top of it. /// </summary> public void Draw(BloomSettings settings) { if (!Visible) { return; } GraphicsDevice.SamplerStates[1] = SamplerState.AnisotropicClamp; // Pass 1: draw the scene into rendertarget 1, using a // shader that extracts only the brightest parts of the image. bloomExtractEffect.Parameters["BloomThreshold"].SetValue( settings.BloomThreshold); DrawFullscreenQuad(sceneRenderTarget, renderTarget1, bloomExtractEffect, IntermediateBuffer.PreBloom); // Pass 2: draw from rendertarget 1 into rendertarget 2, // using a shader to apply a horizontal gaussian blur filter. gaussianBlurEffect.CurrentTechnique = gaussianBlurEffect.Techniques["GaussianBlur"]; SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0, settings); DrawFullscreenQuad(renderTarget1, renderTarget2, gaussianBlurEffect, IntermediateBuffer.BlurredHorizontally); // Pass 3: draw from rendertarget 2 back into rendertarget 1, // using a shader to apply a vertical gaussian blur filter. SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height, settings); DrawFullscreenQuad(renderTarget2, renderTarget1, gaussianBlurEffect, IntermediateBuffer.BlurredBothWays); // Pass 4: draw both rendertarget 1 and the original scene // image back into the main backbuffer, using a shader that // combines them to produce the final bloomed result. GraphicsDevice.SetRenderTarget(finalRenderTarget); EffectParameterCollection parameters = bloomCombineEffect.Parameters; parameters["BloomIntensity"].SetValue(settings.BloomIntensity); parameters["BaseIntensity"].SetValue(settings.BaseIntensity); parameters["BloomSaturation"].SetValue(settings.BloomSaturation); parameters["BaseSaturation"].SetValue(settings.BaseSaturation); // FNA GraphicsDevice.Textures[1] = sceneRenderTarget; //parameters["BaseSampler"].SetValue(sceneRenderTarget); Viewport viewport = GraphicsDevice.Viewport; DrawFullscreenQuad(renderTarget1, viewport.Width, viewport.Height, bloomCombineEffect, IntermediateBuffer.FinalResult); GraphicsDevice.SetRenderTarget(null); }
protected virtual void SetUpdateParameters(EffectParameterCollection parameters) { }
public SemanticMappedMatrix(EffectParameterCollection parent, string semanticName) : base(parent, semanticName) { }
public FogEffectStructure(EffectParameterCollection parameters) { this.fogType = new SemanticMappedInt32(parameters, "Fog_Type"); this.fogColor = new SemanticMappedVector3(parameters, "Fog_Color"); this.fogDensity = new SemanticMappedSingle(parameters, "Fog_Density"); }
internal void CreateInstanceFrom(GraphicsDevice device, EffectData effectData, EffectPool effectPool) { GraphicsDevice = device; ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); Pool = effectPool ?? device.DefaultEffectPool; // Sets the effect name Name = effectData.Description.Name; // Register the bytecode to the pool var effect = Pool.RegisterBytecode(effectData); // Initialize from effect InitializeFrom(effect, null); // If everything was fine, then we can register it into the pool Pool.AddEffect(this); }
public override void Draw(GameTime gameTime) { foreach (var mesh in meshes) { var world = Matrix.Identity; // Wheel transformation if ((int)mesh.Tag > 0) { world *= Matrix.CreateRotationX(wheelRotationX); if ((int)mesh.Tag > 1) { world *= Matrix.CreateRotationY(WheelRotationY); } } // Local modelspace world *= mesh.ParentBone.Transform; // World world *= RotationMatrix * TranslationMatrix; foreach (Effect effect in mesh.Effects) { EffectParameterCollection param = effect.Parameters; param["World"].SetValue(world); param["View"].SetValue(View); param["Projection"].SetValue(Projection); // TODO: CARMOVE if (mesh.Name.Equals("main")) { if (param["NormalMatrix"] != null) { param["NormalMatrix"].SetValue(Matrix.Invert(Matrix.Transpose(world))); } if (param["EyePosition"] != null) { param["EyePosition"].SetValue(Game.GetService <CameraComponent>().Position); } if (DirectionalLight != null) { if (param["DirectionalLightDirection"] != null) { param["DirectionalLightDirection"].SetValue(DirectionalLight.Direction); } if (param["DirectionalLightDiffuse"] != null) { param["DirectionalLightDiffuse"].SetValue(DirectionalLight.Diffuse); } if (param["DirectionalLightAmbient"] != null) { param["DirectionalLightAmbient"].SetValue(DirectionalLight.Ambient); } } } } mesh.Draw(); } }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks. /// </summary> /// <param name="device">The device.</param> /// <param name="effectData">The bytecode to add to <see cref="GraphicsDevice.DefaultEffectPool"/>. This bytecode must contain only one effect.</param> /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception> /// <remarks> /// The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>. /// </remarks> public Effect(GraphicsDevice device, EffectData effectData) : base(device) { if (effectData.Effects.Count != 1) throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}]. Use GraphicsDevice.DefaultEffectPool.RegisterBytecode instead", Utilities.Join(",", effectData.Effects)), "bytecode"); ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); ResourceLinker = ToDispose(new EffectResourceLinker()); Pool = device.DefaultEffectPool; // Sets the effect name Name = effectData.Effects[0].Name; // Register the bytecode to the pool Pool.RegisterBytecode(effectData); Initialize(); }
/// <summary> /// This is where it all happens. Grabs a scene that has already been rendered, /// and uses postprocess magic to add a glowing bloom effect over the top of it. /// </summary> public override void Draw(GameTime gameTime) { BlendState bs = GraphicsDevice.BlendState; DepthStencilState ds = GraphicsDevice.DepthStencilState; RasterizerState rs = GraphicsDevice.RasterizerState; SamplerState ss0 = GraphicsDevice.SamplerStates[0]; SamplerState ss1 = GraphicsDevice.SamplerStates[1]; Texture t0 = GraphicsDevice.Textures[0]; Texture t1 = GraphicsDevice.Textures[1]; // Pass 1: draw the scene into rendertarget 1, using a // shader that extracts only the brightest parts of the image. bloomExtractEffect.Parameters["BloomThreshold"].SetValue( Settings.BloomThreshold); DrawFullscreenQuad(resolveTarget, renderTarget1, bloomExtractEffect, IntermediateBuffer.PreBloom); // Pass 2: draw from rendertarget 1 into rendertarget 2, // using a shader to apply a horizontal gaussian blur filter. SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0); DrawFullscreenQuad(renderTarget1, renderTarget2, gaussianBlurEffect, IntermediateBuffer.BlurredHorizontally); // Pass 3: draw from rendertarget 2 back into rendertarget 1, // using a shader to apply a vertical gaussian blur filter. SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height); DrawFullscreenQuad(renderTarget2, renderTarget1, gaussianBlurEffect, IntermediateBuffer.BlurredBothWays); // Pass 4: draw both rendertarget 1 and the original scene // image back into the main backbuffer, using a shader that // combines them to produce the final bloomed result. GraphicsDevice.SetRenderTarget(resolveTarget); EffectParameterCollection parameters = bloomCombineEffect.Parameters; parameters["BloomIntensity"].SetValue(Settings.BloomIntensity); parameters["BaseIntensity"].SetValue(Settings.BaseIntensity); parameters["BloomSaturation"].SetValue(Settings.BloomSaturation); parameters["BaseSaturation"].SetValue(baseSaturation); GraphicsDevice.Textures[1] = resolveTarget; Viewport viewport = GraphicsDevice.Viewport; DrawFullscreenQuad(renderTarget1, viewport.Width, viewport.Height, bloomCombineEffect, IntermediateBuffer.FinalResult); GraphicsDevice.BlendState = bs; GraphicsDevice.DepthStencilState = ds; GraphicsDevice.RasterizerState = rs; GraphicsDevice.SamplerStates[0] = ss0; GraphicsDevice.SamplerStates[1] = ss1; GraphicsDevice.Textures[0] = t0; GraphicsDevice.Textures[1] = t1; }
public MaterialEffectStructure(EffectParameterCollection parameters) { this.diffuse = new SemanticMappedVector3(parameters, "Material_Diffuse"); this.opacity = new SemanticMappedSingle(parameters, "Material_Opacity"); }
public SemanticMappedVectorArray(EffectParameterCollection parent, string semanticName) : base(parent, semanticName) { }
/// <summary> /// Helper for loading and initializing the particle effect. /// </summary> void LoadParticleEffect() { Effect effect = content.Load <Effect>(@"effects\ParticleEffect"); // If we have several particle systems, the content manager will return // a single shared effect instance to them all. But we want to preconfigure // the effect with parameters that are specific to this particular // particle system. By cloning the effect, we prevent one particle system // from stomping over the parameter settings of another. particleEffect = effect.Clone(); EffectParameterCollection parameters = particleEffect.Parameters; //粒子大小和速度可根据模型缩放调节 float modelScale = 1; float scale = 1; if (parentEffect != null) { if (parentEffect.parentModel != null) { modelScale = parentEffect.parentModel.scale; } scale = parentEffect.Scale * modelScale; } // Look up shortcuts for parameters that change every frame. effectViewParameter = parameters["View"]; effectProjectionParameter = parameters["Projection"]; effectViewportScaleParameter = parameters["ViewportScale"]; effectTimeParameter = parameters["CurrentTime"]; effectWorldParameter = parameters["World"]; effectWorldParameter.SetValue(Matrix.Identity); // Set the values of parameters that do not change. parameters["Duration"].SetValue((float)settings.Duration.TotalSeconds); parameters["DurationRandomness"].SetValue(settings.DurationRandomness); parameters["Gravity"].SetValue(settings.Gravity); parameters["EndVelocity"].SetValue(settings.EndVelocity * scale); parameters["MinColor"].SetValue(settings.MinColor / 255); parameters["MaxColor"].SetValue(settings.MaxColor / 255); parameters["RotateSpeed"].SetValue( new Vector2(settings.MinRotateSpeed, settings.MaxRotateSpeed)); parameters["StartSize"].SetValue( new Vector2(settings.MinStartSize * scale, settings.MaxStartSize * scale)); parameters["EndSize"].SetValue( new Vector2(settings.MinEndSize * scale, settings.MaxEndSize * scale)); // Load the particle texture, and set it onto the effect. Texture2D texture = content.Load <Texture2D>(settings.TextureName); parameters["Texture"].SetValue(texture); //// Choose the appropriate effect technique. If these particles will never //// rotate, we can use a simpler pixel shader that requires less GPU power. //string techniqueName; //if ((settings.MinRotateSpeed == 0) && (settings.MaxRotateSpeed == 0)) // techniqueName = "NonRotatingParticles"; //else // techniqueName = "RotatingParticles"; //particleEffect.CurrentTechnique = particleEffect.Techniques[techniqueName]; }
protected virtual void SetRenderingParameters(EffectParameterCollection parameters) { }
public override void Initialize(ContentManager contentLoader, ComponentManifest manifest) { Effect genericEffect = contentLoader.Load <Effect>("shaders\\Billboard"); // If we have several of these objects, the content manager will return // a single shared effect instance to them all. But we want to preconfigure // the effect with parameters that are specific to this particular // object. By cloning the effect, we prevent one // from stomping over the parameter settings of another. Effect = genericEffect.Clone(); Effect.CurrentTechnique = Effect.Techniques["Billboard"]; EffectRegistry.Add(Effect, RenderOptions.BillboardParams); EffectParameterCollection parameters = Effect.Parameters; // Set the values of parameters that do not change. parameters["WindAmount"].SetValue(0.0f); parameters["BillboardWidth"].SetValue(2.0f); parameters["BillboardHeight"].SetValue(2.0f); mTexture = contentLoader.Load <Texture>((string)(manifest.Properties[ManifestKeys.TEXTURE])); parameters["Texture"].SetValue(mTexture); parameters["gBright"].SetValue(0.17f); parameters["gContrast"].SetValue(0.9f); mDepthOnlyEffect = Effect.Clone(); mDepthOnlyEffect.CurrentTechnique = mDepthOnlyEffect.Techniques["DepthOnlyBillboard"]; EffectRegistry.Add(mDepthOnlyEffect, RenderOptions.BillboardParams); mGeometry = new MeshPart(); BillboardVertex[] vertices = new BillboardVertex[4]; vertices[0].Position = Vector3.Zero; vertices[1].Position = Vector3.Zero; vertices[2].Position = Vector3.Zero; vertices[3].Position = Vector3.Zero; vertices[0].Normal = Vector3.Up; vertices[1].Normal = Vector3.Up; vertices[2].Normal = Vector3.Up; vertices[3].Normal = Vector3.Up; vertices[0].TexCoord = Vector2.Zero; vertices[1].TexCoord = Vector2.UnitX; vertices[2].TexCoord = Vector2.One; vertices[3].TexCoord = Vector2.UnitY; float randValue = 0.5f; if (manifest.Properties.ContainsKey(ManifestKeys.IS_RANDOMIZED) && (bool)(manifest.Properties[ManifestKeys.IS_RANDOMIZED])) { randValue = (float)(GameResources.ActorManager.Random.Next(-524288, 524288)) / (float)524288; } vertices[0].Random = randValue; vertices[1].Random = randValue; vertices[2].Random = randValue; vertices[3].Random = randValue; mGeometry.VertexBuffer = new VertexBuffer( SharedResources.Game.GraphicsDevice, BillboardVertex.VertexDeclaration, 4, BufferUsage.None); mGeometry.VertexBuffer.SetData(vertices); // Create and populate the index buffer. ushort[] indices = new ushort[] { 0, 1, 2, 0, 2, 3 }; mGeometry.IndexBuffer = new IndexBuffer( SharedResources.Game.GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.None); mGeometry.IndexBuffer.SetData(indices); mGeometry.NumVertices = 4; mGeometry.PrimitiveCount = 2; mGeometry.StartIndex = 0; mGeometry.VertexOffset = 0; GameResources.ActorManager.PreAnimationUpdateStep += PreAnimationUpdateHandler; base.Initialize(contentLoader, manifest); }
/// <summary> /// This is where it all happens. Grabs a scene that has already been rendered, /// and uses postprocess magic to add a glowing bloom effect over the top of it. /// </summary> public override void Draw(GameTime gameTime) { GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; // Pass 1: draw the scene into rendertarget 1, using a // shader that extracts only the brightest parts of the image. if (usePresets) { bloomExtractEffect.Parameters["BloomThreshold"].SetValue( Settings.BloomThreshold); } else { bloomExtractEffect.Parameters["BloomThreshold"].SetValue(bloomThreshold); } DrawFullscreenQuad(sceneRenderTarget, renderTarget1, bloomExtractEffect, IntermediateBuffer.PreBloom); // Pass 2: draw from rendertarget 1 into rendertarget 2, // using a shader to apply a horizontal gaussian blur filter. SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0); DrawFullscreenQuad(renderTarget1, renderTarget2, gaussianBlurEffect, IntermediateBuffer.BlurredHorizontally); // Pass 3: draw from rendertarget 2 back into rendertarget 1, // using a shader to apply a vertical gaussian blur filter. SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height); DrawFullscreenQuad(renderTarget2, renderTarget1, gaussianBlurEffect, IntermediateBuffer.BlurredBothWays); // Pass 4: draw both rendertarget 1 and the original scene // image back into the main backbuffer, using a shader that // combines them to produce the final bloomed result. GraphicsDevice.SetRenderTarget(null); EffectParameterCollection parameters = bloomCombineEffect.Parameters; if (usePresets) { parameters["BloomIntensity"].SetValue(Settings.BloomIntensity); parameters["BaseIntensity"].SetValue(Settings.BaseIntensity); parameters["BloomSaturation"].SetValue(Settings.BloomSaturation); parameters["BaseSaturation"].SetValue(Settings.BaseSaturation); } else { parameters["BloomIntensity"].SetValue(bloomIntensity); parameters["BaseIntensity"].SetValue(baseIntensity); parameters["BloomSaturation"].SetValue(bloomSaturation); parameters["BaseSaturation"].SetValue(baseSaturation); } GraphicsDevice.Textures[1] = sceneRenderTarget; Viewport viewport = GraphicsDevice.Viewport; DrawFullscreenQuad(renderTarget1, viewport.Width, viewport.Height, bloomCombineEffect, IntermediateBuffer.FinalResult); }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified effect loaded from an effect pool. /// </summary> /// <param name="device">The device.</param> /// <param name="pool">The effect pool.</param> /// <param name="effectName">Name of the effect.</param> public Effect(GraphicsDevice device, EffectPool pool, string effectName) : base(device, effectName) { ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); ResourceLinker = ToDispose(new EffectResourceLinker()); Pool = pool; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Effect" /> class with the specified bytecode effect. See remarks. /// </summary> /// <param name="device">The device.</param> /// <param name="effectData">The bytecode to add to the Effect Pool. This bytecode must contain only one effect.</param> /// <param name="effectPool">The effect pool used to register the bytecode. Default is <see cref="GraphicsDevice.DefaultEffectPool"/>.</param> /// <exception cref="ArgumentException">If the bytecode doesn't contain a single effect.</exception> /// <remarks>The effect bytecode must contain only a single effect and will be registered into the <see cref="GraphicsDevice.DefaultEffectPool"/>.</remarks> public Effect(GraphicsDevice device, EffectData effectData, EffectPool effectPool = null) : base(device) { if (effectData.Effects.Count != 1) throw new ArgumentException(string.Format("Expecting only one effect in the effect bytecode instead of [{0}].", Utilities.Join(",", effectData.Effects)), "effectData"); ConstantBuffers = new EffectConstantBufferCollection(); Parameters = new EffectParameterCollection(); Techniques = new EffectTechniqueCollection(); Pool = effectPool ?? device.DefaultEffectPool; // Sets the effect name Name = effectData.Effects[0].Name; // Register the bytecode to the pool Pool.RegisterBytecode(effectData); // Initialize from effect InitializeFrom(Pool.Find(Name)); // If everything was fine, then we can register it into the pool Pool.AddEffect(this); }
private void Init(string TextureName, int MaxParticles, int NumberOfImages, BlendState BlendState, bool RotateTowardCamera, ContentManager Content, GraphicsDevice GraphicsDevice) { this.TextureName = TextureName; this.MaxParticles = MaxParticles; this.NumberOfImages = NumberOfImages; this.BlendState = BlendState; _UseAlphaBlend = false; // Allocate the particle array, and fill in the corner fields (which never change). ArrayParticles = new BillboardVertex[MaxParticles * 4]; for (int i = 0; i < MaxParticles; i++) { ArrayParticles[i * 4 + 0].UV = new Vector2(0, 0); ArrayParticles[i * 4 + 1].UV = new Vector2(1, 0); ArrayParticles[i * 4 + 2].UV = new Vector2(1, 1); ArrayParticles[i * 4 + 3].UV = new Vector2(0, 1); } Effect effect = Content.Load <Effect>("Shaders/Particle shader 3D"); // If we have several particle systems, the content manager will return // a single shared effect instance to them all. But we want to preconfigure // the effect with parameters that are specific to this particular // particle system. By cloning the effect, we prevent one particle system // from stomping over the parameter settings of another. particleEffect = effect.Clone(); Parameters = particleEffect.Parameters; // Look up shortcuts for parameters that change every frame. effectViewParameter = Parameters["View"]; effectProjectionParameter = Parameters["Projection"]; effectViewportScaleParameter = Parameters["ViewportScale"]; effectTimeParameter = Parameters["CurrentTime"]; // Set the values of parameters that do not change. Parameters["NumberOfImages"].SetValue(NumberOfImages); Parameters["RotateTowardCamera"].SetValue(RotateTowardCamera ? 1f : 0); // Load the particle texture, and set it onto the effect. Texture2D sprBackground = Content.Load <Texture2D>(TextureName); Parameters["Size"].SetValue(new Vector2((sprBackground.Width / NumberOfImages) * 0.5f, sprBackground.Height * 0.5f)); Parameters["t0"].SetValue(sprBackground); _RepeatOffset.X = sprBackground.Width; _RepeatOffset.Y = sprBackground.Height; // Create a dynamic vertex buffer. vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, BillboardVertex.VertexDeclaration, MaxParticles * 4, BufferUsage.WriteOnly); // Create and populate the index buffer. ushort[] ArrayIndex = new ushort[MaxParticles * 6]; for (int i = 0; i < MaxParticles; i++) { ArrayIndex[i * 6 + 0] = (ushort)(i * 4 + 0); ArrayIndex[i * 6 + 1] = (ushort)(i * 4 + 1); ArrayIndex[i * 6 + 2] = (ushort)(i * 4 + 2); ArrayIndex[i * 6 + 3] = (ushort)(i * 4 + 0); ArrayIndex[i * 6 + 4] = (ushort)(i * 4 + 2); ArrayIndex[i * 6 + 5] = (ushort)(i * 4 + 3); } indexBuffer = new IndexBuffer(GraphicsDevice, typeof(ushort), ArrayIndex.Length, BufferUsage.WriteOnly); indexBuffer.SetData(ArrayIndex); }
public SemanticMappedTexture(EffectParameterCollection parent, string semanticName) : base(parent, semanticName.Replace("Texture", "Sampler")) { }
/// <summary> /// This is where it all happens. Grabs a scene that has already been rendered, /// and uses postprocess magic to add a glowing bloom effect over the top of it. /// </summary> public static void Draw(GameTime gameTime) { BeatShift.graphics.GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; // Pass 1: draw the scene into rendertarget 1, using a // shader that extracts only the brightest parts of the image. //bloomExtractEffect.Parameters["BloomThreshold"].SetValue(0.5f); //DrawFullscreenQuad(sceneRenderTarget, renderTarget1, bloomExtractEffect, IntermediateBuffer.PreBloom); // Pass 2: draw from rendertarget 1 into rendertarget 2, // using a shader to apply a horizontal gaussian blur filter. SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0); DrawFullscreenQuad(glowRenderTarget, renderTarget2,//renderTarget1, renderTarget2, gaussianBlurEffect, IntermediateBuffer.BlurredHorizontally); // Pass 3: draw from rendertarget 2 back into rendertarget 1, // using a shader to apply a vertical gaussian blur filter. SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height); DrawFullscreenQuad(renderTarget2, renderTarget1, gaussianBlurEffect, IntermediateBuffer.BlurredBothWays); // Pass 4: draw both rendertarget 1 and the original scene // image back into the main backbuffer, using a shader that // combines them to produce the final bloomed result. BeatShift.graphics.GraphicsDevice.SetRenderTarget(null); EffectParameterCollection parameters = bloomCombineEffect.Parameters; parameters["BloomIntensity"].SetValue(1f); parameters["BaseIntensity"].SetValue(1f); parameters["BloomSaturation"].SetValue(1f); parameters["BaseSaturation"].SetValue(1f); Viewport viewport = BeatShift.graphics.GraphicsDevice.Viewport; BeatShift.graphics.GraphicsDevice.Textures[1] = sceneRenderTarget; switch (Globals.TestState) { case 0: BeatShift.graphics.GraphicsDevice.BlendState = BlendState.Opaque; DrawFullscreenQuad(renderTarget1, viewport.Width, viewport.Height, bloomCombineEffect, IntermediateBuffer.FinalResult); break; case 1: DrawFullscreenQuad(glowRenderTarget, viewport.Width, viewport.Height, outputEffect, IntermediateBuffer.FinalResult); break; case 2: DrawFullscreenQuad(sceneRenderTarget, viewport.Width, viewport.Height, outputEffect, IntermediateBuffer.FinalResult); break; case 3: DrawFullscreenQuad(renderTarget1, viewport.Width, viewport.Height, outputEffect, IntermediateBuffer.FinalResult); break; case 4: DrawFullscreenQuad(renderTarget2, viewport.Width, viewport.Height, outputEffect, IntermediateBuffer.FinalResult); break; case 5: break; case 6: default: break; } }
public static EffectParameter TryGet(this EffectParameterCollection parameters, string name) => parameters.Any(parameter => parameter.Name == name) ? parameters[name] : null;
/// <summary> /// Helper applies the edge detection and pencil sketch postprocess effect. /// </summary> void ApplyPostprocess() { EffectParameterCollection parameters = postprocessEffect.Parameters; string effectTechniqueName; // Set effect parameters controlling the pencil sketch effect. if (Settings.EnableSketch) { parameters["SketchThreshold"].SetValue(Settings.SketchThreshold); parameters["SketchBrightness"].SetValue(Settings.SketchBrightness); parameters["SketchJitter"].SetValue(sketchJitter); parameters["SketchTexture"].SetValue(sketchTexture); } // Set effect parameters controlling the edge detection effect. if (Settings.EnableEdgeDetect) { Vector2 resolution = new Vector2(sceneRenderTarget.Width, sceneRenderTarget.Height); Texture2D normalDepthTexture = normalDepthRenderTarget; parameters["EdgeWidth"].SetValue(Settings.EdgeWidth); parameters["EdgeIntensity"].SetValue(Settings.EdgeIntensity); parameters["ScreenResolution"].SetValue(resolution); parameters["NormalDepthTexture"].SetValue(normalDepthTexture); // Choose which effect technique to use. if (Settings.EnableSketch) { if (Settings.SketchInColor) { effectTechniqueName = "EdgeDetectColorSketch"; } else { effectTechniqueName = "EdgeDetectMonoSketch"; } } else { effectTechniqueName = "EdgeDetect"; } } else { // If edge detection is off, just pick one of the sketch techniques. if (Settings.SketchInColor) { effectTechniqueName = "ColorSketch"; } else { effectTechniqueName = "MonoSketch"; } } // Activate the appropriate effect technique. postprocessEffect.CurrentTechnique = postprocessEffect.Techniques[effectTechniqueName]; // Draw a fullscreen sprite to apply the postprocessing effect. spriteBatch.Begin(0, BlendState.Opaque, null, null, null, postprocessEffect); spriteBatch.Draw(sceneRenderTarget, Vector2.Zero, Color.White); spriteBatch.End(); }
protected override void SetUpdateParameters(EffectParameterCollection parameters) { base.SetUpdateParameters(parameters); }
public void LoadContent(ContentManager Content, GraphicsDevice GraphicsDevice, Matrix Projection) { // Allocate the particle array, and fill in the corner fields (which never change). particles = new ParticleVertex[settings.MaxParticles * 4]; for (int i = 0; i < settings.MaxParticles; i++) { particles[i * 4 + 0].UV = new Vector2(0, 0); particles[i * 4 + 1].UV = new Vector2(1, 0); particles[i * 4 + 2].UV = new Vector2(1, 1); particles[i * 4 + 3].UV = new Vector2(0, 1); } Effect effect = Content.Load <Effect>("Shaders/Particle shader"); // If we have several particle systems, the content manager will return // a single shared effect instance to them all. But we want to preconfigure // the effect with parameters that are specific to this particular // particle system. By cloning the effect, we prevent one particle system // from stomping over the parameter settings of another. particleEffect = effect.Clone(); EffectParameterCollection parameters = particleEffect.Parameters; // Look up shortcuts for parameters that change every frame. effectViewProjectionParameter = parameters["ViewProjection"]; effectTimeParameter = parameters["CurrentTime"]; effectViewProjectionParameter.SetValue(Projection); // Set the values of parameters that do not change. parameters["Gravity"].SetValue(settings.Gravity); parameters["Duration"].SetValue((float)settings.Duration.TotalSeconds); parameters["SpeedMultiplier"].SetValue(60f); // Load the particle texture, and set it onto the effect. Texture2D texture = Content.Load <Texture2D>(settings.TextureName); settings.Size = new Vector2(texture.Width * 0.5f, texture.Height * 0.5f); parameters["Size"].SetValue(settings.Size); parameters["StartingAlpha"].SetValue(settings.StartingAlpha); parameters["EndAlpha"].SetValue(settings.EndAlpha); parameters["t0"].SetValue(texture); // Create a dynamic vertex buffer. vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, ParticleVertex.VertexDeclaration, settings.MaxParticles * 4, BufferUsage.WriteOnly); /* * // Create and populate the index buffer. * uint[] indices = new uint[settings.MaxParticles * 6]; * * for (int i = 0; i < settings.MaxParticles; i++) * { * indices[i * 6 + 0] = (uint)(i * 4 + 0); * indices[i * 6 + 1] = (uint)(i * 4 + 1); * indices[i * 6 + 2] = (uint)(i * 4 + 2); * * indices[i * 6 + 3] = (uint)(i * 4 + 0); * indices[i * 6 + 4] = (uint)(i * 4 + 2); * indices[i * 6 + 5] = (uint)(i * 4 + 3); * } * * indexBuffer = new IndexBuffer(GraphicsDevice, typeof(uint), indices.Length, BufferUsage.WriteOnly);*/ // Create and populate the index buffer. ushort[] indices = new ushort[settings.MaxParticles * 6]; for (int i = 0; i < settings.MaxParticles; i++) { indices[i * 6 + 0] = (ushort)(i * 4 + 0); indices[i * 6 + 1] = (ushort)(i * 4 + 1); indices[i * 6 + 2] = (ushort)(i * 4 + 2); indices[i * 6 + 3] = (ushort)(i * 4 + 0); indices[i * 6 + 4] = (ushort)(i * 4 + 2); indices[i * 6 + 5] = (ushort)(i * 4 + 3); } indexBuffer = new IndexBuffer(GraphicsDevice, typeof(ushort), indices.Length, BufferUsage.WriteOnly); indexBuffer.SetData(indices); }
protected SemanticMappedParameter(EffectParameterCollection parent, string semanticName) { this.parameter = parent[semanticName] ?? parent[semanticName.Replace("Sampler", "Texture")]; this.missingParameter = this.parameter == null; }
protected override void SetRenderingParameters(EffectParameterCollection parameters) { base.SetRenderingParameters(parameters); }
protected override void SetCreateParameters(EffectParameterCollection parameters) { parameters["SnowParticleLifetime"].SetValue(snowLifeTime); base.SetCreateParameters(parameters); }