Update test case from wgpu's shadow example

This commit is contained in:
hatoo
2022-03-09 17:01:56 +09:00
committed by Dzmitry Malyshau
parent 8344951ebe
commit ae282703e2
10 changed files with 1063 additions and 319 deletions

View File

@@ -1,61 +1,115 @@
struct Globals {
view_proj: mat4x4<f32>;
num_lights: vec4<u32>;
};
@group(0) @binding(0)
@group(0)
@binding(0)
var<uniform> u_globals: Globals;
struct Entity {
world: mat4x4<f32>;
color: vec4<f32>;
};
@group(1)
@binding(0)
var<uniform> u_entity: Entity;
@stage(vertex)
fn vs_bake(@location(0) position: vec4<i32>) -> @builtin(position) vec4<f32> {
return u_globals.view_proj * u_entity.world * vec4<f32>(position);
}
struct VertexOutput {
@builtin(position) proj_position: vec4<f32>;
@location(0) world_normal: vec3<f32>;
@location(1) world_position: vec4<f32>;
};
@stage(vertex)
fn vs_main(
@location(0) position: vec4<i32>,
@location(1) normal: vec4<i32>,
) -> VertexOutput {
let w = u_entity.world;
let world_pos = u_entity.world * vec4<f32>(position);
var out: VertexOutput;
out.world_normal = mat3x3<f32>(w.x.xyz, w.y.xyz, w.z.xyz) * vec3<f32>(normal.xyz);
out.world_position = world_pos;
out.proj_position = u_globals.view_proj * world_pos;
return out;
}
// fragment shader
struct Light {
proj: mat4x4<f32>;
pos: vec4<f32>;
color: vec4<f32>;
};
struct Lights {
data: array<Light>;
};
@group(0) @binding(1)
var<storage> s_lights: Lights;
@group(0) @binding(2)
@group(0)
@binding(1)
var<storage, read> s_lights: array<Light>;
@group(0)
@binding(1)
var<uniform> u_lights: array<Light, 10>; // Used when storage types are not supported
@group(0)
@binding(2)
var t_shadow: texture_depth_2d_array;
@group(0) @binding(3)
@group(0)
@binding(3)
var sampler_shadow: sampler_comparison;
fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
if homogeneous_coords.w <= 0.0 {
if (homogeneous_coords.w <= 0.0) {
return 1.0;
}
// compensate for the Y-flip difference between the NDC and texture coordinates
let flip_correction = vec2<f32>(0.5, -0.5);
let light_local = homogeneous_coords.xy * flip_correction / homogeneous_coords.w + vec2<f32>(0.5, 0.5);
return textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z / homogeneous_coords.w);
// compute texture coordinates for shadow lookup
let proj_correction = 1.0 / homogeneous_coords.w;
let light_local = homogeneous_coords.xy * flip_correction * proj_correction + vec2<f32>(0.5, 0.5);
// do the lookup, using HW PCF and comparison
return textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), homogeneous_coords.z * proj_correction);
}
let c_ambient: vec3<f32> = vec3<f32>(0.05, 0.05, 0.05);
let c_max_lights: u32 = 10u;
@stage(fragment)
fn fs_main(
@location(0) raw_normal: vec3<f32>,
@location(1) position: vec4<f32>
) -> @location(0) vec4<f32> {
let normal: vec3<f32> = normalize(raw_normal);
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
// accumulate color
var color = c_ambient;
var i: u32 = 0u;
loop {
if i >= min(u_globals.num_lights.x, c_max_lights) {
break;
}
let light = s_lights.data[i];
let shadow = fetch_shadow(i, light.proj * position);
let light_dir = normalize(light.pos.xyz - position.xyz);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) {
let light = s_lights[i];
// project into the light space
let shadow = fetch_shadow(i, light.proj * in.world_position);
// compute Lambertian diffuse term
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
color = color + shadow * diffuse * light.color.xyz;
continuing {
i = i + 1u;
}
// add light contribution
color += shadow * diffuse * light.color.xyz;
}
// multiply the light by material color
return vec4<f32>(color, 1.0);
return vec4<f32>(color, 1.0) * u_entity.color;
}
// The fragment entrypoint used when storage buffers are not available for the lights
@stage(fragment)
fn fs_main_without_storage(in: VertexOutput) -> @location(0) vec4<f32> {
let normal = normalize(in.world_normal);
var color: vec3<f32> = c_ambient;
for(var i = 0u; i < min(u_globals.num_lights.x, c_max_lights); i += 1u) {
// This line is the only difference from the entrypoint above. It uses the lights
// uniform instead of the lights storage buffer
let light = u_lights[i];
let shadow = fetch_shadow(i, light.proj * in.world_position);
let light_dir = normalize(light.pos.xyz - in.world_position.xyz);
let diffuse = max(0.0, dot(normal, light_dir));
color += shadow * diffuse * light.color.xyz;
}
return vec4<f32>(color, 1.0) * u_entity.color;
}

View File

@@ -4,8 +4,18 @@ precision highp float;
precision highp int;
struct Globals {
mat4x4 view_proj;
uvec4 num_lights;
};
struct Entity {
mat4x4 world;
vec4 color;
};
struct VertexOutput {
vec4 proj_position;
vec3 world_normal;
vec4 world_position;
};
struct Light {
mat4x4 proj;
vec4 pos;
@@ -13,9 +23,9 @@ struct Light {
};
uniform Globals_block_0Fragment { Globals _group_0_binding_0_fs; };
layout(std430) readonly buffer Lights_block_1Fragment {
Light data[];
} _group_0_binding_1_fs;
uniform Entity_block_1Fragment { Entity _group_1_binding_0_fs; };
layout(std430) readonly buffer type_6_block_2Fragment { Light _group_0_binding_1_fs[]; };
uniform highp sampler2DArrayShadow _group_0_binding_2_fs;
@@ -28,40 +38,42 @@ float fetch_shadow(uint light_id, vec4 homogeneous_coords) {
return 1.0;
}
vec2 flip_correction = vec2(0.5, -0.5);
vec2 light_local = (((homogeneous_coords.xy * flip_correction) / vec2(homogeneous_coords.w)) + vec2(0.5, 0.5));
float _e26 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z / homogeneous_coords.w)), vec2(0.0), vec2(0.0));
return _e26;
float proj_correction = (1.0 / homogeneous_coords.w);
vec2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2(0.5, 0.5));
float _e28 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z * proj_correction)), vec2(0.0), vec2(0.0));
return _e28;
}
void main() {
vec3 raw_normal = _vs2fs_location0;
vec4 position = _vs2fs_location1;
VertexOutput in_ = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
vec3 color = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i = 0u;
vec3 normal = normalize(raw_normal);
vec3 normal_1 = normalize(in_.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
uint _e40 = i;
i = (_e40 + 1u);
uint _e20 = i;
i = (_e20 + 1u);
}
loop_init = false;
uint _e12 = i;
uint _e15 = _group_0_binding_0_fs.num_lights.x;
if ((_e12 >= min(_e15, 10u))) {
uint _e14 = i;
uint _e17 = _group_0_binding_0_fs.num_lights.x;
if ((_e14 < min(_e17, 10u))) {
} else {
break;
}
uint _e19 = i;
Light light = _group_0_binding_1_fs.data[_e19];
uint _e22 = i;
float _e25 = fetch_shadow(_e22, (light.proj * position));
vec3 light_dir = normalize((light.pos.xyz - position.xyz));
float diffuse = max(0.0, dot(normal, light_dir));
vec3 _e34 = color;
color = (_e34 + ((_e25 * diffuse) * light.color.xyz));
uint _e23 = i;
Light light = _group_0_binding_1_fs[_e23];
uint _e26 = i;
float _e30 = fetch_shadow(_e26, (light.proj * in_.world_position));
vec3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz));
float diffuse = max(0.0, dot(normal_1, light_dir));
vec3 _e40 = color;
color = (_e40 + ((_e30 * diffuse) * light.color.xyz));
}
vec3 _e43 = color;
_fs2p_location0 = vec4(_e43, 1.0);
vec3 _e46 = color;
vec4 _e50 = _group_1_binding_0_fs.color;
_fs2p_location0 = (vec4(_e46, 1.0) * _e50);
return;
}

