Skip to content

Commit 9d5b57d

Browse files
Merge branch 'new-scenerenderer' into development
# Conflicts: # Engine/Source/Volt-Assets/Private/Volt-Assets/FontAsset.cpp # Engine/Source/VulkanRHIModule/Private/VulkanRHIModule/Graphics/VulkanGraphicsDevice.cpp
2 parents fd78d45 + 48badfc commit 9d5b57d

378 files changed

Lines changed: 5444 additions & 12043 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#pragma once
2+
3+
#include "GPUTransform.h"
4+
#include "HLSLNamespace.h"
5+
#include "HLSLTypes.h"
6+
7+
#if __cplusplus
8+
#include <RenderCore/RenderGraph/ShaderParameterStruct.h>
9+
10+
#include <RHIModule/Descriptors/BindlessIndex.h>
11+
12+
#else
13+
typedef uint32_t BindlessIndex;
14+
#endif
15+
16+
VT_NAMESPACE_HLSL_BEGIN
17+
enum RenderSceneInstanceFlags
18+
{
19+
RSIF_None = 0,
20+
RSIF_Valid = 1u << 0u
21+
};
22+
23+
enum LightSceneInstanceFlags
24+
{
25+
LSIF_None = 0,
26+
LSIF_Valid = 1u << 0,
27+
LSIF_CastShadows = 1u << 1u
28+
};
29+
30+
enum LightType
31+
{
32+
LT_Directional = 0,
33+
LT_Point = 1,
34+
LT_Spot = 2,
35+
LT_Sky = 3
36+
};
37+
38+
struct GPUMesh
39+
{
40+
BindlessIndex vertexPositionsBuffer;
41+
BindlessIndex vertexMaterialBuffer;
42+
BindlessIndex vertexAnimationBuffer;
43+
BindlessIndex indexBuffer;
44+
45+
uint32_t vertexStartOffset;
46+
uint32_t indexStartOffset;
47+
};
48+
49+
struct GPUMaterial
50+
{
51+
BindlessIndex textures[8];
52+
BindlessIndex samplers[8];
53+
54+
uint32_t numTextures;
55+
uint32_t flags;
56+
uint32_t padding[2];
57+
};
58+
59+
struct RenderSceneInstanceData
60+
{
61+
GPUTransform transform;
62+
63+
uint32_t meshIndex;
64+
uint32_t materialIndex;
65+
uint32_t entityId;
66+
RenderSceneInstanceFlags flags;
67+
68+
uint32_t isAnimated;
69+
uint32_t boneOffset;
70+
71+
uint2 padding;
72+
};
73+
74+
struct LightSceneInstanceData
75+
{
76+
LightType type;
77+
float3 position;
78+
79+
LightSceneInstanceFlags flags;
80+
float3 direction;
81+
82+
float intensity;
83+
float3 color;
84+
85+
// Point: .x=radius, .y=falloff
86+
// Spot: .x=range, .y=falloff, .z=lightAngleScale .w=lightAngleOffset
87+
// Dir: .x=angularRadius
88+
// Sky: x=LOD
89+
float4 lightSpecific;
90+
};
91+
VT_NAMESPACE_HLSL_END
92+
93+
#if __cplusplus
94+
BEGIN_SHADER_PARAMETER_STRUCT(GPUSceneParametersBindless)
95+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<RenderSceneInstanceData>, R_RenderSceneInstances)
96+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<GPUMesh>, R_GPUMeshes)
97+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<GPUMaterial>, R_GPUMaterials)
98+
END_SHADER_PARAMETER_STRUCT()
99+
100+
BEGIN_SHADER_PARAMETER_STRUCT(LightSceneParameters)
101+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<LightSceneInstanceData>, R_LightSceneInstances)
102+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<uint>, R_ValidLightSceneInstances)
103+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<uint>, R_ValidLightSceneInstanceCounter)
104+
END_SHADER_PARAMETER_STRUCT()
105+
106+
BEGIN_SHADER_PARAMETER_STRUCT(CulledLightSceneParameters)
107+
SHADER_PARAMETER_BUFFER_SRV(StructuredBuffer<uint>, R_VisibleLightIndices)
108+
SHADER_PARAMETER_STRUCT_INCLUDE(LightSceneParameters, LightScene)
109+
SHADER_PARAMETER(uint2, NumLightTiles)
110+
END_SHADER_PARAMETER_STRUCT()
111+
#endif
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#pragma once
2+
3+
#include "HLSLNamespace.h"
4+
5+
#if __cplusplus
6+
7+
#include "HLSLTypes.h"
8+
using Quaternion = glm::quat;
9+
10+
#else
11+
#include "Math/Quaternion.hlsli"
12+
#endif
13+
14+
VT_NAMESPACE_HLSL_BEGIN
15+
16+
struct GPUTransform
17+
{
18+
Quaternion rotation;
19+
float3 position;
20+
float padding0;
21+
float3 scale;
22+
float padding1;
23+
24+
#if !__cplusplus
25+
float3 RotateVector(float3 v)
26+
{
27+
return rotation.RotateVector(v);
28+
}
29+
30+
float3 TransformPosition(float3 vertexPos)
31+
{
32+
return RotateVector(vertexPos * scale) + position;
33+
}
34+
35+
GPUTransform Combine(GPUTransform other)
36+
{
37+
GPUTransform result;
38+
result.scale = scale * other.scale;
39+
result.rotation = rotation * other.rotation;
40+
result.position = RotateVector(other.position * scale) + position;
41+
42+
return result;
43+
}
44+
45+
void Initialize(float3 inPosition, float3 inScale, float4 inRotation)
46+
{
47+
position = inPosition;
48+
scale = inScale;
49+
rotation.x = inRotation.x;
50+
rotation.y = inRotation.y;
51+
rotation.z = inRotation.z;
52+
rotation.w = inRotation.w;
53+
}
54+
#endif
55+
};
56+
57+
VT_NAMESPACE_HLSL_END
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#if __cplusplus
4+
5+
#define VT_NAMESPACE_HLSL_BEGIN \
6+
namespace Volt::HLSL { \
7+
using namespace RHI;
8+
9+
#define VT_NAMESPACE_HLSL_END \
10+
}
11+
12+
#else
13+
14+
#define VT_NAMESPACE_HLSL_BEGIN
15+
#define VT_NAMESPACE_HLSL_END
16+
17+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#if __cplusplus
4+
5+
#include <glm/glm.hpp>
6+
7+
namespace Volt::HLSL
8+
{
9+
using float2 = glm::vec2;
10+
using float3 = glm::vec3;
11+
using float4 = glm::vec4;
12+
13+
using int2 = glm::ivec2;
14+
using int3 = glm::ivec3;
15+
using int4 = glm::ivec4;
16+
17+
using uint2 = glm::uvec2;
18+
using uint3 = glm::uvec3;
19+
using uint4 = glm::uvec4;
20+
21+
using float4x4 = glm::mat4;
22+
}
23+
24+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "HLSLNamespace.h"
4+
#include "HLSLTypes.h"
5+
6+
VT_NAMESPACE_HLSL_BEGIN
7+
8+
namespace LightCulling
9+
{
10+
static const uint LightCullingTileSize = 16;
11+
static const uint MaxLightsPerTile = 512;
12+
}
13+
14+
VT_NAMESPACE_HLSL_END
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include "HLSLNamespace.h"
4+
#include "HLSLTypes.h"
5+
6+
VT_NAMESPACE_HLSL_BEGIN
7+
8+
struct RenderViewData
9+
{
10+
float4x4 worldToView;
11+
float4x4 viewToClip;
12+
float4x4 viewToWorld;
13+
float4x4 clipToView;
14+
float4x4 worldToClip;
15+
float4x4 clipToWorld;
16+
float4x4 prevWorldToClip;
17+
float4x4 nonJitteredWorldToClip;
18+
19+
float4 viewPosition;
20+
21+
float2 depthUnpackingConstants;
22+
float nearPlane;
23+
float farPlane;
24+
25+
uint frameIndex;
26+
uint3 padding;
27+
28+
uint2 viewSize;
29+
float2 invViewSize;
30+
31+
float2 frameJitter;
32+
float2 prevFrameJitter;
33+
};
34+
35+
VT_NAMESPACE_HLSL_END
36+
37+
#if !__cplusplus
38+
ConstantBuffer<RenderViewData> View;
39+
#endif

