-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPostProcess.cs
176 lines (138 loc) · 5.01 KB
/
PostProcess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using Core;
using Core.Buffer;
using Core.CustomAttribute;
using Core.Primitive;
using Core.Texture;
using OpenTK.Graphics.OpenGL;
using System.Collections.Generic;
using OpenTK.Mathematics;
namespace Engine.PostProcess
{
public abstract class PostProcessBase : RenderingThreadObject
{
public PostProcessBase()
{
Initialize();
}
[ExposeUI]
public string Name { get; set; }
public override void Initialize()
{
// create vertex, index buffer for screen space drawing
VB = new AOSVertexBuffer<PT_VertexAttribute>();
IB = new IndexBuffer();
VA = new VertexArray();
VA.Bind();
UpdateVertexBuffer();
UpdateIndexBuffer();
//
if (bOwnItsRenderTarget)
{
// create render target
if (bCreateCustomRenderTarget)
{
CreateCustomRenderTarget();
}
else
{
CreateDefaultRenderTarget();
}
}
}
protected void BlitToScreenSpace()
{
using (var s = new ScopedBind(VA,VB, IB))
{
GL.DrawElements(PrimitiveType.Triangles, 6, DrawElementsType.UnsignedInt, 0);
}
}
protected virtual void CreateDefaultRenderTarget()
{
Output = new RenderTarget(1024,768,1, false);
Output.Initialize();
}
protected virtual void CreateCustomRenderTarget()
{
}
public virtual void Render()
{
}
public virtual void Render(TextureBase Input0)
{
}
public virtual void Render(TextureBase Input0, TextureBase Input1)
{
}
public virtual void Render(TextureBase Input0, TextureBase Input1, TextureBase Input2)
{
}
public virtual void Render(TextureBase Input0, TextureBase Input1, TextureBase Input3, TextureBase Input4)
{
}
public virtual void Render(TextureBase Input0, TextureBase Input1, TextureBase Input3, TextureBase Input4, TextureBase Input5)
{
}
public virtual void Render(TextureBase Input0, TextureBase Input1, TextureBase Input3, TextureBase Input4, TextureBase Input5, TextureBase Input6)
{
}
public RenderTarget GetOutputRenderTarget()
{
return Output;
}
public RenderTarget OutputRenderTarget => Output;
public TextureBase OutputColorTex0 => Output.ColorAttachment0;
public TextureBase OutputColorTex1 => Output.ColorAttachment1;
public TextureBase OutputColorTex2 => Output.ColorAttachment2;
// this could be null
protected RenderTarget Output;
protected Core.MaterialBase.MaterialBase PostProcessMaterial = null;
// indices and vertices to draw in screen space
protected List<uint> Indices = new List<uint>();
protected AOSVertexBuffer<PT_VertexAttribute> VB = null;
protected IndexBuffer IB = null;
protected VertexArray VA = null;
List<PT_VertexAttribute> VertexList = new List<PT_VertexAttribute>();
protected bool bCreateCustomRenderTarget = false;
protected bool bOwnItsRenderTarget = true;
protected void UpdateIndexBuffer()
{
// feed index buffer
uint[] IndexArray = { 0, 1, 2, 3, 4, 5 };
IB.Bind();
IB.BufferData<uint>(IndexArray);
}
protected void UpdateVertexBuffer()
{
VertexList.Clear();
var EachVertex = new PT_VertexAttribute();
// uppper left
EachVertex.VertexPosition = new Vector3(-1, 1, 0);
EachVertex.TexCoord = new Vector2(0, 1);
VertexList.Add(EachVertex);
// lower right
EachVertex.VertexPosition = new Vector3(1, -1, 0);
EachVertex.TexCoord = new Vector2(1, 0);
VertexList.Add(EachVertex);
// lower left
EachVertex.VertexPosition = new Vector3(-1, -1, 0);
EachVertex.TexCoord = new Vector2(0, 0);
VertexList.Add(EachVertex);
// upper left
EachVertex.VertexPosition = new Vector3(-1, 1, 0);
EachVertex.TexCoord = new Vector2(0, 1);
VertexList.Add(EachVertex);
// upper right
EachVertex.VertexPosition = new Vector3(1, 1, 0);
EachVertex.TexCoord = new Vector2(1, 1);
VertexList.Add(EachVertex);
// lower right
EachVertex.VertexPosition = new Vector3(1, -1, 0);
EachVertex.TexCoord = new Vector2(1, 0);
VertexList.Add(EachVertex);
// feed vertex buffer
VB.Bind();
var VertexArray = VertexList.ToArray();
VB.BufferData<PT_VertexAttribute>(VertexArray);
}
}
}