Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
SlideShowPlugin.cs
Go to the documentation of this file.
1 // Copyright (c) 2011 Silicon Studio
2 
3 using System;
4 using System.Collections.Generic;
5 
6 using SiliconStudio.Paradox.DataModel;
7 using SiliconStudio.Paradox.Effects.Data;
8 using SiliconStudio.Paradox.Effects.Modules;
9 using SiliconStudio.Paradox;
10 using SiliconStudio.Paradox.Graphics;
11 using SiliconStudio.Core;
12 using SiliconStudio.Core.Mathematics;
13 using SiliconStudio.Paradox.Shaders;
14 
16 
17 namespace SiliconStudio.Paradox.Effects
18 {
19  /// <summary>
20  /// Posteffect manager.
21  /// </summary>
23  {
24  private EffectOld slideShowEffect;
25 
26  public SlideShowPlugin()
27  : this(null)
28  {
29  }
30 
31  public SlideShowPlugin(string name) : base(name)
32  {
33  Parameters.RegisterParameter(TexturingKeys.Texture0);
34  Parameters.RegisterParameter(TexturingKeys.Texture2);
35  Parameters.RegisterParameter(PostEffectTransitionKeys.ColorFactorFrom);
36  Parameters.RegisterParameter(PostEffectTransitionKeys.ColorFactorTo);
37  Parameters.RegisterParameter(PostEffectTransitionKeys.TransitionFactor);
38  Parameters.RegisterParameter(PostEffectTransitionKeys.ZoomFactor);
39 
40  TransitionFactor = 0.0f;
41  ZoomFactor = 1.0f;
42  ColorFactorFrom = Color.White;
43  ColorFactorTo = Color.White;
44  }
45 
46  public MainPlugin MainPlugin { get; set; }
47 
48  public RenderTargetsPlugin MainTargetPlugin { get; set; }
49 
50  public Texture2D TextureFrom
51  {
52  get
53  {
54  return Parameters.Get(TexturingKeys.Texture0);
55  }
56  set
57  {
58  Parameters.Set(TexturingKeys.Texture0, value);
59  }
60  }
61 
62  public Texture2D TextureTo
63  {
64  get
65  {
66  return Parameters.Get(TexturingKeys.Texture2);
67  }
68  set
69  {
70  Parameters.Set(TexturingKeys.Texture2, value);
71  }
72  }
73 
74  public Color ColorFactorFrom
75  {
76  get
77  {
78  return (Color)Parameters.Get(PostEffectTransitionKeys.ColorFactorFrom);
79  }
80  set
81  {
82  Parameters.Set(PostEffectTransitionKeys.ColorFactorFrom, value.ToVector4());
83  }
84  }
85 
86  public Color ColorFactorTo
87  {
88  get
89  {
90  return (Color)Parameters.Get(PostEffectTransitionKeys.ColorFactorTo);
91  }
92  set
93  {
94  Parameters.Set(PostEffectTransitionKeys.ColorFactorTo, value.ToVector4());
95  }
96  }
97 
98  public float TransitionFactor
99  {
100  get
101  {
102  return Parameters.Get(PostEffectTransitionKeys.TransitionFactor);
103  }
104  set
105  {
106  Parameters.Set(PostEffectTransitionKeys.TransitionFactor, value);
107  }
108  }
109 
110  public float ZoomFactor
111  {
112  get
113  {
114  return Parameters.Get(PostEffectTransitionKeys.ZoomFactor);
115  }
116  set
117  {
118  Parameters.Set(PostEffectTransitionKeys.ZoomFactor, value);
119  }
120  }
121 
122  public override void Load()
123  {
124  base.Load();
125 
126  slideShowEffect = this.EffectSystemOld.BuildEffect("SlideShow")
127  .Using(new StateShaderPlugin() { RenderPassPlugin = this, UseDepthStencilState = true})
128  .Using(new BasicShaderPlugin(new ShaderClassSource("PostEffectTransition")) { RenderPassPlugin = this })
129  .InstantiatePermutation();
130 
131  if (OfflineCompilation)
132  return;
133 
134  RenderPass.StartPass += (context) =>
135  {
136  if (RenderPass.Enabled)
137  {
138  // Setup the Viewport
139  context.GraphicsDevice.SetViewport(MainTargetPlugin.Viewport);
140 
141  // Setup the depth stencil and main render target.
142  context.GraphicsDevice.SetRenderTarget(RenderTarget);
143  }
144  };
145 
146  RenderPass.EndPass += (context) =>
147  {
148  if (RenderPass.Enabled)
149  {
150  context.GraphicsDevice.UnsetRenderTargets();
151  }
152  };
153 
154  // Generates a quad for post effect rendering (should be utility function)
155  var vertices = new[]
156  {
157  -1.0f, 1.0f,
158  1.0f, 1.0f,
159  -1.0f, -1.0f,
160  1.0f, -1.0f,
161  };
162 
163  // Use the quad for this effectMesh
164  var quadData = new Mesh();
165  quadData.Draw = new MeshDraw
166  {
167  DrawCount = 4,
168  PrimitiveType = PrimitiveType.TriangleStrip,
169  VertexBuffers = new[]
170  {
172  }
173  };
174  var textureMesh = new EffectMesh(slideShowEffect, quadData).KeepAliveBy(this);
175  textureMesh.Parameters.Set(EffectPlugin.DepthStencilStateKey, GraphicsDevice.DepthStencilStates.None);
176 
177  textureMesh.Parameters.AddSources(this.Parameters);
178  RenderSystem.GlobalMeshes.AddMesh(textureMesh);
179  }
180 
181  public RenderTarget RenderTarget { get; set; }
182  }
183 }
bool Enabled
Gets or sets a value indicating whether this RenderPass is enabled for collection.
Definition: RenderPass.cs:90
The layout of a vertex buffer with a set of VertexElement.
SiliconStudio.Paradox.Graphics.Buffer Buffer
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
Basic shader plugin built directly from shader source file.
All-in-One Buffer class linked SharpDX.Direct3D11.Buffer.
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.
static Buffer New(GraphicsDevice device, BufferDescription description, PixelFormat viewFormat=PixelFormat.None)
Creates a new Buffer instance.
Definition: Buffer.cs:343
Represents a 32-bit color (4 bytes) in the form of RGBA (in byte order: R, G, B, A).
Definition: Color.cs:16
Plugin used for the main rendering view.
Definition: MainPlugin.cs:15
static VertexElement Position(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "POSITION".
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37
Level10 render pass using a depth buffer and a render target.
PrimitiveType
Defines how vertex data is ordered.
RenderPass is a hierarchy that defines how to collect and render meshes.
Definition: RenderPass.cs:19
A description of a single element for the input-assembler stage. This structure is related to Direct3...
Binding structure that specifies a vertex buffer and other per-vertex parameters (such as offset and ...