View File

@@ -0,0 +1,79 @@
#version 310 es
precision highp float;
precision highp int;
struct Globals {
mat4x4 view_proj;
uvec4 num_lights;
};
struct Entity {
mat4x4 world;
vec4 color;
};
struct VertexOutput {
vec4 proj_position;
vec3 world_normal;
vec4 world_position;
};
struct Light {
mat4x4 proj;
vec4 pos;
vec4 color;
};
uniform Globals_block_0Fragment { Globals _group_0_binding_0_fs; };
uniform Entity_block_1Fragment { Entity _group_1_binding_0_fs; };
uniform type_7_block_2Fragment { Light _group_0_binding_1_fs[10]; };
uniform highp sampler2DArrayShadow _group_0_binding_2_fs;
layout(location = 0) smooth in vec3 _vs2fs_location0;
layout(location = 1) smooth in vec4 _vs2fs_location1;
layout(location = 0) out vec4 _fs2p_location0;
float fetch_shadow(uint light_id, vec4 homogeneous_coords) {
if ((homogeneous_coords.w <= 0.0)) {
return 1.0;
}
vec2 flip_correction = vec2(0.5, -0.5);
float proj_correction = (1.0 / homogeneous_coords.w);
vec2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2(0.5, 0.5));
float _e28 = textureGrad(_group_0_binding_2_fs, vec4(light_local, int(light_id), (homogeneous_coords.z * proj_correction)), vec2(0.0), vec2(0.0));
return _e28;
}
void main() {
VertexOutput in_1 = VertexOutput(gl_FragCoord, _vs2fs_location0, _vs2fs_location1);
vec3 color_1 = vec3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i_1 = 0u;
vec3 normal_1 = normalize(in_1.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
uint _e20 = i_1;
i_1 = (_e20 + 1u);
}
loop_init = false;
uint _e14 = i_1;
uint _e17 = _group_0_binding_0_fs.num_lights.x;
if ((_e14 < min(_e17, 10u))) {
} else {
break;
}
uint _e23 = i_1;
Light light = _group_0_binding_1_fs[_e23];
uint _e26 = i_1;
float _e30 = fetch_shadow(_e26, (light.proj * in_1.world_position));
vec3 light_dir = normalize((light.pos.xyz - in_1.world_position.xyz));
float diffuse = max(0.0, dot(normal_1, light_dir));
vec3 _e40 = color_1;
color_1 = (_e40 + ((_e30 * diffuse) * light.color.xyz));
}
vec3 _e46 = color_1;
vec4 _e50 = _group_1_binding_0_fs.color;
_fs2p_location0 = (vec4(_e46, 1.0) * _e50);
return;
}

View File

@@ -0,0 +1,38 @@
#version 310 es
precision highp float;
precision highp int;
struct Globals {
mat4x4 view_proj;
uvec4 num_lights;
};
struct Entity {
mat4x4 world;
vec4 color;
};
struct VertexOutput {
vec4 proj_position;
vec3 world_normal;
vec4 world_position;
};
struct Light {
mat4x4 proj;
vec4 pos;
vec4 color;
};
uniform Globals_block_0Vertex { Globals _group_0_binding_0_vs; };
uniform Entity_block_1Vertex { Entity _group_1_binding_0_vs; };
layout(location = 0) in ivec4 _p2vs_location0;
void main() {
ivec4 position = _p2vs_location0;
mat4x4 _e4 = _group_0_binding_0_vs.view_proj;
mat4x4 _e6 = _group_1_binding_0_vs.world;
gl_Position = ((_e4 * _e6) * vec4(position));
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}

View File

@@ -0,0 +1,51 @@
#version 310 es
precision highp float;
precision highp int;
struct Globals {
mat4x4 view_proj;
uvec4 num_lights;
};
struct Entity {
mat4x4 world;
vec4 color;
};
struct VertexOutput {
vec4 proj_position;
vec3 world_normal;
vec4 world_position;
};
struct Light {
mat4x4 proj;
vec4 pos;
vec4 color;
};
uniform Globals_block_0Vertex { Globals _group_0_binding_0_vs; };
uniform Entity_block_1Vertex { Entity _group_1_binding_0_vs; };
layout(location = 0) in ivec4 _p2vs_location0;
layout(location = 1) in ivec4 _p2vs_location1;
layout(location = 0) smooth out vec3 _vs2fs_location0;
layout(location = 1) smooth out vec4 _vs2fs_location1;
void main() {
ivec4 position_1 = _p2vs_location0;
ivec4 normal = _p2vs_location1;
VertexOutput out_ = VertexOutput(vec4(0.0), vec3(0.0), vec4(0.0));
mat4x4 w = _group_1_binding_0_vs.world;
mat4x4 _e7 = _group_1_binding_0_vs.world;
vec4 world_pos = (_e7 * vec4(position_1));
out_.world_normal = (mat3x3(w[0].xyz, w[1].xyz, w[2].xyz) * vec3(normal.xyz));
out_.world_position = world_pos;
mat4x4 _e25 = _group_0_binding_0_vs.view_proj;
out_.proj_position = (_e25 * world_pos);
VertexOutput _e27 = out_;
gl_Position = _e27.proj_position;
_vs2fs_location0 = _e27.world_normal;
_vs2fs_location1 = _e27.world_position;
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
return;
}

View File

