feat(graphics): improve rendering pipeline and docs
- Refactor D3D12 backend and RenderGraph module - Update graphics RHI and core rendering components - Add Random.hlsl shader include - Regenerate API documentation and update user guides
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef BUILTIN_COMMON_HLSL
|
||||
#define BUILTIN_COMMON_HLSL
|
||||
#ifndef GHOST_COMMON_HLSL
|
||||
#define GHOST_COMMON_HLSL
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
@@ -104,4 +104,4 @@ static inline T LoadData(BYTE_ADDRESS_BUFFER buffer, uint index)
|
||||
return buf.Load<T>(index * sizeof(T));
|
||||
}
|
||||
|
||||
#endif // BUILTIN_COMMON_HLSL
|
||||
#endif // GHOST_COMMON_HLSL
|
||||
|
||||
@@ -1,27 +1,26 @@
|
||||
#ifndef BUILTIN_PROPERTIES_HLSL
|
||||
#define BUILTIN_PROPERTIES_HLSL
|
||||
#ifndef GHOST_PROPERTIES_HLSL
|
||||
#define GHOST_PROPERTIES_HLSL
|
||||
|
||||
#include "F:/csharp/GhostEngine/src/Runtime/Ghost.Graphics/Shaders/Includes/Common.hlsl"
|
||||
|
||||
// TODO: This should be auto generated to match the c# side.
|
||||
|
||||
struct PushConstantData
|
||||
{
|
||||
uint globalIndex;
|
||||
uint viewIndex;
|
||||
uint objectIndex;
|
||||
BYTE_ADDRESS_BUFFER frameBuffer;
|
||||
BYTE_ADDRESS_BUFFER viewBuffer;
|
||||
BYTE_ADDRESS_BUFFER instanceBuffer;
|
||||
uint instanceIndex;
|
||||
uint materialIndex;
|
||||
};
|
||||
|
||||
struct GlobalFrameData
|
||||
struct FrameData
|
||||
{
|
||||
uint viewBufferIndex;
|
||||
uint instanceBufferIndex;
|
||||
uint viewBufferCount;
|
||||
uint instanceBufferCount;
|
||||
uint userBufferIndex;
|
||||
BYTE_ADDRESS_BUFFER viewBuffer;
|
||||
BYTE_ADDRESS_BUFFER instanceBuffer;
|
||||
BYTE_ADDRESS_BUFFER userBuffer;
|
||||
};
|
||||
|
||||
struct PerViewData
|
||||
struct ViewData
|
||||
{
|
||||
float4x4 viewMatrix;
|
||||
float4x4 projectionMatrix;
|
||||
@@ -32,17 +31,20 @@ struct PerViewData
|
||||
float4 screenSize; // xy: size, zw: 1/size
|
||||
};
|
||||
|
||||
struct PerInstanceData
|
||||
struct InstanceData
|
||||
{
|
||||
float4x4 localToWorld;
|
||||
BYTE_ADDRESS_BUFFER meshBuffer;
|
||||
BYTE_ADDRESS_BUFFER materialBuffer;
|
||||
};
|
||||
|
||||
struct PerObjectData
|
||||
struct MeshData
|
||||
{
|
||||
float3 worldBoundsMin;
|
||||
BYTE_ADDRESS_BUFFER vertexBuffer;
|
||||
float3 worldBoundsMax;
|
||||
BYTE_ADDRESS_BUFFER indexBuffer;
|
||||
|
||||
BYTE_ADDRESS_BUFFER meshletBuffer;
|
||||
BYTE_ADDRESS_BUFFER meshletVerticesBuffer;
|
||||
BYTE_ADDRESS_BUFFER meshletTrianglesBuffer;
|
||||
@@ -50,4 +52,4 @@ struct PerObjectData
|
||||
|
||||
PushConstantData g_PushConstantData : register(b0);
|
||||
|
||||
#endif // BUILTIN_PROPERTIES_HLSL
|
||||
#endif // GHOST_PROPERTIES_HLSL
|
||||
|
||||
123
src/Runtime/Ghost.Graphics/Shaders/Includes/Random.hlsl
Normal file
123
src/Runtime/Ghost.Graphics/Shaders/Includes/Random.hlsl
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef GHOST_RANDOM_HLSL
|
||||
#define GHOST_RANDOM_HLSL
|
||||
|
||||
float RandomFloat(float2 uv)
|
||||
{
|
||||
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
|
||||
}
|
||||
|
||||
float Hash(uint s)
|
||||
{
|
||||
s = s ^ 2747636419u;
|
||||
s = s * 2654435769u;
|
||||
s = s ^ (s >> 16);
|
||||
s = s * 2654435769u;
|
||||
s = s ^ (s >> 16);
|
||||
s = s * 2654435769u;
|
||||
return float(s) * rcp(4294967296.0); // 2^-32
|
||||
}
|
||||
|
||||
// A single iteration of Bob Jenkins' One-At-A-Time hashing algorithm.
|
||||
uint JenkinsHash(uint x)
|
||||
{
|
||||
x += (x << 10u);
|
||||
x ^= (x >> 6u);
|
||||
x += (x << 3u);
|
||||
x ^= (x >> 11u);
|
||||
x += (x << 15u);
|
||||
return x;
|
||||
}
|
||||
|
||||
// Compound versions of the hashing algorithm.
|
||||
uint JenkinsHash(uint2 v)
|
||||
{
|
||||
return JenkinsHash(v.x ^ JenkinsHash(v.y));
|
||||
}
|
||||
|
||||
uint JenkinsHash(uint3 v)
|
||||
{
|
||||
return JenkinsHash(v.x ^ JenkinsHash(v.yz));
|
||||
}
|
||||
|
||||
uint JenkinsHash(uint4 v)
|
||||
{
|
||||
return JenkinsHash(v.x ^ JenkinsHash(v.yzw));
|
||||
}
|
||||
|
||||
uint PCGHash(uint input)
|
||||
{
|
||||
uint state = input * 747796405u + 2891336453u;
|
||||
uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u;
|
||||
return (word >> 22u) ^ word;
|
||||
}
|
||||
|
||||
// Construct a float with half-open range [0, 1) using low 23 bits.
|
||||
// All zeros yields 0, all ones yields the next smallest representable value below 1.
|
||||
float ConstructFloat(int m)
|
||||
{
|
||||
const int ieeeMantissa = 0x007FFFFF; // Binary FP32 mantissa bitmask
|
||||
const int ieeeOne = 0x3F800000; // 1.0 in FP32 IEEE
|
||||
|
||||
m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
|
||||
m |= ieeeOne; // Add fractional part to 1.0
|
||||
|
||||
float f = asfloat(m); // Range [1, 2)
|
||||
return f - 1; // Range [0, 1)
|
||||
}
|
||||
|
||||
float ConstructFloat(uint m)
|
||||
{
|
||||
return ConstructFloat(asint(m));
|
||||
}
|
||||
|
||||
// Pseudo-random value in half-open range [0, 1). The distribution is reasonably uniform.
|
||||
// Ref: https://stackoverflow.com/a/17479300
|
||||
float GenerateHashedRandomFloat(uint x)
|
||||
{
|
||||
return ConstructFloat(JenkinsHash(x));
|
||||
}
|
||||
|
||||
float GenerateHashedRandomFloat(uint2 v)
|
||||
{
|
||||
return ConstructFloat(JenkinsHash(v));
|
||||
}
|
||||
|
||||
float GenerateHashedRandomFloat(uint3 v)
|
||||
{
|
||||
return ConstructFloat(JenkinsHash(v));
|
||||
}
|
||||
|
||||
float GenerateHashedRandomFloat(uint4 v)
|
||||
{
|
||||
return ConstructFloat(JenkinsHash(v));
|
||||
}
|
||||
|
||||
float2 InitRandom(float2 input)
|
||||
{
|
||||
float2 r;
|
||||
r.x = Hash(uint(input.x * 0xFFFFFFFFu));
|
||||
r.y = Hash(uint(input.y * 0xFFFFFFFFu));
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
//From Next Generation Post Processing in Call of Duty: Advanced Warfare [Jimenez 2014]
|
||||
// http://advances.realtimerendering.com/s2014/index.html
|
||||
float InterleavedGradientNoise(float2 pixCoord, int frameCount)
|
||||
{
|
||||
const float3 magic = float3(0.06711056f, 0.00583715f, 52.9829189f);
|
||||
float2 frameMagicScale = float2(2.083f, 4.867f);
|
||||
pixCoord += frameCount * frameMagicScale;
|
||||
return frac(magic.z * frac(dot(pixCoord, magic.xy)));
|
||||
}
|
||||
|
||||
// 32-bit Xorshift random number generator
|
||||
uint XorShift(inout uint rngState)
|
||||
{
|
||||
rngState ^= rngState << 13;
|
||||
rngState ^= rngState >> 17;
|
||||
rngState ^= rngState << 5;
|
||||
return rngState;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user