Engine/Engine/Shaders/Source/Debug/DrawDebugBillboards.hlsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
#include "ViewData.hlsli"
21
#include "BillboardInstanceData.hlsli"
32
#include "StaticSamplerStates.hlsli"
43

4+
#include "RenderViewData.h"
5+
56
static const float2 offsets[6] =
67
{
78
{ -50.f, 50.f },
@@ -38,11 +39,11 @@ BillboardVSToPS MainVS(uint vertexId : SV_VertexID, uint instanceId : SV_Instanc
3839
}
3940
else
4041
{
41-
result.position = mul(View.view, float4(billboardInstanceData.position, 1.f));
42+
result.position = mul(View.worldToView, float4(billboardInstanceData.position, 1.f));
4243
}
4344

4445
result.position.xy += offsets[vertexId] * billboardInstanceData.size.xy;
45-
result.position = mul(View.projection, result.position);
46+
result.position = mul(View.viewToClip, result.position);
4647
result.color = billboardInstanceData.color;
4748
result.texCoords = uvs[vertexId];
4849
result.userData = billboardInstanceData.userData;

Engine/Engine/Shaders/Source/Debug/DrawDebugLines.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "ViewData.hlsli"
1+
#include "RenderViewData.h"
22

33
struct LineVertex
44
{
@@ -15,7 +15,7 @@ struct VSToPS
1515
VSToPS MainVS(in LineVertex input)
1616
{
1717
VSToPS result;
18-
result.position = mul(View.viewProjection, float4(input.position, 1.f));
18+
result.position = mul(View.worldToClip, float4(input.position, 1.f));
1919
result.color = input.color;
2020

2121
return result;

Engine/Engine/Shaders/Source/Editor/2DGrid_ps.hlsl

Lines changed: 0 additions & 36 deletions
This file was deleted.

Engine/Engine/Shaders/Source/Editor/3DGrid.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "ViewData.hlsli"
1+
#include "RenderViewData.h"
22

33
static const float4 m_positions[] =
44
{
@@ -18,7 +18,7 @@ float4x4 NonReversedInverseProjection;
1818

1919
float3 UnprojectPoint(float x, float y, float z)
2020
{
21-
float4 unprojectedPoint = mul(View.inverseView, mul(NonReversedInverseProjection, float4(x, y, z, 1.f)));
21+
float4 unprojectedPoint = mul(View.viewToWorld, mul(NonReversedInverseProjection, float4(x, y, z, 1.f)));
2222
return unprojectedPoint.xyz / unprojectedPoint.w;
2323
}
2424

@@ -65,7 +65,7 @@ float4 EvaluateGrid(float3 position, float scale)
6565

6666
float ComputeDepth(float3 position)
6767
{
68-
float4 clipPos = mul(View.viewProjection, float4(position, 1.f));
68+
float4 clipPos = mul(View.worldToClip, float4(position, 1.f));
6969
return clipPos.z / clipPos.w;
7070
}
7171

@@ -74,7 +74,7 @@ PSOutput GridPS(VSToPS input)
7474
const float t = -input.nearPoint.y / (input.farPoint.y - input.nearPoint.y);
7575
const float3 position = input.nearPoint + t * (input.farPoint - input.nearPoint);
7676

77-
const float linearDepth = mul(View.view, float4(position, 1.f)).z / View.farPlane;
77+
const float linearDepth = mul(View.worldToView, float4(position, 1.f)).z / View.farPlane;
7878
const float fade = max(0.f, (0.5f - linearDepth));
7979

8080
PSOutput result;

0 commit comments

Comments
 (0)