Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
YebisPlugin.cs
Go to the documentation of this file.
1 // Copyright (c) 2011 ReShader - Alexandre Mutel
2 
3 using System;
4 using SiliconStudio.Paradox.Effects.Modules;
5 using SiliconStudio.Paradox.Effects.Yebis;
6 using SiliconStudio.Paradox.Graphics;
7 
8 namespace SiliconStudio.Paradox.Effects
9 {
11  {
12  private Manager yebis;
13 
14  public bool AntiAlias;
15 
16  public ToneMap ToneMap;
17 
18  public Glare Glare;
19 
20  public Lens Lens;
21 
22  public DepthOfField DepthOfField;
23 
24  public ColorCorrection ColorCorrection;
25 
26  public HeatShimmer HeatShimmer;
27 
28  public LightShaft LightShaft;
29 
30  /// <summary>
31  /// Initializes a new instance of the <see cref="YebisPlugin"/> class.
32  /// </summary>
33  public YebisPlugin() : this(null)
34  {
35  }
36 
37  /// <summary>
38  /// Initializes a new instance of the <see cref="YebisPlugin"/> class.
39  /// </summary>
40  /// <param name="name">The name.</param>
41  public YebisPlugin(string name) : base(name)
42  {
43  yebis = new Manager();
44  ToneMap = yebis.Config.ToneMap;
45  Glare = yebis.Config.Glare;
46  ColorCorrection = yebis.Config.ColorCorrection;
47  Lens = yebis.Config.Lens;
48  DepthOfField = yebis.Config.DepthOfField;
49  HeatShimmer = yebis.Config.HeatShimmer;
50  LightShaft = yebis.Config.LightShaft;
51  PreferredFormat = PixelFormat.R16G16B16A16_Float;
52 
53  // Make sure that the Depth Stencil will be created with ShaderResource
54  Tags.Set(RenderTargetKeys.RequireDepthStencilShaderResource, true);
55  }
56 
57  public ParameterCollection ViewParameters { get; set; }
58 
59  public PixelFormat PreferredFormat { get; set; }
60 
61  public Texture2D RenderSource { get; set; }
62 
63  public DepthStencilBuffer SourceDepth { get; set; }
64 
65  public RenderTarget RenderTarget { get; set; }
66 
67  private void CopyParametersToYebis()
68  {
69  // Retrieve defaults
70  if (ViewParameters != null)
71  {
72  yebis.Config.Camera.NearClipPlane = ViewParameters.Get(CameraKeys.NearClipPlane);
73  yebis.Config.Camera.FarClipPlane = ViewParameters.Get(CameraKeys.FarClipPlane);
74  yebis.Config.Camera.FieldOfView = ViewParameters.Get(CameraKeys.FieldOfView);
75  ViewParameters.Get(TransformationKeys.View, out yebis.Config.Camera.View);
76 
77  // Reverse value for Z and recalculate matrix projection
78  yebis.Config.Camera.IsZReverse = yebis.Config.Camera.NearClipPlane > yebis.Config.Camera.FarClipPlane;
79  float nearClipPlane = yebis.Config.Camera.IsZReverse ? yebis.Config.Camera.FarClipPlane : yebis.Config.Camera.NearClipPlane;
80  float farClipPlane = yebis.Config.Camera.IsZReverse ? yebis.Config.Camera.NearClipPlane : yebis.Config.Camera.FarClipPlane;
81  yebis.Config.Camera.NearClipPlane = nearClipPlane;
82  yebis.Config.Camera.FarClipPlane = farClipPlane;
83 
84  var focusDistance = ViewParameters.Get(CameraKeys.FocusDistance);
85  DepthOfField.AutoFocus = (focusDistance < 0.01);
86  if (!DepthOfField.AutoFocus)
87  {
88  DepthOfField.FocusDistance = focusDistance;
89  }
90  }
91 
92  yebis.Config.AntiAlias = AntiAlias;
93  yebis.Config.ToneMap = ToneMap;
94  yebis.Config.Glare = Glare;
95  yebis.Config.ColorCorrection = ColorCorrection;
96  yebis.Config.Lens = Lens;
97  yebis.Config.DepthOfField = DepthOfField;
98  yebis.Config.HeatShimmer = HeatShimmer;
99  yebis.Config.LightShaft = LightShaft;
100  }
101 
102  public override void Load()
103  {
104  base.Load();
105 
106  if (OfflineCompilation)
107  return;
108 
109  RenderPass.StartPass += (context) =>
110  {
111  CopyParametersToYebis();
112  yebis.Apply();
113 
114  if (ToneMap.AutoExposure.Enable)
115  ToneMap.Exposure = yebis.Config.ToneMap.Exposure;
116 
117  DepthOfField.FocusDistance = yebis.Config.DepthOfField.FocusDistance;
118  };
119 
120  //var deviceContextPtr = RenderContext.GraphicsDeviceContext.NativeDeviceContext.NativePointer;
121 
122  //var renderTargetViewPtr = RenderTarget.NativeRenderTargetView.NativePointer;
123 
124  yebis.Initialize(GraphicsDevice, RenderTarget);
125  yebis.SetSource(RenderSource, SourceDepth.Texture);
126  }
127  }
128 }
YebisPlugin()
Initializes a new instance of the YebisPlugin class.
Definition: YebisPlugin.cs:33
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.
A Texture 2D frontend to SharpDX.Direct3D11.Texture2D.
Definition: Texture2D.cs:37
YebisPlugin(string name)
Initializes a new instance of the YebisPlugin class.
Definition: YebisPlugin.cs:41
PixelFormat
Defines various types of pixel formats.
Definition: PixelFormat.cs:32
A container to handle a hierarchical collection of effect variables.