@@ -2,9 +2,21 @@ static const float3 c_ambient = float3(0.05000000074505806, 0.05000000074505806,
static const uint c_max_lights = 10;
struct Globals {
row_major float4x4 view_proj;
uint4 num_lights;
};
struct Entity {
row_major float4x4 world;
float4 color;
};
struct VertexOutput {
float4 proj_position : SV_Position;
linear float3 world_normal : LOC0;
linear float4 world_position : LOC1;
};
struct Light {
row_major float4x4 proj;
float4 pos;
@@ -12,13 +24,28 @@ struct Light {
};
cbuffer u_globals : register(b0) { Globals u_globals; }
cbuffer u_entity : register(b0, space1) { Entity u_entity; }
ByteAddressBuffer s_lights : register(t1);
cbuffer u_lights : register(b1) { Light u_lights[10]; }
Texture2DArray<float> t_shadow : register(t2);
SamplerComparisonState sampler_shadow : register(s3);
struct VertexOutput_vs_main {
float3 world_normal : LOC0;
float4 world_position : LOC1;
float4 proj_position : SV_Position;
};
struct FragmentInput_fs_main {
float3 raw_normal_1 : LOC0;
float4 position_1 : LOC1;
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;
};
float fetch_shadow(uint light_id, float4 homogeneous_coords)
@@ -27,40 +54,100 @@ float fetch_shadow(uint light_id, float4 homogeneous_coords)
return 1.0;
}
float2 flip_correction = float2(0.5, -0.5);
float2 light_local = (((homogeneous_coords.xy * flip_correction) / float2(homogeneous_coords.w.xx)) + float2(0.5, 0.5));
float _expr26 = t_shadow.SampleCmpLevelZero(sampler_shadow, float3(light_local, int(light_id)), (homogeneous_coords.z / homogeneous_coords.w));
return _expr26;
float proj_correction = (1.0 / homogeneous_coords.w);
float2 light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + float2(0.5, 0.5));
float _expr28 = t_shadow.SampleCmpLevelZero(sampler_shadow, float3(light_local, int(light_id)), (homogeneous_coords.z * proj_correction));
return _expr28;
}
float4 vs_bake(int4 position : LOC0) : SV_Position
{
float4x4 _expr4 = u_globals.view_proj;
float4x4 _expr6 = u_entity.world;
return mul(float4(position), mul(_expr6, _expr4));
}
VertexOutput_vs_main vs_main(int4 position_1 : LOC0, int4 normal : LOC1)
{
VertexOutput out_ = (VertexOutput)0;
float4x4 w = u_entity.world;
float4x4 _expr7 = u_entity.world;
float4 world_pos = mul(float4(position_1), _expr7);
out_.world_normal = mul(float3(normal.xyz), float3x3(w[0].xyz, w[1].xyz, w[2].xyz));
out_.world_position = world_pos;
float4x4 _expr25 = u_globals.view_proj;
out_.proj_position = mul(world_pos, _expr25);
VertexOutput _expr27 = out_;
const VertexOutput vertexoutput = _expr27;
const VertexOutput_vs_main vertexoutput_1 = { vertexoutput.world_normal, vertexoutput.world_position, vertexoutput.proj_position };
return vertexoutput_1;
}
float4 fs_main(FragmentInput_fs_main fragmentinput_fs_main) : SV_Target0
{
float3 raw_normal = fragmentinput_fs_main.raw_normal_1;
float4 position = fragmentinput_fs_main.position_1;
VertexOutput in_ = { fragmentinput_fs_main.proj_position_1, fragmentinput_fs_main.world_normal_1, fragmentinput_fs_main.world_position_1 };
float3 color = float3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i = 0u;
float3 normal = normalize(raw_normal);
float3 normal_1 = normalize(in_.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
uint _expr40 = i;
i = (_expr40 + 1u);
uint _expr20 = i;
i = (_expr20 + 1u);
}
loop_init = false;
uint _expr12 = i;
uint _expr15 = u_globals.num_lights.x;
if ((_expr12 >= min(_expr15, c_max_lights))) {
uint _expr14 = i;
uint _expr17 = u_globals.num_lights.x;
if ((_expr14 < min(_expr17, c_max_lights))) {
} else {
break;
}
uint _expr19 = i;
Light light = {float4x4(asfloat(s_lights.Load4(_expr19*96+0+0+0)), asfloat(s_lights.Load4(_expr19*96+0+0+16)), asfloat(s_lights.Load4(_expr19*96+0+0+32)), asfloat(s_lights.Load4(_expr19*96+0+0+48))), asfloat(s_lights.Load4(_expr19*96+0+64)), asfloat(s_lights.Load4(_expr19*96+0+80))};
uint _expr22 = i;
const float _e25 = fetch_shadow(_expr22, mul(position, light.proj));
float3 light_dir = normalize((light.pos.xyz - position.xyz));
float diffuse = max(0.0, dot(normal, light_dir));
float3 _expr34 = color;
color = (_expr34 + ((_e25 * diffuse) * light.color.xyz));
uint _expr23 = i;
Light light = {float4x4(asfloat(s_lights.Load4(_expr23*96+0+0)), asfloat(s_lights.Load4(_expr23*96+0+16)), asfloat(s_lights.Load4(_expr23*96+0+32)), asfloat(s_lights.Load4(_expr23*96+0+48))), asfloat(s_lights.Load4(_expr23*96+64)), asfloat(s_lights.Load4(_expr23*96+80))};
uint _expr26 = i;
const float _e30 = fetch_shadow(_expr26, mul(in_.world_position, light.proj));
float3 light_dir = normalize((light.pos.xyz - in_.world_position.xyz));
float diffuse = max(0.0, dot(normal_1, light_dir));
float3 _expr40 = color;
color = (_expr40 + ((_e30 * diffuse) * light.color.xyz));
}
float3 _expr43 = color;
return float4(_expr43, 1.0);
float3 _expr46 = color;
float4 _expr50 = u_entity.color;
return (float4(_expr46, 1.0) * _expr50);
}
float4 fs_main_without_storage(FragmentInput_fs_main_without_storage fragmentinput_fs_main_without_storage) : SV_Target0
{
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 };
float3 color_1 = float3(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
uint i_1 = 0u;
float3 normal_2 = normalize(in_1.world_normal);
bool loop_init_1 = true;
while(true) {
if (!loop_init_1) {
uint _expr20 = i_1;
i_1 = (_expr20 + 1u);
}
loop_init_1 = false;
uint _expr14 = i_1;
uint _expr17 = u_globals.num_lights.x;
if ((_expr14 < min(_expr17, c_max_lights))) {
} else {
break;
}
uint _expr23 = i_1;
Light light_1 = u_lights[_expr23];
uint _expr26 = i_1;
const float _e30 = fetch_shadow(_expr26, mul(in_1.world_position, light_1.proj));
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));
float3 _expr40 = color_1;
color_1 = (_expr40 + ((_e30 * diffuse_1) * light_1.color.xyz));
}
float3 _expr46 = color_1;
float4 _expr50 = u_entity.color;
return (float4(_expr46, 1.0) * _expr50);
}

View File

@@ -1,3 +1,3 @@
vertex=()
fragment=(fs_main:ps_5_1 )
vertex=(vs_bake:vs_5_1 vs_main:vs_5_1 )
fragment=(fs_main:ps_5_1 fs_main_without_storage:ps_5_1 )
compute=()

View File

