remove old kernel layer
This commit is contained in:
parent
d4aa3de928
commit
506c59018b
@ -147,7 +147,7 @@ void GPU_D12_InitDevice(void)
|
|||||||
ID3D12Debug_EnableDebugLayer(debug_controller0);
|
ID3D12Debug_EnableDebugLayer(debug_controller0);
|
||||||
|
|
||||||
/* FIXME: Enable this */
|
/* FIXME: Enable this */
|
||||||
//ID3D12Debug1_SetEnableGPUBasedValidation(debug_controller1, 1);
|
// ID3D12Debug1_SetEnableGPUBasedValidation(debug_controller1, 1);
|
||||||
|
|
||||||
ID3D12Debug_Release(debug_controller1);
|
ID3D12Debug_Release(debug_controller1);
|
||||||
ID3D12Debug_Release(debug_controller0);
|
ID3D12Debug_Release(debug_controller0);
|
||||||
@ -1324,32 +1324,35 @@ void GPU_ReleaseResource(GPU_Resource *gpu_resource, GPU_ReleaseFlag flags)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GPU_GetReadableId(GPU_Resource *resource)
|
u32 GPU_GetReadableId(GPU_Resource *gpu_resource)
|
||||||
{
|
{
|
||||||
u32 result = U32Max;
|
u32 result = U32Max;
|
||||||
if (resource && ((GPU_D12_Resource *)resource)->srv_descriptor)
|
GPU_D12_Resource *r = (GPU_D12_Resource *)gpu_resource;
|
||||||
|
if (r && r->srv_descriptor)
|
||||||
{
|
{
|
||||||
result = ((GPU_D12_Resource *)resource)->srv_descriptor->index;
|
result = r->srv_descriptor->index;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GPU_GetWritableId(GPU_Resource *resource)
|
u32 GPU_GetWritableId(GPU_Resource *gpu_resource)
|
||||||
{
|
{
|
||||||
u32 result = U32Max;
|
u32 result = U32Max;
|
||||||
if (resource && ((GPU_D12_Resource *)resource)->uav_descriptor)
|
GPU_D12_Resource *r = (GPU_D12_Resource *)gpu_resource;
|
||||||
|
if (r && r->uav_descriptor)
|
||||||
{
|
{
|
||||||
result = ((GPU_D12_Resource *)resource)->uav_descriptor->index;
|
result = r->uav_descriptor->index;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GPU_GetSamplerId(GPU_Resource *resource)
|
u32 GPU_GetSamplerId(GPU_Resource *gpu_resource)
|
||||||
{
|
{
|
||||||
u32 result = U32Max;
|
u32 result = U32Max;
|
||||||
if (resource && ((GPU_D12_Resource *)resource)->sampler_descriptor)
|
GPU_D12_Resource *r = (GPU_D12_Resource *)gpu_resource;
|
||||||
|
if (r && r->sampler_descriptor)
|
||||||
{
|
{
|
||||||
result = ((GPU_D12_Resource *)resource)->sampler_descriptor->index;
|
result = r->sampler_descriptor->index;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,201 +0,0 @@
|
|||||||
/* Determine if file was included from C or from HLSL */
|
|
||||||
#if LanguageIsC
|
|
||||||
# define K_IS_CPU 1
|
|
||||||
#else
|
|
||||||
# define K_IS_CPU 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !K_IS_CPU
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Root signature
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define K_ROOTSIG \
|
|
||||||
"RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED | SAMPLER_HEAP_DIRECTLY_INDEXED | ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
|
|
||||||
"RootConstants(b0, num32BitConstants = 64), " \
|
|
||||||
\
|
|
||||||
"StaticSampler(s0, " \
|
|
||||||
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
||||||
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
||||||
"maxAnisotropy = 1)"
|
|
||||||
|
|
||||||
SamplerState s_point_clamp : register(s0);
|
|
||||||
|
|
||||||
#define K_ENTRY [RootSignature(K_ROOTSIG)]
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Global textures
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
/* Blue noise */
|
|
||||||
#define K_BLUE_NOISE_TEX_ID 0
|
|
||||||
#define K_BLUE_NOISE_TEX_WIDTH 128
|
|
||||||
#define K_BLUE_NOISE_TEX_HEIGHT 128
|
|
||||||
#define K_BLUE_NOISE_TEX_DEPTH 64
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Material shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(K_MaterialSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Mat4x4 projection; /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 instances_urid; /* 01 consts */
|
|
||||||
u32 grids_urid; /* 01 consts */
|
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
|
||||||
u32 _pad1; /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_MaterialSig, 20);
|
|
||||||
|
|
||||||
Struct(K_MaterialInstance)
|
|
||||||
{
|
|
||||||
u32 tex_nurid;
|
|
||||||
u32 grid_id;
|
|
||||||
Xform xf;
|
|
||||||
Vec2 uv0;
|
|
||||||
Vec2 uv1;
|
|
||||||
u32 tint_srgb;
|
|
||||||
u32 is_light;
|
|
||||||
Vec3 light_emittance_srgb;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(K_MaterialGrid)
|
|
||||||
{
|
|
||||||
f32 line_thickness;
|
|
||||||
f32 line_spacing;
|
|
||||||
Vec2 offset;
|
|
||||||
u32 bg0_srgb;
|
|
||||||
u32 bg1_srgb;
|
|
||||||
u32 line_srgb;
|
|
||||||
u32 x_srgb;
|
|
||||||
u32 y_srgb;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Flood shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(K_FloodSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
i32 step_len; /* 01 consts */
|
|
||||||
u32 emittance_tex_urid; /* 01 consts */
|
|
||||||
u32 read_flood_tex_urid; /* 01 consts */
|
|
||||||
u32 target_flood_tex_urid; /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 tex_width; /* 01 consts */
|
|
||||||
u32 tex_height; /* 01 consts */
|
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
|
||||||
u32 _pad1; /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_FloodSig, 8);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Shade shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define K_SHADE_FLAG_NONE (0 << 0)
|
|
||||||
#define K_SHADE_FLAG_DISABLE_EFFECTS (1 << 0)
|
|
||||||
|
|
||||||
Struct(K_ShadeSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Vec4I32 frame_seed; /* 04 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 flags; /* 01 consts */
|
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
|
||||||
u32 tex_width; /* 01 consts */
|
|
||||||
u32 tex_height; /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Vec2 camera_offset; /* 02 consts */
|
|
||||||
u32 frame_index; /* 01 consts */
|
|
||||||
u32 albedo_tex_urid; /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 emittance_tex_urid; /* 01 consts */
|
|
||||||
u32 emittance_flood_tex_urid; /* 01 consts */
|
|
||||||
u32 read_tex_urid; /* 01 consts */
|
|
||||||
u32 target_tex_urid; /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_ShadeSig, 16);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Shape shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(K_ShapeSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Mat4x4 projection; /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 verts_urid; /* 01 consts */
|
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
|
||||||
u32 _pad1; /* 01 consts (padding) */
|
|
||||||
u32 _pad2; /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_ShapeSig, 20);
|
|
||||||
|
|
||||||
Struct(K_ShapeVert)
|
|
||||||
{
|
|
||||||
Vec2 pos;
|
|
||||||
u32 color_srgb;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* UI shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(K_UiSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Mat4x4 projection; /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 instances_urid; /* 01 consts */
|
|
||||||
u32 _pad0; /* 01 consts (padding) */
|
|
||||||
u32 _pad1; /* 01 consts (padding) */
|
|
||||||
u32 _pad2; /* 01 consts (padding) */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_UiSig, 20);
|
|
||||||
|
|
||||||
Struct(K_UiInstance)
|
|
||||||
{
|
|
||||||
u32 tex_nurid;
|
|
||||||
u32 grid_id;
|
|
||||||
Xform xf;
|
|
||||||
Vec2 uv0;
|
|
||||||
Vec2 uv1;
|
|
||||||
u32 tint_srgb;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Blit shader structs
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define K_BLIT_FLAG_NONE (0 << 0)
|
|
||||||
#define K_BLIT_FLAG_TONE_MAP (1 << 0)
|
|
||||||
#define K_BLIT_FLAG_GAMMA_CORRECT (1 << 1)
|
|
||||||
|
|
||||||
Struct(K_BlitSig)
|
|
||||||
{
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
Mat4x4 projection; /* 16 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
u32 flags; /* 01 consts */
|
|
||||||
u32 tex_urid; /* 01 consts */
|
|
||||||
f32 exposure; /* 01 consts */
|
|
||||||
f32 gamma; /* 01 consts */
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
};
|
|
||||||
AssertRootConst(K_BlitSig, 20);
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
@Layer kernel
|
|
||||||
|
|
||||||
//- Dependencies
|
|
||||||
@Dep base
|
|
||||||
|
|
||||||
//- Api
|
|
||||||
@IncludeC kernel_core.h
|
|
||||||
@IncludeGpu kernel_core.h
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
ConstantBuffer<K_BlitSig> sig : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Vertex shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(VsInput)
|
|
||||||
{
|
|
||||||
Semantic(u32, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(VSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Position);
|
|
||||||
Semantic(Vec2, uv);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY VSOutput vs(VsInput input)
|
|
||||||
{
|
|
||||||
static const Vec2 unit_quad_verts[4] = {
|
|
||||||
Vec2(-0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, 0.5f),
|
|
||||||
Vec2(-0.5f, 0.5f)
|
|
||||||
};
|
|
||||||
|
|
||||||
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
|
||||||
|
|
||||||
VSOutput output;
|
|
||||||
output.SV_Position = mul(sig.projection, Vec4(vert, 0, 1));
|
|
||||||
output.uv = vert + 0.5;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Tone map
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
/* ACES approximation by Krzysztof Narkowicz
|
|
||||||
* https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ */
|
|
||||||
Vec3 tone_map(Vec3 v)
|
|
||||||
{
|
|
||||||
return saturate((v * (2.51f * v + 0.03f)) / (v * (2.43f * v + 0.59f) + 0.14f));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Pixel shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(PsInput)
|
|
||||||
{
|
|
||||||
VSOutput vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(PSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Target);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY PSOutput ps(PsInput input)
|
|
||||||
{
|
|
||||||
PSOutput output;
|
|
||||||
Texture2D<Vec4> tex = GpuResourceFromUrid(sig.tex_urid);
|
|
||||||
Vec4 color = tex.Sample(s_point_clamp, input.vs.uv);
|
|
||||||
|
|
||||||
/* Apply tone map */
|
|
||||||
if (sig.flags & K_BLIT_FLAG_TONE_MAP) {
|
|
||||||
/* TODO: Dynamic exposure based on average scene luminance */
|
|
||||||
color.rgb *= sig.exposure;
|
|
||||||
color.rgb = tone_map(color.rgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply gamma correction */
|
|
||||||
if (sig.flags & K_BLIT_FLAG_GAMMA_CORRECT) {
|
|
||||||
color = pow(abs(color), 1/sig.gamma);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.SV_Target = color;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
ConstantBuffer<K_FloodSig> sig : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Entry point
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(CsInput)
|
|
||||||
{
|
|
||||||
Semantic(uint3, SV_DispatchThreadID);
|
|
||||||
};
|
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
|
||||||
K_ENTRY void cs(CsInput input)
|
|
||||||
{
|
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
|
||||||
uint2 tex_size = uint2(sig.tex_width, sig.tex_height);
|
|
||||||
if (id.x < tex_size.x && id.y < tex_size.y) {
|
|
||||||
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
|
||||||
RWTexture2D<uint2> read_flood_tex = GpuResourceFromUrid(sig.read_flood_tex_urid);
|
|
||||||
RWTexture2D<uint2> target_flood_tex = GpuResourceFromUrid(sig.target_flood_tex_urid);
|
|
||||||
int step_len = sig.step_len;
|
|
||||||
if (step_len == -1) {
|
|
||||||
/* Seed */
|
|
||||||
Vec4 emittance = emittance_tex[id];
|
|
||||||
uint2 seed = uint2(0xFFFF, 0xFFFF);
|
|
||||||
if (emittance.a > 0) {
|
|
||||||
seed = id;
|
|
||||||
}
|
|
||||||
target_flood_tex[id] = seed;
|
|
||||||
} else {
|
|
||||||
/* Flood */
|
|
||||||
Vec2I32 read_coords[9] = {
|
|
||||||
(Vec2I32)id + Vec2I32(-step_len, -step_len), /* top left */
|
|
||||||
(Vec2I32)id + Vec2I32(0 , -step_len), /* top center */
|
|
||||||
(Vec2I32)id + Vec2I32(+step_len, -step_len), /* top right */
|
|
||||||
(Vec2I32)id + Vec2I32(-step_len, 0 ), /* center left */
|
|
||||||
(Vec2I32)id + Vec2I32(0 , 0 ), /* center center */
|
|
||||||
(Vec2I32)id + Vec2I32(+step_len, 0 ), /* center right */
|
|
||||||
(Vec2I32)id + Vec2I32(-step_len, +step_len), /* bottom left */
|
|
||||||
(Vec2I32)id + Vec2I32(0 , +step_len), /* bottom center */
|
|
||||||
(Vec2I32)id + Vec2I32(+step_len, +step_len) /* bottom right */
|
|
||||||
};
|
|
||||||
uint2 closest_seed = uint2(0xFFFF, 0xFFFF);
|
|
||||||
u32 closest_seed_len_sq = 0xFFFFFFFF;
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
|
||||||
Vec2I32 coord = read_coords[i];
|
|
||||||
if (coord.x >= 0 && coord.x < (int)tex_size.x && coord.y >= 0 && coord.y < (int)tex_size.y) {
|
|
||||||
uint2 seed = read_flood_tex[coord];
|
|
||||||
Vec2I32 dist_vec = (Vec2I32)id - (Vec2I32)seed;
|
|
||||||
u32 dist_len_sq = dot(dist_vec, dist_vec);
|
|
||||||
if (dist_len_sq < closest_seed_len_sq) {
|
|
||||||
closest_seed = seed;
|
|
||||||
closest_seed_len_sq = dist_len_sq;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
target_flood_tex[id] = closest_seed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
ConstantBuffer<K_MaterialSig> sig : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Vertex shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(VsInput)
|
|
||||||
{
|
|
||||||
Semantic(u32, SV_InstanceID);
|
|
||||||
Semantic(u32, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(VSOutput)
|
|
||||||
{
|
|
||||||
nointerpolation Semantic(u32, tex_nurid);
|
|
||||||
nointerpolation Semantic(u32, grid_id);
|
|
||||||
Semantic(Vec2, uv);
|
|
||||||
Semantic(Vec4, tint_lin);
|
|
||||||
Semantic(Vec4, emittance_lin);
|
|
||||||
Semantic(Vec4, SV_Position);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY VSOutput vs(VsInput input)
|
|
||||||
{
|
|
||||||
static const Vec2 unit_quad_verts[4] = {
|
|
||||||
Vec2(-0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, 0.5f),
|
|
||||||
Vec2(-0.5f, 0.5f)
|
|
||||||
};
|
|
||||||
StructuredBuffer<K_MaterialInstance> instances = GpuResourceFromUrid(sig.instances_urid);
|
|
||||||
K_MaterialInstance instance = instances[input.SV_InstanceID];
|
|
||||||
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
|
||||||
Vec2 world_pos = mul(instance.xf, Vec3(vert, 1)).xy;
|
|
||||||
VSOutput output;
|
|
||||||
output.SV_Position = mul(sig.projection, Vec4(world_pos, 0, 1));
|
|
||||||
output.tex_nurid = instance.tex_nurid;
|
|
||||||
output.grid_id = instance.grid_id;
|
|
||||||
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
|
||||||
output.tint_lin = LinearFromSrgbU32(instance.tint_srgb);
|
|
||||||
output.emittance_lin = LinearFromSrgbVec4(Vec4(instance.light_emittance_srgb, instance.is_light));
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Pixel shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(PsInput)
|
|
||||||
{
|
|
||||||
VSOutput vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(PSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Target0); /* Albedo */
|
|
||||||
Semantic(Vec4, SV_Target1); /* Emittance */
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY PSOutput ps(PsInput input)
|
|
||||||
{
|
|
||||||
PSOutput output;
|
|
||||||
Vec4 albedo = input.vs.tint_lin;
|
|
||||||
|
|
||||||
/* Texture */
|
|
||||||
if (input.vs.tex_nurid < 0xFFFFFFFF) {
|
|
||||||
Texture2D<Vec4> tex = GpuResourceFromNurid(input.vs.tex_nurid);
|
|
||||||
albedo *= tex.Sample(s_point_clamp, input.vs.uv);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Grid */
|
|
||||||
if (input.vs.grid_id < 0xFFFFFFFF) {
|
|
||||||
StructuredBuffer<K_MaterialGrid> grids = GpuResourceFromUrid(sig.grids_urid);
|
|
||||||
K_MaterialGrid grid = grids[input.vs.grid_id];
|
|
||||||
Vec2 grid_pos = input.vs.SV_Position.xy + grid.offset;
|
|
||||||
float half_thickness = grid.line_thickness / 2;
|
|
||||||
float spacing = grid.line_spacing;
|
|
||||||
u32 color_srgb = grid.bg0_srgb;
|
|
||||||
Vec2 v = abs(round(grid_pos / spacing) * spacing - grid_pos);
|
|
||||||
float dist = min(v.x, v.y);
|
|
||||||
if (grid_pos.y <= half_thickness && grid_pos.y >= -half_thickness) {
|
|
||||||
color_srgb = grid.x_srgb;
|
|
||||||
} else if (grid_pos.x <= half_thickness && grid_pos.x >= -half_thickness) {
|
|
||||||
color_srgb = grid.y_srgb;
|
|
||||||
} else if (dist < half_thickness) {
|
|
||||||
color_srgb = grid.line_srgb;
|
|
||||||
} else {
|
|
||||||
bool checker = 0;
|
|
||||||
u32 cell_x = (u32)(abs(grid_pos.x) / spacing) + (grid_pos.x < 0);
|
|
||||||
u32 cell_y = (u32)(abs(grid_pos.y) / spacing) + (grid_pos.y < 0);
|
|
||||||
if (cell_x % 2 == 0) {
|
|
||||||
checker = cell_y % 2 == 0;
|
|
||||||
} else {
|
|
||||||
checker = cell_y % 2 == 1;
|
|
||||||
}
|
|
||||||
if (checker) {
|
|
||||||
color_srgb = grid.bg1_srgb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
albedo = LinearFromSrgbU32(color_srgb);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec4 emittance = input.vs.emittance_lin * albedo.a;
|
|
||||||
|
|
||||||
output.SV_Target0 = albedo;
|
|
||||||
output.SV_Target1 = emittance;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@ -1,106 +0,0 @@
|
|||||||
#include "kernel.h"
|
|
||||||
|
|
||||||
ConstantBuffer<K_ShadeSig> sig : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Lighting
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
#define SAMPLES 16
|
|
||||||
#define MARCHES 16
|
|
||||||
#define EDGE_FALLOFF 100
|
|
||||||
|
|
||||||
float rand_angle(uint2 pos, u32 ray_index) {
|
|
||||||
Texture3D<u32> noise_tex = GpuResourceFromUrid(K_BLUE_NOISE_TEX_ID);
|
|
||||||
|
|
||||||
Vec3I32 noise_coord = Vec3I32(1, 1, 1);
|
|
||||||
noise_coord += Vec3I32(pos.xy, ray_index);
|
|
||||||
noise_coord.xyz += sig.frame_seed.xyz;
|
|
||||||
// noise_coord.xy -= sig.camera_offset;
|
|
||||||
|
|
||||||
u32 noise = noise_tex[noise_coord % uint3(K_BLUE_NOISE_TEX_WIDTH, K_BLUE_NOISE_TEX_HEIGHT, K_BLUE_NOISE_TEX_DEPTH)];
|
|
||||||
return ((float)noise / (float)0xFFFF) * Tau;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 get_light_in_dir(uint2 ray_start, Vec2 ray_dir)
|
|
||||||
{
|
|
||||||
Texture2D<uint2> flood_tex = GpuResourceFromUrid(sig.emittance_flood_tex_urid);
|
|
||||||
Texture2D<Vec4> emittance_tex = GpuResourceFromUrid(sig.emittance_tex_urid);
|
|
||||||
|
|
||||||
Vec3 result = Vec3(0, 0, 0);
|
|
||||||
Vec2 at_float = ray_start;
|
|
||||||
uint2 at_uint = ray_start;
|
|
||||||
for (u32 i = 0; i < MARCHES; ++i) {
|
|
||||||
uint2 flood = flood_tex[at_uint];
|
|
||||||
Vec2 dist_vec = at_float - (Vec2)flood;
|
|
||||||
float dist = length(dist_vec);
|
|
||||||
if (dist < 1) {
|
|
||||||
/* Scale light by distance from edge so that offscreen-lights fade in/out rather than popping in */
|
|
||||||
float dist_x = min(abs(sig.tex_width - at_float.x), at_float.x);
|
|
||||||
float dist_y = min(abs(sig.tex_height - at_float.y), at_float.y);
|
|
||||||
float dist_scale = min(min(dist_x, dist_y) / EDGE_FALLOFF, 1);
|
|
||||||
result = emittance_tex[flood].rgb * dist_scale;
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
at_float += ray_dir * dist;
|
|
||||||
at_uint = round(at_float);
|
|
||||||
if (at_uint.x < 0 || at_uint.x >= sig.tex_width || at_uint.y < 0 || at_uint.y >= sig.tex_height) {
|
|
||||||
/* Ray hit edge of screen */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 get_light_at_pos(uint2 pos)
|
|
||||||
{
|
|
||||||
Vec3 result = 0;
|
|
||||||
for (u32 i = 0; i < SAMPLES; ++i) {
|
|
||||||
float angle = rand_angle(pos, i);
|
|
||||||
Vec2 dir = Vec2(cos(angle), sin(angle));
|
|
||||||
Vec3 light_in_dir = get_light_in_dir(pos, dir);
|
|
||||||
result += light_in_dir;
|
|
||||||
}
|
|
||||||
result /= SAMPLES;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Entry point
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(CsInput)
|
|
||||||
{
|
|
||||||
Semantic(uint3, SV_DispatchThreadID);
|
|
||||||
};
|
|
||||||
|
|
||||||
[numthreads(8, 8, 1)]
|
|
||||||
K_ENTRY void cs(CsInput input)
|
|
||||||
{
|
|
||||||
uint2 id = input.SV_DispatchThreadID.xy;
|
|
||||||
if (id.x < sig.tex_width && id.y < sig.tex_height) {
|
|
||||||
Texture2D<Vec4> albedo_tex = GpuResourceFromUrid(sig.albedo_tex_urid);
|
|
||||||
Texture2D<Vec4> read_tex = GpuResourceFromUrid(sig.read_tex_urid);
|
|
||||||
RWTexture2D<Vec4> target_tex = GpuResourceFromUrid(sig.target_tex_urid);
|
|
||||||
Vec4 color = Vec4(1, 1, 1, 1);
|
|
||||||
|
|
||||||
/* Apply albedo */
|
|
||||||
color *= albedo_tex[id];
|
|
||||||
|
|
||||||
/* Apply lighting */
|
|
||||||
if (!(sig.flags & K_SHADE_FLAG_DISABLE_EFFECTS)) {
|
|
||||||
color.rgb *= get_light_at_pos(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply temporal accumulation */
|
|
||||||
float hysterisis = 0;
|
|
||||||
// hysterisis = 0.2;
|
|
||||||
// hysterisis = 0.4;
|
|
||||||
// hysterisis = 0.5;
|
|
||||||
// hysterisis = 0.9;
|
|
||||||
color.rgb = lerp(color.rgb, read_tex[id].rgb, hysterisis);
|
|
||||||
|
|
||||||
target_tex[id] = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
#include "kernel.h"
|
|
||||||
|
|
||||||
ConstantBuffer<K_ShapeSig> sig : register(b0);
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Vertex shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(VsInput)
|
|
||||||
{
|
|
||||||
Semantic(u32, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(VSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Position);
|
|
||||||
Semantic(Vec4, color_srgb);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY VSOutput vs(VsInput input)
|
|
||||||
{
|
|
||||||
StructuredBuffer<K_ShapeVert> verts = GpuResourceFromUrid(sig.verts_urid);
|
|
||||||
K_ShapeVert vert = verts[input.SV_VertexID];
|
|
||||||
VSOutput output;
|
|
||||||
output.SV_Position = mul(sig.projection, Vec4(vert.pos.xy, 0, 1));
|
|
||||||
output.color_srgb = Vec4NormFromU32(vert.color_srgb);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================== *
|
|
||||||
* Pixel shader
|
|
||||||
* ========================== */
|
|
||||||
|
|
||||||
Struct(PsInput)
|
|
||||||
{
|
|
||||||
VSOutput vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(PSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Target);
|
|
||||||
};
|
|
||||||
|
|
||||||
K_ENTRY PSOutput ps(PsInput input)
|
|
||||||
{
|
|
||||||
PSOutput output;
|
|
||||||
output.SV_Target = input.vs.color_srgb;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
#include "kernel.h"
|
|
||||||
|
|
||||||
ConstantBuffer<K_UiSig> sig : register(b0);
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Shader types
|
|
||||||
|
|
||||||
//- Vertex shader in/out
|
|
||||||
Struct(VsInput)
|
|
||||||
{
|
|
||||||
Semantic(u32, SV_InstanceID);
|
|
||||||
Semantic(u32, SV_VertexID);
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(VSOutput)
|
|
||||||
{
|
|
||||||
nointerpolation Semantic(u32, tex_nurid);
|
|
||||||
Semantic(Vec2, uv);
|
|
||||||
Semantic(Vec4, tint_srgb);
|
|
||||||
Semantic(Vec4, SV_Position);
|
|
||||||
};
|
|
||||||
|
|
||||||
//- Pixel shader in/out
|
|
||||||
Struct(PsInput)
|
|
||||||
{
|
|
||||||
VSOutput vs;
|
|
||||||
};
|
|
||||||
|
|
||||||
Struct(PSOutput)
|
|
||||||
{
|
|
||||||
Semantic(Vec4, SV_Target0);
|
|
||||||
};
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Vertex shader
|
|
||||||
|
|
||||||
K_ENTRY VSOutput vs(VsInput input)
|
|
||||||
{
|
|
||||||
static const Vec2 unit_quad_verts[4] = {
|
|
||||||
Vec2(-0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, -0.5f),
|
|
||||||
Vec2(0.5f, 0.5f),
|
|
||||||
Vec2(-0.5f, 0.5f)
|
|
||||||
};
|
|
||||||
|
|
||||||
StructuredBuffer<K_UiInstance> instances = GpuResourceFromUrid(sig.instances_urid);
|
|
||||||
K_UiInstance instance = instances[input.SV_InstanceID];
|
|
||||||
Vec2 vert = unit_quad_verts[input.SV_VertexID];
|
|
||||||
Vec2 world_pos = mul(instance.xf, Vec3(vert, 1)).xy;
|
|
||||||
|
|
||||||
VSOutput output;
|
|
||||||
output.SV_Position = mul(sig.projection, Vec4(world_pos, 0, 1));
|
|
||||||
output.tex_nurid = instance.tex_nurid;
|
|
||||||
output.uv = instance.uv0 + ((vert + 0.5) * (instance.uv1 - instance.uv0));
|
|
||||||
output.tint_srgb = Vec4NormFromU32(instance.tint_srgb);
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
//~ Pixel shader
|
|
||||||
|
|
||||||
K_ENTRY PSOutput ps(PsInput input)
|
|
||||||
{
|
|
||||||
PSOutput output;
|
|
||||||
Vec4 color = input.vs.tint_srgb;
|
|
||||||
|
|
||||||
/* Texture */
|
|
||||||
if (input.vs.tex_nurid < 0xFFFFFFFF)
|
|
||||||
{
|
|
||||||
Texture2D<Vec4> tex = GpuResourceFromNurid(input.vs.tex_nurid);
|
|
||||||
color *= tex.Sample(s_point_clamp, input.vs.uv);
|
|
||||||
}
|
|
||||||
|
|
||||||
output.SV_Target0 = color;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
@ -2355,7 +2355,7 @@ void UpdateUser(P_Window *window)
|
|||||||
sig.step_len = step_length;
|
sig.step_len = step_length;
|
||||||
sig.emittance_tex_urid = GPU_GetReadableId(g->emittance);
|
sig.emittance_tex_urid = GPU_GetReadableId(g->emittance);
|
||||||
sig.read_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
sig.read_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
||||||
sig.target_flood_tex_urid = GPU_GetReadableId(g->emittance_flood_target);
|
sig.target_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_target);
|
||||||
sig.tex_width = g->render_size.x;
|
sig.tex_width = g->render_size.x;
|
||||||
sig.tex_height = g->render_size.y;
|
sig.tex_height = g->render_size.y;
|
||||||
GPU_Compute(cl, &sig, FloodCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
|
GPU_Compute(cl, &sig, FloodCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1);
|
||||||
@ -2400,6 +2400,7 @@ void UpdateUser(P_Window *window)
|
|||||||
{
|
{
|
||||||
shade_flags |= ShadeFlag_DisableEffects;
|
shade_flags |= ShadeFlag_DisableEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShadeSig sig = ZI;
|
ShadeSig sig = ZI;
|
||||||
sig.flags = shade_flags;
|
sig.flags = shade_flags;
|
||||||
sig.tex_width = g->render_size.x;
|
sig.tex_width = g->render_size.x;
|
||||||
@ -2412,10 +2413,10 @@ void UpdateUser(P_Window *window)
|
|||||||
sig.camera_offset = g->world_to_render_xf.og;
|
sig.camera_offset = g->world_to_render_xf.og;
|
||||||
sig.albedo_tex_urid = GPU_GetReadableId(g->albedo);
|
sig.albedo_tex_urid = GPU_GetReadableId(g->albedo);
|
||||||
sig.emittance_tex_urid = GPU_GetReadableId(g->emittance);
|
sig.emittance_tex_urid = GPU_GetReadableId(g->emittance);
|
||||||
|
sig.noise_tex_urid = GPU_GetReadableId(g->gpu_noise);
|
||||||
sig.emittance_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
sig.emittance_flood_tex_urid = GPU_GetWritableId(g->emittance_flood_read);
|
||||||
sig.read_tex_urid = GPU_GetWritableId(g->shade_read);
|
sig.read_tex_urid = GPU_GetWritableId(g->shade_read);
|
||||||
sig.target_tex_urid = GPU_GetWritableId(g->shade_target);
|
sig.target_tex_urid = GPU_GetWritableId(g->shade_target);
|
||||||
sig.noise_tex_urid = GPU_GetReadableId(g->gpu_noise);
|
|
||||||
sig.noise_tex_width = noise_size.x;
|
sig.noise_tex_width = noise_size.x;
|
||||||
sig.noise_tex_height = noise_size.y;
|
sig.noise_tex_height = noise_size.y;
|
||||||
sig.noise_tex_depth = noise_size.z;
|
sig.noise_tex_depth = noise_size.z;
|
||||||
@ -2471,8 +2472,8 @@ void UpdateUser(P_Window *window)
|
|||||||
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
GPU_Scissor scissor = GPU_ScissorFromRect(ui_viewport);
|
||||||
|
|
||||||
UiRectSig sig = ZI;
|
UiRectSig sig = ZI;
|
||||||
sig.tex_sampler_urid = GPU_GetSamplerId(g->pt_sampler);
|
|
||||||
sig.projection = ui_vp_matrix;
|
sig.projection = ui_vp_matrix;
|
||||||
|
sig.tex_sampler_urid = GPU_GetSamplerId(g->pt_sampler);
|
||||||
sig.instances_urid = GPU_GetReadableId(ui_rect_instance_buffer);
|
sig.instances_urid = GPU_GetReadableId(ui_rect_instance_buffer);
|
||||||
GPU_Rasterize(cl,
|
GPU_Rasterize(cl,
|
||||||
&sig,
|
&sig,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user