-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathRenderProxy.hpp
More file actions
398 lines (314 loc) · 7.6 KB
/
RenderProxy.hpp
File metadata and controls
398 lines (314 loc) · 7.6 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/* Copyright (c) 2016-2026 Andrew J. MacDonald. All rights reserved. */
#pragma once
#include <Core/utilities/EnumFlags.hpp>
#include <Core/containers/FixedArray.hpp>
#include <Core/math/BoundingBox.hpp>
#include <Core/math/Mat4f.hpp>
#include <Core/math/Frustum.hpp>
#include <rendering/RenderableAttributes.hpp>
#include <rendering/RenderObject.hpp>
namespace Hyperion {
class Entity;
class Mesh;
class Light;
class Camera;
class View;
class Texture;
class LightmapVolume;
class ParticleVolume;
class FogVolume;
class Material;
class Skeleton;
class EnvProbe;
class EnvGrid;
class ShadowMap;
class InstancedMeshData;
enum LightmapTextureType : uint32;
HYP_STRUCT()
struct MeshRayTracingData
{
HYP_STRUCT_BODY(MeshRayTracingData);
HYP_FIELD(NoScriptBindings)
GpuBlasRef blas;
~MeshRayTracingData();
};
class IRenderProxy
{
public:
int version = 0;
bool forceRebind = false;
};
class NullProxy final : public IRenderProxy
{
private:
NullProxy() = default;
};
struct alignas(16) WorldShaderData
{
Vec4f fogParams;
float gameTime;
uint32 frameCounter;
uint32 _pad0;
uint32 _pad1;
};
struct alignas(16) EntityShaderData
{
Mat4f modelMatrix;
Mat4f previousModelMatrix;
Mat3f normalMatrix;
Vec3f worldAabbMax;
Vec3f worldAabbMin;
uint32 entityIndex = ~0u;
uint32 lightmapVolumeIndex = ~0u;
uint32 materialIndex = ~0u;
uint32 skeletonIndex = ~0u;
uint32 bucket;
uint32 flags;
uint32 _pad0;
uint32 _pad1;
Vec4f _pad2;
};
enum class LightmapElementId : uint32;
struct InstanceData
{
static constexpr uint32 MaxBuffers = 5;
ByteBuffer buffers[MaxBuffers];
uint32 bufferStructSizes[MaxBuffers] {};
uint32 bufferStructAlignments[MaxBuffers] {};
};
/*! \brief Proxy for a renderable Entity with a valid Mesh and Material assigned */
class RenderProxyMesh final : public IRenderProxy
{
public:
WeakHandle<Entity> entity;
Mesh* mesh = nullptr;
Material* material = nullptr;
Skeleton* skeleton = nullptr;
uint32 numIndices = 0;
uint32 numInstances = 1;
bool enableAutoInstancing = false;
LightmapVolume* lightmapVolume = nullptr;
LightmapElementId lightmapElementId = LightmapElementId(~0u);
RenderableAttributeSet cachedAttributes;
InstanceData instanceData;
MeshRayTracingData rayTracingData;
EntityShaderData bufferData {};
};
struct alignas(16) EnvProbeShaderData
{
Mat4f faceViewMatrices[6];
Vec4f aabbMax;
Vec4f aabbMin;
Vec4f worldPosition;
uint32 textureIndex = ~0u;
uint32 flags = 0;
float cameraNear = 0.01f;
float cameraFar = 100.0f;
Vec2u dimensions;
uint64 visibilityBits = 0;
Vec4f shData[9];
};
class RenderProxyEnvProbe final : public IRenderProxy
{
public:
WeakHandle<EnvProbe> envProbe;
Texture* texture = nullptr; // baked cubemap texture or prefiltered env
EnvProbeShaderData bufferData {};
};
struct alignas(16) EnvGridShaderData
{
// Nothing for now until we add the new env grid (baked)
Vec4f dummy;
};
class RenderProxyEnvGrid final : public IRenderProxy
{
public:
WeakHandle<EnvGrid> envGrid;
EnvGridShaderData bufferData {};
};
struct alignas(16) ShadowMapData
{
uint32 layerIndex;
float splitDistance;
float _pad0;
float _pad1;
Mat4f viewProjMat;
Vec4f aabbMin; // w = offsetUV.x
Vec4f aabbMax; // w = offsetUV.y
Vec4f dimensionsScale; // xy = shadow map dimensions in pixels, zw = shadow map dimensions relative to the atlas dimensions
};
struct alignas(16) LightShaderData
{
uint32 lightType;
uint32 materialIndex;
uint32 radiusFalloffPacked;
uint32 flags;
Vec4f positionIntensity;
Vec4f color;
union
{
Vec3f areaNormal;
Vec3f spotLightDir;
};
Vec2f areaSize; // also angles for spot lights
Vec2f _pad0;
Vec4f _pad1[3];
};
class RenderProxyLight final : public IRenderProxy
{
public:
WeakHandle<Light> light;
Material* lightMaterial = nullptr; // for textured area lights
uint32 numCascades = 0;
LightShaderData bufferData {};
};
struct alignas(16) LightmapVolumeShaderData
{
Vec4f aabbMax;
Vec4f aabbMin;
uint32 textureIndex;
uint32 _pad0;
uint32 _pad1;
uint32 _pad2;
};
class RenderProxyLightmapVolume final : public IRenderProxy
{
public:
WeakHandle<LightmapVolume> lightmapVolume;
Array<Texture*> atlasIrradianceTextures;
Array<Texture*> atlasRadianceTextures;
uint32 numAtlases = 0;
LightmapVolumeShaderData bufferData {};
};
struct alignas(16) ParticleVolumeShaderData
{
Vec4f originStartSize; // xyz = origin, w = start size
float spawnRadius = 0.0f;
float randomness = 0.0f;
float avgLifespan = 0.0f;
uint32 maxParticles = 0;
float maxParticlesSqrt = 0.0f;
float _pad0 = 0.0f;
float _pad1 = 0.0f;
float _pad2 = 0.0f;
};
class RenderProxyParticleVolume final : public IRenderProxy
{
public:
WeakHandle<ParticleVolume> particleVolume;
Texture* particleTexture = nullptr;
BoundingBox worldAabb; // for culling/debug
ParticleVolumeShaderData bufferData {};
};
struct alignas(16) FogVolumeShaderData
{
Mat4f transformMatrix;
Vec4f aabbMin;
Vec4f aabbMax;
uint32 numBoundLights;
Vec4u lightIndices[4];
};
class RenderProxyFogVolume final : public IRenderProxy
{
public:
WeakHandle<FogVolume> fogVolume;
Texture* volumeTexture = nullptr;
Texture* noiseTexture = nullptr;
BoundingBox worldAabb;
FogVolumeShaderData bufferData {};
};
struct alignas(16) MaterialShaderData
{
Vec4f albedo;
// 4 vec4s of 0.0..1.0 values stuffed into uint32s
Vec4u packedParams;
Vec2f uvScale;
float parallaxHeight;
uint32 textureUsage;
Vec4u textureIndices[4];
Vec4f _pad0;
};
class RenderProxyMaterial final : public IRenderProxy
{
public:
RenderProxyMaterial()
{
for (uint32 i = 0; i < MaxBoundTextures; ++i)
{
boundTextureIndices[i] = ~0u;
}
}
WeakHandle<Material> material;
MaterialAttributes attributes;
MaterialShaderData bufferData {};
FixedArray<uint32, MaxBoundTextures> boundTextureIndices;
Array<Handle<Texture>> boundTextures;
};
struct alignas(16) SkeletonShaderData
{
static constexpr size_t maxBones = 256;
Mat4f bones[maxBones];
};
class RenderProxySkeleton final : public IRenderProxy
{
public:
RenderProxySkeleton()
{
for (size_t i = 0; i < SkeletonShaderData::maxBones; ++i)
{
bufferData.bones[i] = Mat4f::Identity();
}
}
WeakHandle<Skeleton> skeleton;
SkeletonShaderData bufferData {};
};
struct alignas(16) CameraShaderData
{
Mat4f viewMat;
Mat4f projMat;
Mat4f viewProjMat;
Mat4f inverseViewMat;
Mat4f inverseProjMat;
Mat4f prevViewProjMat;
Vec4u dimensions;
Vec4f cameraPosition;
Vec4f cameraDirection;
Vec4f jitter;
float cameraNear;
float cameraFar;
float cameraFov;
float _pad;
Vec4f _pad1;
Vec4f _pad2;
Vec4f _pad3;
};
class RenderProxyCamera final : public IRenderProxy
{
public:
WeakHandle<Camera> camera;
CameraShaderData bufferData {};
Frustum viewFrustum;
};
struct ProbeRayData
{
Vec4f directionDepth;
Vec4f origin;
Vec4f normal;
Vec4f color;
};
struct alignas(16) DDGIConstants
{
Mat4f rotationMatrix;
Vec4f aabbMax;
Vec4f aabbMin;
Vec4u probeBorder;
Vec4u probeCounts;
Vec4u gridDimensions;
Vec4u imageDimensions;
float probeDistance;
uint32 numRaysPerProbe;
uint32 numBoundLights;
uint32 flags;
Vec4u lightIndices[4];
};
} // namespace Hyperion