Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PostEffectSeparateShaderPlugin.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using SiliconStudio.Core.Mathematics;
4 using SiliconStudio.Paradox.Effects.Data;
5 using SiliconStudio.Paradox.Effects.Modules;
6 using SiliconStudio.Paradox.Graphics;
7 using SiliconStudio.Paradox.Shaders;
8 
10 
11 namespace SiliconStudio.Paradox.Effects
12 {
13  /// <summary>
14  /// TODO: Update summary.
15  /// </summary>
16  public class PostEffectSeparateShaderPlugin : ShaderPlugin<RenderPassPlugin>
17  {
18  /// <param name="effectMesh"></param>
19  /// <inheritdoc/>
20  /// <inheritdoc/>
21  public override void SetupShaders(EffectMesh effectMesh)
22  {
23  // Create shader from base shader
24  var postEffect = new ShaderClassSource("PostEffectBase");
25  DefaultShaderPass.Shader.Mixins.Add(postEffect);
26  }
27 
28  /// <param name="effectMesh"></param>
29  /// <inheritdoc/>
30  public override void SetupResources(EffectMesh effectMesh)
31  {
32  // PrepareMesh event so that this quad is used for each EffectMesh
33  Effect.PrepareMesh += SetupMeshResources;
34  }
35 
36  void SetupMeshResources(EffectOld effect, EffectMesh effectMesh)
37  {
38  // Generates a quad for post effect rendering (should be utility function)
39  var vertices = new[]
40  {
41  -1.0f, 1.0f,
42  1.0f, 1.0f,
43  -1.0f, -1.0f,
44  1.0f, -1.0f,
45  };
46 
47  // Use the quad for this effectMesh
48  effectMesh.MeshData.Draw = new MeshDraw
49  {
50  DrawCount = 4,
51  PrimitiveType = PrimitiveType.TriangleStrip,
52  VertexBuffers = new[]
53  {
55  }
56  };
57 
58  // TODO: unbind render targets
59  var previousRender = effectMesh.Render;
60  effectMesh.Render += (threadContext) =>
61  {
62  // Setup render target
63  var renderTarget = effectMesh.Parameters.Get(RenderTargetKeys.RenderTarget);
64  var desc = renderTarget.Description;
65  threadContext.GraphicsDevice.SetViewport(new Viewport(0, 0, desc.Width, desc.Height));
66  threadContext.GraphicsDevice.SetRenderTarget(renderTarget);
67 
68  // Draw
69  previousRender.Invoke(threadContext);
70 
71  // Unbind RenderTargets
72  threadContext.GraphicsDevice.UnsetRenderTargets();
73  };
74  }
75  }
76 }
override void SetupShaders(EffectMesh effectMesh)
The layout of a vertex buffer with a set of VertexElement.
Represents a two dimensional mathematical vector.
Definition: Vector2.cs:42
TODO: Update summary.
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
Defines the window dimensions of a render-target surface onto which a 3D volume projects.
Definition: Viewport.cs:14
static VertexElement Position(PixelFormat format, int offsetInBytes=AppendAligned)
Declares a VertexElement with the semantic "POSITION".
PrimitiveType
Defines how vertex data is ordered.
A description of a single element for the input-assembler stage. This structure is related to Direct3...
SiliconStudio.Paradox.Graphics.Buffer Buffer
override void SetupResources(EffectMesh effectMesh)
Binding structure that specifies a vertex buffer and other per-vertex parameters (such as offset and ...