Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
MinMaxShaderPlugin.cs
Go to the documentation of this file.
1 // Copyright (c) 2011 Silicon Studio
2 
3 using SiliconStudio.Paradox.Graphics;
4 using SiliconStudio.Paradox.Shaders;
5 
6 namespace SiliconStudio.Paradox.Effects
7 {
8  /// <summary>
9  /// Light Shaft plugin.
10  /// </summary>
11  public class MinMaxShaderPlugin : ShaderPlugin<RenderPassPlugin>
12  {
13  private EffectShaderPass minPass;
14  private EffectShaderPass maxPass;
15 
16 
17  /// <summary>
18  /// Initializes a new instance of class <see cref="LightShaftsPlugin"/>.
19  /// </summary>
20  public MinMaxShaderPlugin() : this(null)
21  {
22  }
23 
24  /// <summary>
25  /// Initializes a new instance of class <see cref="LightShaftsPlugin"/>.
26  /// </summary>
27  public MinMaxShaderPlugin(string name)
28  : base(name)
29  {
30  MinMaxShader = new ShaderClassSource("MinMaxBounding");
31  }
32 
33  public ShaderClassSource MinMaxShader { get; set; }
34 
35  /// <param name="effectMesh"></param>
36  /// <inheritdoc/>
37  public override void SetupPasses(EffectMesh effectMesh)
38  {
39  // Special case: We have 2 shader passes that are sharing the same Shader, but with different parameters
40  throw new System.NotImplementedException();
41  //maxPass = CreateShaderPass(RenderPassPlugin.RenderPass, "MaxPass", RenderPassPlugin.Parameters);
42  //minPass = CreateShaderPass(RenderPassPlugin.RenderPass, "MinPass", RenderPassPlugin.Parameters);
43  DefaultShaderPass = maxPass;
44  }
45 
46  /// <param name="effectMesh"></param>
47  /// <inheritdoc/>
48  public override void SetupShaders(EffectMesh effectMesh)
49  {
50  maxPass.Shader.Mixins.Add(MinMaxShader);
51  minPass.Shader = maxPass.Shader;
52  }
53 
54  public override void SetupResources(EffectMesh effectMesh)
55  {
56  base.SetupResources(effectMesh);
57 
58  Effect.Parameters.RegisterParameter(BlendStateKey);
59  Effect.Parameters.RegisterParameter(RasterizerStateKey);
60 
61  // Create blendstate for min calculation
62  var bbBlendDesc = new BlendStateDescription();
63  bbBlendDesc.SetDefaults();
64  bbBlendDesc.AlphaToCoverageEnable = false;
65  bbBlendDesc.IndependentBlendEnable = false;
66  bbBlendDesc.RenderTargets[0].BlendEnable = true;
67  bbBlendDesc.RenderTargets[0].ColorSourceBlend = Blend.One;
68  bbBlendDesc.RenderTargets[0].ColorDestinationBlend = Blend.One;
69 
70  bbBlendDesc.RenderTargets[0].ColorBlendFunction = BlendFunction.Max;
71  bbBlendDesc.RenderTargets[0].ColorWriteChannels = ColorWriteChannels.Red;
72  var blendMinState = BlendState.New(GraphicsDevice, bbBlendDesc);
73  blendMinState.Name = "MinBlend";
74 
75  // Create blendstate for max calculation
76  bbBlendDesc.RenderTargets[0].ColorBlendFunction = BlendFunction.Max;
77  bbBlendDesc.RenderTargets[0].ColorWriteChannels = ColorWriteChannels.Green;
78  var blendMaxState = BlendState.New(GraphicsDevice, bbBlendDesc);
79  blendMaxState.Name= "MaxBlend";
80 
81  maxPass.Parameters.Set(RasterizerStateKey, GraphicsDevice.RasterizerStates.CullFront);
82  maxPass.Parameters.Set(BlendStateKey, blendMaxState);
83 
84  minPass.Parameters.Set(RasterizerStateKey, GraphicsDevice.RasterizerStates.CullBack);
85  minPass.Parameters.Set(BlendStateKey, blendMinState);
86  }
87  }
88 }
MinMaxShaderPlugin(string name)
Initializes a new instance of class LightShaftsPlugin.
MinMaxShaderPlugin()
Initializes a new instance of class LightShaftsPlugin.
override void SetupPasses(EffectMesh effectMesh)
override void SetupShaders(EffectMesh effectMesh)
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
override void SetupResources(EffectMesh effectMesh)
ColorWriteChannels
Identify which components of each pixel of a render target are writable during blending.