136 lines
2.9 KiB
Plaintext
136 lines
2.9 KiB
Plaintext
static const float HALF_PI = 1.57079633f;
|
|
static const float PI = 3.14159265f;
|
|
static const float TAU = 6.28318530f;
|
|
|
|
struct VertexData
|
|
{
|
|
float4 normal;
|
|
float2 uv0;
|
|
float2 uv1;
|
|
float4 color0;
|
|
};
|
|
|
|
struct TransformData
|
|
{
|
|
float4x4 transform;
|
|
float4x4 normalTransform;
|
|
};
|
|
|
|
struct MaterialData
|
|
{
|
|
float4 albedoFactor;
|
|
float4 emissionFactor;
|
|
Sampler2D.Handle albedoTex;
|
|
Sampler2D.Handle normalTex;
|
|
Sampler2D.Handle metalRoughTex;
|
|
Sampler2D.Handle occlusionTex;
|
|
Sampler2D.Handle emissionTex;
|
|
float metalFactor;
|
|
float roughFactor;
|
|
};
|
|
|
|
struct PointLight
|
|
{
|
|
float3 Position; // 12
|
|
float Range; // 16
|
|
uint Color; // 20
|
|
float Intensity; // 24
|
|
uint pad0;
|
|
uint pad1;
|
|
};
|
|
|
|
struct DirectionalLight
|
|
{
|
|
float3 Direction;
|
|
float Validity_;
|
|
uint Color;
|
|
float Intensity;
|
|
uint pad0;
|
|
uint pad1;
|
|
};
|
|
|
|
struct CameraData
|
|
{
|
|
float4x4 view; // 64
|
|
float4x4 proj; // 128
|
|
float4x4 invView; // 192
|
|
float4x4 invProj; // 256
|
|
float4 position; // 272
|
|
};
|
|
|
|
struct Indexer
|
|
{
|
|
uint16_t count;
|
|
uint16_t offset;
|
|
};
|
|
|
|
struct Lighting
|
|
{
|
|
SamplerCube.Handle environment; // 8
|
|
SamplerCube.Handle diffuseIrradiance; // 16
|
|
SamplerCube.Handle prefilter; // 24
|
|
Sampler2D<float2>.Handle brdfLUT; // 32
|
|
ByteAddressBuffer.Handle lights; // 40
|
|
Indexer pointLightIndexer; // 44
|
|
Indexer dirLightIndexer; // 48
|
|
};
|
|
|
|
struct Block
|
|
{
|
|
static const uint USE_DIFFUSE_BIT = 1;
|
|
static const uint USE_SPECULAR_BIT = 2;
|
|
static const uint SHOW_DIFFUSE_BIT = 4;
|
|
static const uint SHOW_PREFILTER_BIT = 8;
|
|
|
|
StructuredBuffer<float4>.Handle vertexBuffer; // 8
|
|
StructuredBuffer<VertexData>.Handle vertexData; // 16
|
|
StructuredBuffer<MaterialData>.Handle materialBuffer; // 24
|
|
StructuredBuffer<TransformData>.Handle nodeBuffer; // 32
|
|
StructuredBuffer<CameraData>.Handle camera; // 40
|
|
StructuredBuffer<Lighting>.Handle lights; // 48
|
|
|
|
uint debugFlags; // 52
|
|
|
|
int materialIdx; // 56
|
|
uint nodeIdx; // 60
|
|
|
|
property ignoreDiffuse : bool
|
|
{
|
|
get {
|
|
return (debugFlags & USE_DIFFUSE_BIT) == 0;
|
|
}
|
|
}
|
|
|
|
property ignoreSpecular : bool
|
|
{
|
|
get {
|
|
return (debugFlags & USE_SPECULAR_BIT) == 0;
|
|
}
|
|
}
|
|
|
|
property showDiffuse : bool
|
|
{
|
|
get {
|
|
return (debugFlags & SHOW_DIFFUSE_BIT) != 0;
|
|
}
|
|
}
|
|
|
|
property showPrefilter : bool
|
|
{
|
|
get {
|
|
return (debugFlags & SHOW_PREFILTER_BIT) != 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
float3 Uncharted2Tonemap(float3 color)
|
|
{
|
|
float A = 0.15f;
|
|
float B = 0.50f;
|
|
float C = 0.10f;
|
|
float D = 0.20f;
|
|
float E = 0.02f;
|
|
float F = 0.30f;
|
|
float W = 11.2f;
|
|
return ((color * (A * color + C * B) + D * E) / (color * (A * color + B) + D * F)) - E / F;
|
|
} |