2021-07-18 05:29:41 +00:00
|
|
|
struct Globals {
|
2022-03-09 08:01:56 +00:00
|
|
|
row_major float4x4 view_proj;
|
2021-07-18 05:29:41 +00:00
|
|
|
uint4 num_lights;
|
|
|
|
};
|
|
|
|
|
2022-03-09 08:01:56 +00:00
|
|
|
struct Entity {
|
|
|
|
row_major float4x4 world;
|
|
|
|
float4 color;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertexOutput {
|
|
|
|
float4 proj_position : SV_Position;
|
2022-04-10 05:36:36 +00:00
|
|
|
float3 world_normal : LOC0;
|
|
|
|
float4 world_position : LOC1;
|
2022-03-09 08:01:56 +00:00
|
|
|
};
|
|
|
|
|
2021-07-18 05:29:41 +00:00
|
|
|
struct Light {
|
2021-08-15 23:32:52 +00:00
|
|
|
row_major float4x4 proj;
|
2021-07-18 05:29:41 +00:00
|
|
|
float4 pos;
|
|
|
|
float4 color;
|
|
|
|
};
|
|
|
|
|
2023-04-05 15:38:03 +00:00
|
|
|
static const float3 c_ambient = float3(0.05, 0.05, 0.05);
|
|
|
|
static const uint c_max_lights = 10u;
|
|
|
|
|
2021-07-18 06:15:02 +00:00
|
|
|
cbuffer u_globals : register(b0) { Globals u_globals; }
|
2022-03-09 08:01:56 +00:00
|
|
|
cbuffer u_entity : register(b0, space1) { Entity u_entity; }
|
2021-07-24 06:21:54 +00:00
|
|
|
ByteAddressBuffer s_lights : register(t1);
|
2022-03-09 08:01:56 +00:00
|
|
|
cbuffer u_lights : register(b1) { Light u_lights[10]; }
|
2021-07-22 00:06:56 +00:00
|
|
|
Texture2DArray<float> t_shadow : register(t2);
|
2021-07-18 05:29:41 +00:00
|
|
|
SamplerComparisonState sampler_shadow : register(s3);
|
|
|
|
|
2022-03-09 08:01:56 +00:00
|
|
|
struct VertexOutput_vs_main {
|
|
|
|
float3 world_normal : LOC0;
|
|
|
|
float4 world_position : LOC1;
|
|
|
|
float4 proj_position : SV_Position;
|
|
|
|
};
|
|
|
|
|
2021-07-18 05:29:41 +00:00
|
|
|
struct FragmentInput_fs_main {
|
2022-03-09 08:01:56 +00:00
|
|
|
float3 world_normal_1 : LOC0;
|
|
|
|
float4 world_position_1 : LOC1;
|
|
|
|
float4 proj_position_1 : SV_Position;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentInput_fs_main_without_storage {
|
|
|
|
float3 world_normal_2 : LOC0;
|
|
|
|
float4 world_position_2 : LOC1;
|
|
|
|
float4 proj_position_2 : SV_Position;
|
2021-07-18 05:29:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
float fetch_shadow(uint light_id, float4 homogeneous_coords)
|
|
|
|
{
|
|
|
|
if ((homogeneous_coords.w <= 0.0)) {
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
float2 flip_correction = float2(0.5, -0.5);
|
2022-03-09 08:01:56 +00:00
|
|
|
float proj_correction = (1.0 / homogeneous_coords.w);
|
|
|
|
float2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + float2(0.5, 0.5));
|
2024-06-19 19:45:14 +00:00
|
|
|
float _e24 = t_shadow.SampleCmpLevelZero(sampler_shadow, float3(light_local, int(light_id)), (homogeneous_coords.z * proj_correction));
|
|
|
|
return _e24;
|
2022-03-09 08:01:56 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 06:17:02 +00:00
|
|
|
VertexOutput_vs_main vs_main(int4 position : LOC0, int4 normal : LOC1)
|
2022-03-09 08:01:56 +00:00
|
|
|
{
|
2022-04-29 17:48:27 +00:00
|
|
|
VertexOutput out_ = (VertexOutput)0;
|
2022-03-09 08:01:56 +00:00
|
|
|
|
|
|
|
float4x4 w = u_entity.world;
|
2024-06-19 19:45:14 +00:00
|
|
|
float4x4 _e7 = u_entity.world;
|
|
|
|
float4 world_pos = mul(float4(position), _e7);
|
2022-04-29 17:48:27 +00:00
|
|
|
out_.world_normal = mul(float3(normal.xyz), float3x3(w[0].xyz, w[1].xyz, w[2].xyz));
|
|
|
|
out_.world_position = world_pos;
|
2024-06-19 19:45:14 +00:00
|
|
|
float4x4 _e26 = u_globals.view_proj;
|
|
|
|
out_.proj_position = mul(world_pos, _e26);
|
|
|
|
VertexOutput _e28 = out_;
|
|
|
|
const VertexOutput vertexoutput = _e28;
|
2022-03-09 08:01:56 +00:00
|
|
|
const VertexOutput_vs_main vertexoutput_1 = { vertexoutput.world_normal, vertexoutput.world_position, vertexoutput.proj_position };
|
|
|
|
return vertexoutput_1;
|
2021-07-18 05:29:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 03:40:42 +00:00
|
|
|
Light ConstructLight(float4x4 arg0, float4 arg1, float4 arg2) {
|
|
|
|
Light ret = (Light)0;
|
|
|
|
ret.proj = arg0;
|
|
|
|
ret.pos = arg1;
|
|
|
|
ret.color = arg2;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-07-18 05:29:41 +00:00
|
|
|
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
|
|
|
|
{
|
2022-04-29 17:48:27 +00:00
|
|
|
VertexOutput in_ = { fragmentinput_fs_main.proj_position_1, fragmentinput_fs_main.world_normal_1, fragmentinput_fs_main.world_position_1 };
|
2023-04-19 13:16:46 +00:00
|
|
|
float3 color = c_ambient;
|
|
|
|
uint i = 0u;
|
2021-07-18 05:29:41 +00:00
|
|
|
|
2022-04-29 17:48:27 +00:00
|
|
|
float3 normal_1 = normalize(in_.world_normal);
|
2021-07-26 05:21:24 +00:00
|
|
|
bool loop_init = true;
|
2021-07-18 05:29:41 +00:00
|
|
|
while(true) {
|
2021-07-26 05:21:24 +00:00
|
|
|
if (!loop_init) {
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e40 = i;
|
|
|
|
i = (_e40 + 1u);
|
2021-07-26 05:21:24 +00:00
|
|
|
}
|
|
|
|
loop_init = false;
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e7 = i;
|
|
|
|
uint _e11 = u_globals.num_lights.x;
|
|
|
|
if ((_e7 < min(_e11, c_max_lights))) {
|
2022-03-09 08:01:56 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2023-01-12 17:26:28 +00:00
|
|
|
{
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e16 = i;
|
|
|
|
Light light = ConstructLight(float4x4(asfloat(s_lights.Load4(_e16*96+0+0)), asfloat(s_lights.Load4(_e16*96+0+16)), asfloat(s_lights.Load4(_e16*96+0+32)), asfloat(s_lights.Load4(_e16*96+0+48))), asfloat(s_lights.Load4(_e16*96+64)), asfloat(s_lights.Load4(_e16*96+80)));
|
|
|
|
uint _e19 = i;
|
|
|
|
const float _e23 = fetch_shadow(_e19, mul(in_.world_position, light.proj));
|
2023-01-12 17:26:28 +00:00
|
|
|
float3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz));
|
|
|
|
float diffuse = max(0.0, dot(normal_1, light_dir));
|
2024-06-19 19:45:14 +00:00
|
|
|
float3 _e37 = color;
|
|
|
|
color = (_e37 + ((_e23 * diffuse) * light.color.xyz));
|
2023-01-12 17:26:28 +00:00
|
|
|
}
|
2022-03-09 08:01:56 +00:00
|
|
|
}
|
2024-06-19 19:45:14 +00:00
|
|
|
float3 _e42 = color;
|
|
|
|
float4 _e47 = u_entity.color;
|
|
|
|
return (float4(_e42, 1.0) * _e47);
|
2022-03-09 08:01:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float4 fs_main_without_storage(FragmentInput_fs_main_without_storage fragmentinput_fs_main_without_storage) : SV_Target0
|
|
|
|
{
|
2022-04-29 17:48:27 +00:00
|
|
|
VertexOutput in_1 = { fragmentinput_fs_main_without_storage.proj_position_2, fragmentinput_fs_main_without_storage.world_normal_2, fragmentinput_fs_main_without_storage.world_position_2 };
|
2023-04-19 13:16:46 +00:00
|
|
|
float3 color_1 = c_ambient;
|
|
|
|
uint i_1 = 0u;
|
2022-03-09 08:01:56 +00:00
|
|
|
|
2022-04-29 17:48:27 +00:00
|
|
|
float3 normal_2 = normalize(in_1.world_normal);
|
2022-03-09 08:01:56 +00:00
|
|
|
bool loop_init_1 = true;
|
|
|
|
while(true) {
|
|
|
|
if (!loop_init_1) {
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e40 = i_1;
|
|
|
|
i_1 = (_e40 + 1u);
|
2022-03-09 08:01:56 +00:00
|
|
|
}
|
|
|
|
loop_init_1 = false;
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e7 = i_1;
|
|
|
|
uint _e11 = u_globals.num_lights.x;
|
|
|
|
if ((_e7 < min(_e11, c_max_lights))) {
|
2022-03-09 08:01:56 +00:00
|
|
|
} else {
|
2021-07-18 05:29:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-01-12 17:26:28 +00:00
|
|
|
{
|
2024-06-19 19:45:14 +00:00
|
|
|
uint _e16 = i_1;
|
|
|
|
Light light_1 = u_lights[_e16];
|
|
|
|
uint _e19 = i_1;
|
|
|
|
const float _e23 = fetch_shadow(_e19, mul(in_1.world_position, light_1.proj));
|
2023-01-12 17:26:28 +00:00
|
|
|
float3 light_dir_1 = normalize((light_1.pos.xyz - in_1.world_position.xyz));
|
|
|
|
float diffuse_1 = max(0.0, dot(normal_2, light_dir_1));
|
2024-06-19 19:45:14 +00:00
|
|
|
float3 _e37 = color_1;
|
|
|
|
color_1 = (_e37 + ((_e23 * diffuse_1) * light_1.color.xyz));
|
2023-01-12 17:26:28 +00:00
|
|
|
}
|
2021-07-18 05:29:41 +00:00
|
|
|
}
|
2024-06-19 19:45:14 +00:00
|
|
|
float3 _e42 = color_1;
|
|
|
|
float4 _e47 = u_entity.color;
|
|
|
|
return (float4(_e42, 1.0) * _e47);
|
2021-07-18 05:29:41 +00:00
|
|
|
}
|