@@ -5,21 +5,31 @@
using metal::uint;
struct _mslBufferSizes {
uint size1;
uint size2;
};
constexpr constant unsigned c_max_lights = 10u;
struct Globals {
metal::float4x4 view_proj;
metal::uint4 num_lights;
};
struct Entity {
metal::float4x4 world;
metal::float4 color;
};
struct VertexOutput {
metal::float4 proj_position;
metal::float3 world_normal;
metal::float4 world_position;
};
struct Light {
metal::float4x4 proj;
metal::float4 pos;
metal::float4 color;
};
typedef Light type_3[1];
struct Lights {
type_3 data;
typedef Light type_6[1];
struct type_7 {
Light inner[10];
};
constant metal::float3 c_ambient = {0.05000000074505806, 0.05000000074505806, 0.05000000074505806};
@@ -33,52 +43,152 @@ float fetch_shadow(
return 1.0;
}
metal::float2 flip_correction = metal::float2(0.5, -0.5);
metal::float2 light_local = ((homogeneous_coords.xy * flip_correction) / metal::float2(homogeneous_coords.w)) + metal::float2(0.5, 0.5);
float _e26 = t_shadow.sample_compare(sampler_shadow, light_local, static_cast<int>(light_id), homogeneous_coords.z / homogeneous_coords.w);
return _e26;
float proj_correction = 1.0 / homogeneous_coords.w;
metal::float2 light_local = ((homogeneous_coords.xy * flip_correction) * proj_correction) + metal::float2(0.5, 0.5);
float _e28 = t_shadow.sample_compare(sampler_shadow, light_local, static_cast<int>(light_id), homogeneous_coords.z * proj_correction);
return _e28;
}
struct vs_bakeInput {
metal::int4 position [[attribute(0)]];
};
struct vs_bakeOutput {
metal::float4 member [[position]];
};
vertex vs_bakeOutput vs_bake(
vs_bakeInput varyings [[stage_in]]
, constant Globals& u_globals [[user(fake0)]]
, constant Entity& u_entity [[user(fake0)]]
) {
const auto position = varyings.position;
metal::float4x4 _e4 = u_globals.view_proj;
metal::float4x4 _e6 = u_entity.world;
return vs_bakeOutput { (_e4 * _e6) * static_cast<metal::float4>(position) };
}
struct vs_mainInput {
metal::int4 position_1 [[attribute(0)]];
metal::int4 normal [[attribute(1)]];
};
struct vs_mainOutput {
metal::float4 proj_position [[position]];
metal::float3 world_normal [[user(loc0), center_perspective]];
metal::float4 world_position [[user(loc1), center_perspective]];
};
vertex vs_mainOutput vs_main(
vs_mainInput varyings_1 [[stage_in]]
, constant Globals& u_globals [[user(fake0)]]
, constant Entity& u_entity [[user(fake0)]]
) {
const auto position_1 = varyings_1.position_1;
const auto normal = varyings_1.normal;
VertexOutput out;
metal::float4x4 w = u_entity.world;
metal::float4x4 _e7 = u_entity.world;
metal::float4 world_pos = _e7 * static_cast<metal::float4>(position_1);
out.world_normal = metal::float3x3(w[0].xyz, w[1].xyz, w[2].xyz) * static_cast<metal::float3>(normal.xyz);
out.world_position = world_pos;
metal::float4x4 _e25 = u_globals.view_proj;
out.proj_position = _e25 * world_pos;
VertexOutput _e27 = out;
const auto _tmp = _e27;
return vs_mainOutput { _tmp.proj_position, _tmp.world_normal, _tmp.world_position };
}
struct fs_mainInput {
metal::float3 raw_normal [[user(loc0), center_perspective]];
metal::float4 position [[user(loc1), center_perspective]];
metal::float3 world_normal [[user(loc0), center_perspective]];
metal::float4 world_position [[user(loc1), center_perspective]];
};
struct fs_mainOutput {
metal::float4 member [[color(0)]];
metal::float4 member_2 [[color(0)]];
};
fragment fs_mainOutput fs_main(
fs_mainInput varyings [[stage_in]]
fs_mainInput varyings_2 [[stage_in]]
, metal::float4 proj_position [[position]]
, constant Globals& u_globals [[user(fake0)]]
, device Lights const& s_lights [[user(fake0)]]
, constant Entity& u_entity [[user(fake0)]]
, device type_6 const& s_lights [[user(fake0)]]
, metal::depth2d_array<float, metal::access::sample> t_shadow [[user(fake0)]]
, metal::sampler sampler_shadow [[user(fake0)]]
, constant _mslBufferSizes& _buffer_sizes [[user(fake0)]]
) {
const auto raw_normal = varyings.raw_normal;
const auto position = varyings.position;
const VertexOutput in = { proj_position, varyings_2.world_normal, varyings_2.world_position };
metal::float3 color = c_ambient;
uint i = 0u;
metal::float3 normal = metal::normalize(raw_normal);
metal::float3 normal_1 = metal::normalize(in.world_normal);
bool loop_init = true;
while(true) {
if (!loop_init) {
uint _e40 = i;
i = _e40 + 1u;
uint _e20 = i;
i = _e20 + 1u;
}
loop_init = false;
uint _e12 = i;
uint _e15 = u_globals.num_lights.x;
if (_e12 >= metal::min(_e15, c_max_lights)) {
uint _e14 = i;
uint _e17 = u_globals.num_lights.x;
if (_e14 < metal::min(_e17, c_max_lights)) {
} else {
break;
}
uint _e19 = i;
Light light = s_lights.data[_e19];
uint _e22 = i;
float _e25 = fetch_shadow(_e22, light.proj * position, t_shadow, sampler_shadow);
metal::float3 light_dir = metal::normalize(light.pos.xyz - position.xyz);
float diffuse = metal::max(0.0, metal::dot(normal, light_dir));
metal::float3 _e34 = color;
color = _e34 + ((_e25 * diffuse) * light.color.xyz);
uint _e23 = i;
Light light = s_lights[_e23];
uint _e26 = i;
float _e30 = fetch_shadow(_e26, light.proj * in.world_position, t_shadow, sampler_shadow);
metal::float3 light_dir = metal::normalize(light.pos.xyz - in.world_position.xyz);
float diffuse = metal::max(0.0, metal::dot(normal_1, light_dir));
metal::float3 _e40 = color;
color = _e40 + ((_e30 * diffuse) * light.color.xyz);
}
metal::float3 _e43 = color;
return fs_mainOutput { metal::float4(_e43, 1.0) };
metal::float3 _e46 = color;
metal::float4 _e50 = u_entity.color;
return fs_mainOutput { metal::float4(_e46, 1.0) * _e50 };
}
struct fs_main_without_storageInput {
metal::float3 world_normal [[user(loc0), center_perspective]];
metal::float4 world_position [[user(loc1), center_perspective]];
};
struct fs_main_without_storageOutput {
metal::float4 member_3 [[color(0)]];
};
fragment fs_main_without_storageOutput fs_main_without_storage(
fs_main_without_storageInput varyings_3 [[stage_in]]
, metal::float4 proj_position_1 [[position]]
, constant Globals& u_globals [[user(fake0)]]
, constant Entity& u_entity [[user(fake0)]]
, constant type_7& u_lights [[user(fake0)]]
, metal::depth2d_array<float, metal::access::sample> t_shadow [[user(fake0)]]
, metal::sampler sampler_shadow [[user(fake0)]]
) {
const VertexOutput in_1 = { proj_position_1, varyings_3.world_normal, varyings_3.world_position };
metal::float3 color_1 = c_ambient;
uint i_1 = 0u;
metal::float3 normal_2 = metal::normalize(in_1.world_normal);
bool loop_init_1 = true;
while(true) {
if (!loop_init_1) {
uint _e20 = i_1;
i_1 = _e20 + 1u;
}
loop_init_1 = false;
uint _e14 = i_1;
uint _e17 = u_globals.num_lights.x;
if (_e14 < metal::min(_e17, c_max_lights)) {
} else {
break;
}
uint _e23 = i_1;
Light light_1 = u_lights.inner[_e23];
uint _e26 = i_1;
float _e30 = fetch_shadow(_e26, light_1.proj * in_1.world_position, t_shadow, sampler_shadow);
metal::float3 light_dir_1 = metal::normalize(light_1.pos.xyz - in_1.world_position.xyz);
float diffuse_1 = metal::max(0.0, metal::dot(normal_2, light_dir_1));
metal::float3 _e40 = color_1;
color_1 = _e40 + ((_e30 * diffuse_1) * light_1.color.xyz);
}
metal::float3 _e46 = color_1;
metal::float4 _e50 = u_entity.color;
return fs_main_without_storageOutput { metal::float4(_e46, 1.0) * _e50 };
}

View File

@@ -1,199 +1,444 @@
; SPIR-V
; Version: 1.2
; Generator: rspirv
; Bound: 125
; Bound: 279
OpCapability Shader
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %79 "fs_main" %71 %74 %77
OpExecutionMode %79 OriginUpperLeft
OpEntryPoint Vertex %86 "vs_bake" %81 %84
OpEntryPoint Vertex %114 "vs_main" %106 %108 %110 %111 %113
OpEntryPoint Fragment %165 "fs_main" %156 %159 %162 %164
OpEntryPoint Fragment %229 "fs_main_without_storage" %222 %224 %226 %228
OpExecutionMode %165 OriginUpperLeft
OpExecutionMode %229 OriginUpperLeft
OpSource GLSL 450
OpName %9 "c_max_lights"
OpMemberName %14 0 "num_lights"
OpName %14 "Globals"
OpMemberName %17 0 "proj"
OpMemberName %17 1 "pos"
OpMemberName %17 2 "color"
OpName %17 "Light"
OpMemberName %19 0 "data"
OpName %19 "Lights"
OpName %24 "c_ambient"
OpName %25 "u_globals"
OpName %28 "s_lights"
OpName %30 "t_shadow"
OpName %32 "sampler_shadow"
OpName %35 "light_id"
OpName %36 "homogeneous_coords"
OpName %37 "fetch_shadow"
OpName %66 "color"
OpName %68 "i"
OpName %71 "raw_normal"
OpName %74 "position"
OpName %79 "fs_main"
OpMemberDecorate %14 0 Offset 0
OpMemberDecorate %17 0 Offset 0
OpMemberDecorate %17 0 ColMajor
OpMemberDecorate %17 0 MatrixStride 16
OpMemberDecorate %17 1 Offset 64
OpMemberDecorate %17 2 Offset 80
OpDecorate %18 ArrayStride 96
OpName %11 "c_max_lights"
OpMemberName %18 0 "view_proj"
OpMemberName %18 1 "num_lights"
OpName %18 "Globals"
OpMemberName %19 0 "world"
OpMemberName %19 1 "color"
OpName %19 "Entity"
OpMemberName %22 0 "proj_position"
OpMemberName %22 1 "world_normal"
OpMemberName %22 2 "world_position"
OpName %22 "VertexOutput"
OpMemberName %24 0 "proj"
OpMemberName %24 1 "pos"
OpMemberName %24 2 "color"
OpName %24 "Light"
OpName %30 "c_ambient"
OpName %31 "u_globals"
OpName %34 "u_entity"
OpName %37 "s_lights"
OpName %40 "u_lights"
OpName %43 "t_shadow"
OpName %45 "sampler_shadow"
OpName %48 "light_id"
OpName %49 "homogeneous_coords"
OpName %50 "fetch_shadow"
OpName %81 "position"
OpName %86 "vs_bake"
OpName %103 "out"
OpName %106 "position"
OpName %108 "normal"
OpName %110 "proj_position"
OpName %111 "world_normal"
OpName %113 "world_position"
OpName %114 "vs_main"
OpName %151 "color"
OpName %152 "i"
OpName %156 "proj_position"
OpName %159 "world_normal"
OpName %162 "world_position"
OpName %165 "fs_main"
OpName %218 "color"
OpName %219 "i"
OpName %222 "proj_position"
OpName %224 "world_normal"
OpName %226 "world_position"
OpName %229 "fs_main_without_storage"
OpMemberDecorate %18 0 Offset 0
OpMemberDecorate %18 0 ColMajor
OpMemberDecorate %18 0 MatrixStride 16
OpMemberDecorate %18 1 Offset 64
OpMemberDecorate %19 0 Offset 0
OpDecorate %25 DescriptorSet 0
OpDecorate %25 Binding 0
OpDecorate %26 Block
OpMemberDecorate %26 0 Offset 0
OpDecorate %28 NonWritable
OpDecorate %28 DescriptorSet 0
OpDecorate %28 Binding 1
OpDecorate %19 Block
OpDecorate %30 DescriptorSet 0
OpDecorate %30 Binding 2
OpDecorate %32 DescriptorSet 0
OpDecorate %32 Binding 3
OpDecorate %71 Location 0
OpDecorate %74 Location 1
OpDecorate %77 Location 0
OpMemberDecorate %19 0 ColMajor
OpMemberDecorate %19 0 MatrixStride 16
OpMemberDecorate %19 1 Offset 64
OpMemberDecorate %22 0 Offset 0
OpMemberDecorate %22 1 Offset 16
OpMemberDecorate %22 2 Offset 32
OpMemberDecorate %24 0 Offset 0
OpMemberDecorate %24 0 ColMajor
OpMemberDecorate %24 0 MatrixStride 16
OpMemberDecorate %24 1 Offset 64
OpMemberDecorate %24 2 Offset 80
OpDecorate %25 ArrayStride 96
OpDecorate %26 ArrayStride 96
OpDecorate %31 DescriptorSet 0
OpDecorate %31 Binding 0
OpDecorate %32 Block
OpMemberDecorate %32 0 Offset 0
OpDecorate %34 DescriptorSet 1
OpDecorate %34 Binding 0
OpDecorate %35 Block
OpMemberDecorate %35 0 Offset 0
OpDecorate %37 NonWritable
OpDecorate %37 DescriptorSet 0
OpDecorate %37 Binding 1
OpDecorate %38 Block
OpMemberDecorate %38 0 Offset 0
OpDecorate %40 DescriptorSet 0
OpDecorate %40 Binding 1
OpDecorate %41 Block
OpMemberDecorate %41 0 Offset 0
OpDecorate %43 DescriptorSet 0
OpDecorate %43 Binding 2
OpDecorate %45 DescriptorSet 0
OpDecorate %45 Binding 3
OpDecorate %81 Location 0
OpDecorate %81 Flat
OpDecorate %84 BuiltIn Position
OpDecorate %106 Location 0
OpDecorate %106 Flat
OpDecorate %108 Location 1
OpDecorate %108 Flat
OpDecorate %110 BuiltIn Position
OpDecorate %111 Location 0
OpDecorate %113 Location 1
OpDecorate %156 BuiltIn FragCoord
OpDecorate %159 Location 0
OpDecorate %162 Location 1
OpDecorate %164 Location 0
OpDecorate %222 BuiltIn FragCoord
OpDecorate %224 Location 0
OpDecorate %226 Location 1
OpDecorate %228 Location 0
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpConstant %4 0.0
%5 = OpConstant %4 1.0
%6 = OpConstant %4 0.5
%7 = OpConstant %4 -0.5
%8 = OpConstant %4 0.05
%10 = OpTypeInt 32 0
%9 = OpConstant %10 10
%11 = OpConstant %10 0
%12 = OpConstant %10 1
%13 = OpTypeVector %10 4
%14 = OpTypeStruct %13
%16 = OpTypeVector %4 4
%4 = OpTypeInt 32 1
%3 = OpConstant %4 10
%6 = OpTypeFloat 32
%5 = OpConstant %6 0.0
%7 = OpConstant %6 1.0
%8 = OpConstant %6 0.5
%9 = OpConstant %6 -0.5
%10 = OpConstant %6 0.05
%12 = OpTypeInt 32 0
%11 = OpConstant %12 10
%13 = OpConstant %12 0
%14 = OpConstant %12 1
%16 = OpTypeVector %6 4
%15 = OpTypeMatrix %16 4
%17 = OpTypeStruct %15 %16 %16
%18 = OpTypeRuntimeArray %17
%19 = OpTypeStruct %18
%20 = OpTypeImage %4 2D 1 1 0 1 Unknown
%21 = OpTypeSampler
%22 = OpTypeVector %4 2
%23 = OpTypeVector %4 3
%24 = OpConstantComposite %23 %8 %8 %8
%26 = OpTypeStruct %14
%27 = OpTypePointer Uniform %26
%25 = OpVariable %27 Uniform
%29 = OpTypePointer StorageBuffer %19
%28 = OpVariable %29 StorageBuffer
%31 = OpTypePointer UniformConstant %20
%30 = OpVariable %31 UniformConstant
%33 = OpTypePointer UniformConstant %21
%32 = OpVariable %33 UniformConstant
%38 = OpTypeFunction %4 %10 %16
%41 = OpTypePointer Uniform %14
%44 = OpTypeBool
%56 = OpTypeInt 32 1
%61 = OpTypeSampledImage %20
%67 = OpTypePointer Function %23
%69 = OpTypePointer Function %10
%72 = OpTypePointer Input %23
%71 = OpVariable %72 Input
%75 = OpTypePointer Input %16
%74 = OpVariable %75 Input
%78 = OpTypePointer Output %16
%77 = OpVariable %78 Output
%80 = OpTypeFunction %2
%91 = OpTypePointer Uniform %13
%92 = OpTypePointer Uniform %10
%99 = OpTypePointer StorageBuffer %18
%101 = OpTypePointer StorageBuffer %17
%37 = OpFunction %4 None %38
%35 = OpFunctionParameter %10
%36 = OpFunctionParameter %16
%34 = OpLabel
%39 = OpLoad %20 %30
%40 = OpLoad %21 %32
OpBranch %42
%42 = OpLabel
%43 = OpCompositeExtract %4 %36 3
%45 = OpFOrdLessThanEqual %44 %43 %3
OpSelectionMerge %46 None
OpBranchConditional %45 %47 %46
%17 = OpTypeVector %12 4
%18 = OpTypeStruct %15 %17
%19 = OpTypeStruct %15 %16
%20 = OpTypeVector %4 4
%21 = OpTypeVector %6 3
%22 = OpTypeStruct %16 %21 %16
%23 = OpTypeMatrix %21 3
%24 = OpTypeStruct %15 %16 %16
%25 = OpTypeRuntimeArray %24
%26 = OpTypeArray %24 %3
%27 = OpTypeImage %6 2D 1 1 0 1 Unknown
%28 = OpTypeSampler
%29 = OpTypeVector %6 2
%30 = OpConstantComposite %21 %10 %10 %10
%32 = OpTypeStruct %18
%33 = OpTypePointer Uniform %32
%31 = OpVariable %33 Uniform
%35 = OpTypeStruct %19
%36 = OpTypePointer Uniform %35
%34 = OpVariable %36 Uniform
%38 = OpTypeStruct %25
%39 = OpTypePointer StorageBuffer %38
%37 = OpVariable %39 StorageBuffer
%41 = OpTypeStruct %26
%42 = OpTypePointer Uniform %41
%40 = OpVariable %42 Uniform
%44 = OpTypePointer UniformConstant %27
%43 = OpVariable %44 UniformConstant
%46 = OpTypePointer UniformConstant %28
%45 = OpVariable %46 UniformConstant
%51 = OpTypeFunction %6 %12 %16
%54 = OpTypePointer Uniform %19
%55 = OpTypePointer Uniform %18
%56 = OpTypePointer Uniform %26
%57 = OpTypePointer StorageBuffer %25
%60 = OpTypeBool
%75 = OpTypeSampledImage %27
%82 = OpTypePointer Input %20
%81 = OpVariable %82 Input
%85 = OpTypePointer Output %16
%84 = OpVariable %85 Output
%87 = OpTypeFunction %2
%91 = OpTypePointer Uniform %15
%99 = OpTypePointer Output %6
%104 = OpTypePointer Function %22
%106 = OpVariable %82 Input
%108 = OpVariable %82 Input
%110 = OpVariable %85 Output
%112 = OpTypePointer Output %21
%111 = OpVariable %112 Output
%113 = OpVariable %85 Output
%124 = OpTypePointer Function %21
%132 = OpTypeVector %4 3
%137 = OpTypePointer Function %16
%138 = OpConstant %12 2
%153 = OpTypePointer Function %12
%157 = OpTypePointer Input %16
%156 = OpVariable %157 Input
%160 = OpTypePointer Input %21
%159 = OpVariable %160 Input
%162 = OpVariable %157 Input
%164 = OpVariable %85 Output
%179 = OpTypePointer Uniform %17
%180 = OpTypePointer Uniform %12
%188 = OpTypePointer StorageBuffer %24
%214 = OpTypePointer Uniform %16
%222 = OpVariable %157 Input
%224 = OpVariable %160 Input
%226 = OpVariable %157 Input
%228 = OpVariable %85 Output
%250 = OpTypePointer Uniform %24
%50 = OpFunction %6 None %51
%48 = OpFunctionParameter %12
%49 = OpFunctionParameter %16
%47 = OpLabel
OpReturnValue %5
%46 = OpLabel
%48 = OpCompositeConstruct %22 %6 %7
%49 = OpVectorShuffle %22 %36 %36 0 1
%50 = OpFMul %22 %49 %48
%51 = OpCompositeExtract %4 %36 3
%52 = OpCompositeConstruct %22 %51 %51
%53 = OpFDiv %22 %50 %52
%54 = OpCompositeConstruct %22 %6 %6
%55 = OpFAdd %22 %53 %54
%57 = OpBitcast %56 %35
%58 = OpCompositeExtract %4 %36 2
%59 = OpCompositeExtract %4 %36 3
%60 = OpFDiv %4 %58 %59
%62 = OpConvertUToF %4 %57
%63 = OpCompositeConstruct %23 %55 %62
%64 = OpSampledImage %61 %39 %40
%65 = OpImageSampleDrefExplicitLod %4 %64 %63 %60 Lod %3
OpReturnValue %65
%52 = OpLoad %27 %43
%53 = OpLoad %28 %45
OpBranch %58
%58 = OpLabel
%59 = OpCompositeExtract %6 %49 3
%61 = OpFOrdLessThanEqual %60 %59 %5
OpSelectionMerge %62 None
OpBranchConditional %61 %63 %62
%63 = OpLabel
OpReturnValue %7
%62 = OpLabel
%64 = OpCompositeConstruct %29 %8 %9
%65 = OpCompositeExtract %6 %49 3
%66 = OpFDiv %6 %7 %65
%67 = OpVectorShuffle %29 %49 %49 0 1
%68 = OpFMul %29 %67 %64
%69 = OpVectorTimesScalar %29 %68 %66
%70 = OpCompositeConstruct %29 %8 %8
%71 = OpFAdd %29 %69 %70
%72 = OpBitcast %4 %48
%73 = OpCompositeExtract %6 %49 2
%74 = OpFMul %6 %73 %66
%76 = OpConvertUToF %6 %72
%77 = OpCompositeConstruct %21 %71 %76
%78 = OpSampledImage %75 %52 %53
%79 = OpImageSampleDrefExplicitLod %6 %78 %77 %74 Lod %5
OpReturnValue %79
OpFunctionEnd
%79 = OpFunction %2 None %80
%70 = OpLabel
%66 = OpVariable %67 Function %24
%68 = OpVariable %69 Function %11
%73 = OpLoad %23 %71
%76 = OpLoad %16 %74
%81 = OpAccessChain %41 %25 %11
%82 = OpLoad %20 %30
%83 = OpLoad %21 %32
OpBranch %84
%84 = OpLabel
%85 = OpExtInst %23 %1 Normalize %73
OpBranch %86
%86 = OpLabel
OpLoopMerge %87 %89 None
OpBranch %88
%88 = OpLabel
%90 = OpLoad %10 %68
%93 = OpAccessChain %92 %81 %11 %11
%94 = OpLoad %10 %93
%95 = OpExtInst %10 %1 UMin %94 %9
%96 = OpUGreaterThanEqual %44 %90 %95
OpSelectionMerge %97 None
OpBranchConditional %96 %98 %97
%98 = OpLabel
OpBranch %87
%97 = OpLabel
%100 = OpLoad %10 %68
%102 = OpAccessChain %101 %28 %11 %100
%103 = OpLoad %17 %102
%104 = OpLoad %10 %68
%105 = OpCompositeExtract %15 %103 0
%106 = OpMatrixTimesVector %16 %105 %76
%107 = OpFunctionCall %4 %37 %104 %106
%108 = OpCompositeExtract %16 %103 1
%109 = OpVectorShuffle %23 %108 %108 0 1 2
%110 = OpVectorShuffle %23 %76 %76 0 1 2
%111 = OpFSub %23 %109 %110
%112 = OpExtInst %23 %1 Normalize %111
%113 = OpDot %4 %85 %112
%114 = OpExtInst %4 %1 FMax %3 %113
%115 = OpLoad %23 %66
%116 = OpFMul %4 %107 %114
%117 = OpCompositeExtract %16 %103 2
%118 = OpVectorShuffle %23 %117 %117 0 1 2
%119 = OpVectorTimesScalar %23 %118 %116
%120 = OpFAdd %23 %115 %119
OpStore %66 %120
OpBranch %89
%89 = OpLabel
%121 = OpLoad %10 %68
%122 = OpIAdd %10 %121 %12
OpStore %68 %122
OpBranch %86
%87 = OpLabel
%123 = OpLoad %23 %66
%124 = OpCompositeConstruct %16 %123 %5
OpStore %77 %124
%86 = OpFunction %2 None %87
%80 = OpLabel
%83 = OpLoad %20 %81
%88 = OpAccessChain %55 %31 %13
%89 = OpAccessChain %54 %34 %13
OpBranch %90
%90 = OpLabel
%92 = OpAccessChain %91 %88 %13
%93 = OpLoad %15 %92
%94 = OpAccessChain %91 %89 %13
%95 = OpLoad %15 %94
%96 = OpMatrixTimesMatrix %15 %93 %95
%97 = OpConvertSToF %16 %83
%98 = OpMatrixTimesVector %16 %96 %97
OpStore %84 %98
%100 = OpAccessChain %99 %84 %14
%101 = OpLoad %6 %100
%102 = OpFNegate %6 %101
OpStore %100 %102
OpReturn
OpFunctionEnd
%114 = OpFunction %2 None %87
%105 = OpLabel
%103 = OpVariable %104 Function
%107 = OpLoad %20 %106
%109 = OpLoad %20 %108
%115 = OpAccessChain %55 %31 %13
%116 = OpAccessChain %54 %34 %13
OpBranch %117
%117 = OpLabel
%118 = OpAccessChain %91 %116 %13
%119 = OpLoad %15 %118
%120 = OpAccessChain %91 %116 %13
%121 = OpLoad %15 %120
%122 = OpConvertSToF %16 %107
%123 = OpMatrixTimesVector %16 %121 %122
%125 = OpCompositeExtract %16 %119 0
%126 = OpVectorShuffle %21 %125 %125 0 1 2
%127 = OpCompositeExtract %16 %119 1
%128 = OpVectorShuffle %21 %127 %127 0 1 2
%129 = OpCompositeExtract %16 %119 2
%130 = OpVectorShuffle %21 %129 %129 0 1 2
%131 = OpCompositeConstruct %23 %126 %128 %130
%133 = OpVectorShuffle %132 %109 %109 0 1 2
%134 = OpConvertSToF %21 %133
%135 = OpMatrixTimesVector %21 %131 %134
%136 = OpAccessChain %124 %103 %14
OpStore %136 %135
%139 = OpAccessChain %137 %103 %138
OpStore %139 %123
%140 = OpAccessChain %91 %115 %13
%141 = OpLoad %15 %140
%142 = OpMatrixTimesVector %16 %141 %123
%143 = OpAccessChain %137 %103 %13
OpStore %143 %142
%144 = OpLoad %22 %103
%145 = OpCompositeExtract %16 %144 0
OpStore %110 %145
%146 = OpAccessChain %99 %110 %14
%147 = OpLoad %6 %146
%148 = OpFNegate %6 %147
OpStore %146 %148
%149 = OpCompositeExtract %21 %144 1
OpStore %111 %149
%150 = OpCompositeExtract %16 %144 2
OpStore %113 %150
OpReturn
OpFunctionEnd
%165 = OpFunction %2 None %87
%154 = OpLabel
%151 = OpVariable %124 Function %30
%152 = OpVariable %153 Function %13
%158 = OpLoad %16 %156
%161 = OpLoad %21 %159
%163 = OpLoad %16 %162
%155 = OpCompositeConstruct %22 %158 %161 %163
%166 = OpAccessChain %55 %31 %13
%167 = OpAccessChain %54 %34 %13
%168 = OpAccessChain %57 %37 %13
%169 = OpLoad %27 %43
%170 = OpLoad %28 %45
OpBranch %171
%171 = OpLabel
%172 = OpCompositeExtract %21 %155 1
%173 = OpExtInst %21 %1 Normalize %172
OpBranch %174
%174 = OpLabel
OpLoopMerge %175 %177 None
OpBranch %176
%176 = OpLabel
%178 = OpLoad %12 %152
%181 = OpAccessChain %180 %166 %14 %13
%182 = OpLoad %12 %181
%183 = OpExtInst %12 %1 UMin %182 %11
%184 = OpULessThan %60 %178 %183
OpSelectionMerge %185 None
OpBranchConditional %184 %185 %186
%186 = OpLabel
OpBranch %175
%185 = OpLabel
%187 = OpLoad %12 %152
%189 = OpAccessChain %188 %168 %187
%190 = OpLoad %24 %189
%191 = OpLoad %12 %152
%192 = OpCompositeExtract %15 %190 0
%193 = OpCompositeExtract %16 %155 2
%194 = OpMatrixTimesVector %16 %192 %193
%195 = OpFunctionCall %6 %50 %191 %194
%196 = OpCompositeExtract %16 %190 1
%197 = OpVectorShuffle %21 %196 %196 0 1 2
%198 = OpCompositeExtract %16 %155 2
%199 = OpVectorShuffle %21 %198 %198 0 1 2
%200 = OpFSub %21 %197 %199
%201 = OpExtInst %21 %1 Normalize %200
%202 = OpDot %6 %173 %201
%203 = OpExtInst %6 %1 FMax %5 %202
%204 = OpLoad %21 %151
%205 = OpFMul %6 %195 %203
%206 = OpCompositeExtract %16 %190 2
%207 = OpVectorShuffle %21 %206 %206 0 1 2
%208 = OpVectorTimesScalar %21 %207 %205
%209 = OpFAdd %21 %204 %208
OpStore %151 %209
OpBranch %177
%177 = OpLabel
%210 = OpLoad %12 %152
%211 = OpIAdd %12 %210 %14
OpStore %152 %211
OpBranch %174
%175 = OpLabel
%212 = OpLoad %21 %151
%213 = OpCompositeConstruct %16 %212 %7
%215 = OpAccessChain %214 %167 %14
%216 = OpLoad %16 %215
%217 = OpFMul %16 %213 %216
OpStore %164 %217
OpReturn
OpFunctionEnd
%229 = OpFunction %2 None %87
%220 = OpLabel
%218 = OpVariable %124 Function %30
%219 = OpVariable %153 Function %13
%223 = OpLoad %16 %222
%225 = OpLoad %21 %224
%227 = OpLoad %16 %226
%221 = OpCompositeConstruct %22 %223 %225 %227
%230 = OpAccessChain %55 %31 %13
%231 = OpAccessChain %54 %34 %13
%232 = OpAccessChain %56 %40 %13
%233 = OpLoad %27 %43
%234 = OpLoad %28 %45
OpBranch %235
%235 = OpLabel
%236 = OpCompositeExtract %21 %221 1
%237 = OpExtInst %21 %1 Normalize %236
OpBranch %238
%238 = OpLabel
OpLoopMerge %239 %241 None
OpBranch %240
%240 = OpLabel
%242 = OpLoad %12 %219
%243 = OpAccessChain %180 %230 %14 %13
%244 = OpLoad %12 %243
%245 = OpExtInst %12 %1 UMin %244 %11
%246 = OpULessThan %60 %242 %245
OpSelectionMerge %247 None
OpBranchConditional %246 %247 %248
%248 = OpLabel
OpBranch %239
%247 = OpLabel
%249 = OpLoad %12 %219
%251 = OpAccessChain %250 %232 %249
%252 = OpLoad %24 %251
%253 = OpLoad %12 %219
%254 = OpCompositeExtract %15 %252 0
%255 = OpCompositeExtract %16 %221 2
%256 = OpMatrixTimesVector %16 %254 %255
%257 = OpFunctionCall %6 %50 %253 %256
%258 = OpCompositeExtract %16 %252 1
%259 = OpVectorShuffle %21 %258 %258 0 1 2
%260 = OpCompositeExtract %16 %221 2
%261 = OpVectorShuffle %21 %260 %260 0 1 2
%262 = OpFSub %21 %259 %261
%263 = OpExtInst %21 %1 Normalize %262
%264 = OpDot %6 %237 %263
%265 = OpExtInst %6 %1 FMax %5 %264
%266 = OpLoad %21 %218
%267 = OpFMul %6 %257 %265
%268 = OpCompositeExtract %16 %252 2
%269 = OpVectorShuffle %21 %268 %268 0 1 2
%270 = OpVectorTimesScalar %21 %269 %267
%271 = OpFAdd %21 %266 %270
OpStore %218 %271
OpBranch %241
%241 = OpLabel
%272 = OpLoad %12 %219
%273 = OpIAdd %12 %272 %14
OpStore %219 %273
OpBranch %238
%239 = OpLabel
%274 = OpLoad %21 %218
%275 = OpCompositeConstruct %16 %274 %7
%276 = OpAccessChain %214 %231 %14
%277 = OpLoad %16 %276
%278 = OpFMul %16 %275 %277
OpStore %228 %278
OpReturn
OpFunctionEnd

View File

@@ -1,24 +1,36 @@
struct Globals {
view_proj: mat4x4<f32>;
num_lights: vec4<u32>;
};
struct Entity {
world: mat4x4<f32>;
color: vec4<f32>;
};
struct VertexOutput {
@builtin(position) proj_position: vec4<f32>;
@location(0) world_normal: vec3<f32>;
@location(1) world_position: vec4<f32>;
};
struct Light {
proj: mat4x4<f32>;
pos: vec4<f32>;
color: vec4<f32>;
};
struct Lights {
data: array<Light>;
};
let c_ambient: vec3<f32> = vec3<f32>(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
let c_max_lights: u32 = 10u;
@group(0) @binding(0)
var<uniform> u_globals: Globals;
@group(1) @binding(0)
var<uniform> u_entity: Entity;
@group(0) @binding(1)
var<storage> s_lights: Lights;
var<storage> s_lights: array<Light>;
@group(0) @binding(1)
var<uniform> u_lights: array<Light,10>;
@group(0) @binding(2)
var t_shadow: texture_depth_2d_array;
@group(0) @binding(3)
@@ -29,36 +41,92 @@ fn fetch_shadow(light_id: u32, homogeneous_coords: vec4<f32>) -> f32 {
return 1.0;
}
let flip_correction = vec2<f32>(0.5, -0.5);
let light_local = (((homogeneous_coords.xy * flip_correction) / vec2<f32>(homogeneous_coords.w)) + vec2<f32>(0.5, 0.5));
let _e26 = textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), (homogeneous_coords.z / homogeneous_coords.w));
return _e26;
let proj_correction = (1.0 / homogeneous_coords.w);
let light_local = (((homogeneous_coords.xy * flip_correction) * proj_correction) + vec2<f32>(0.5, 0.5));
let _e28 = textureSampleCompareLevel(t_shadow, sampler_shadow, light_local, i32(light_id), (homogeneous_coords.z * proj_correction));
return _e28;
}
@stage(vertex)
fn vs_bake(@location(0) position: vec4<i32>) -> @builtin(position) vec4<f32> {
let _e4 = u_globals.view_proj;
let _e6 = u_entity.world;
return ((_e4 * _e6) * vec4<f32>(position));
}
@stage(vertex)
fn vs_main(@location(0) position_1: vec4<i32>, @location(1) normal: vec4<i32>) -> VertexOutput {
var out: VertexOutput;
let w = u_entity.world;
let _e7 = u_entity.world;
let world_pos = (_e7 * vec4<f32>(position_1));
out.world_normal = (mat3x3<f32>(w[0].xyz, w[1].xyz, w[2].xyz) * vec3<f32>(normal.xyz));
out.world_position = world_pos;
let _e25 = u_globals.view_proj;
out.proj_position = (_e25 * world_pos);
let _e27 = out;
return _e27;
}
@stage(fragment)
fn fs_main(@location(0) raw_normal: vec3<f32>, @location(1) position: vec4<f32>) -> @location(0) vec4<f32> {
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
var color: vec3<f32> = vec3<f32>(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
var i: u32 = 0u;
let normal = normalize(raw_normal);
let normal_1 = normalize(in.world_normal);
loop {
let _e12 = i;
let _e15 = u_globals.num_lights.x;
if (_e12 >= min(_e15, c_max_lights)) {
let _e14 = i;
let _e17 = u_globals.num_lights.x;
if (_e14 < min(_e17, c_max_lights)) {
} else {
break;
}
let _e19 = i;
let light = s_lights.data[_e19];
let _e22 = i;
let _e25 = fetch_shadow(_e22, (light.proj * position));
let light_dir = normalize((light.pos.xyz - position.xyz));
let diffuse = max(0.0, dot(normal, light_dir));
let _e34 = color;
color = (_e34 + ((_e25 * diffuse) * light.color.xyz));
let _e23 = i;
let light = s_lights[_e23];
let _e26 = i;
let _e30 = fetch_shadow(_e26, (light.proj * in.world_position));
let light_dir = normalize((light.pos.xyz - in.world_position.xyz));
let diffuse = max(0.0, dot(normal_1, light_dir));
let _e40 = color;
color = (_e40 + ((_e30 * diffuse) * light.color.xyz));
continuing {
let _e40 = i;
i = (_e40 + 1u);
let _e20 = i;
i = (_e20 + 1u);
}
}
let _e43 = color;
return vec4<f32>(_e43, 1.0);
let _e46 = color;
let _e50 = u_entity.color;
return (vec4<f32>(_e46, 1.0) * _e50);
}
@stage(fragment)
fn fs_main_without_storage(in_1: VertexOutput) -> @location(0) vec4<f32> {
var color_1: vec3<f32> = vec3<f32>(0.05000000074505806, 0.05000000074505806, 0.05000000074505806);
var i_1: u32 = 0u;
let normal_2 = normalize(in_1.world_normal);
loop {
let _e14 = i_1;
let _e17 = u_globals.num_lights.x;
if (_e14 < min(_e17, c_max_lights)) {
} else {
break;
}
let _e23 = i_1;
let light_1 = u_lights[_e23];
let _e26 = i_1;
let _e30 = fetch_shadow(_e26, (light_1.proj * in_1.world_position));
let light_dir_1 = normalize((light_1.pos.xyz - in_1.world_position.xyz));
let diffuse_1 = max(0.0, dot(normal_2, light_dir_1));
let _e40 = color_1;
color_1 = (_e40 + ((_e30 * diffuse_1) * light_1.color.xyz));
continuing {
let _e20 = i_1;
i_1 = (_e20 + 1u);
}
}
let _e46 = color_1;
let _e50 = u_entity.color;
return (vec4<f32>(_e46, 1.0) * _e50);
}