pub const GPU_DEVICE_FALLBACK: &str = "euv-software-fallback";
pub const GPU_DEVICE_WEB: &str = "Browser WebGL2 / WebGPU";
pub const GPU_DEVICE_D3D12: &str = "Windows Direct3D 12";
pub const GPU_DEVICE_VULKAN: &str = "Vulkan Physical GPU";
pub const GPU_DRIVER_RING_SLOTS: usize = 3;
pub const MOBILE_MAX_MULTI_UPLOAD_RECTS: usize = 12;
pub const MOBILE_UPLOAD_PER_RECT_OVERHEAD_BYTES: usize = 16_384;
pub const MOBILE_UPLOAD_FULL_FRAME_COVERAGE_THRESHOLD: f32 = 0.70;
pub const MOBILE_UPLOAD_COALESCE_PAD_PX: u32 = 4;
pub const GLSL_ES3_BACKDROP_BLUR_VERTEX_SHADER: &str = "#version 300 es\n\
precision highp float;\n\
precision highp int;\n\
out highp vec2 v_uv;\n\
void main() {\n\
vec2 p = vec2((gl_VertexID == 1) ? 3.0 : -1.0, (gl_VertexID == 2) ? 3.0 : -1.0);\n\
gl_Position = vec4(p, 0.0, 1.0);\n\
v_uv = vec2(p.x * 0.5 + 0.5, p.y * 0.5 + 0.5);\n\
}\n";
pub const MOBILE_TIMING_UNOBSERVABLE_REASON_SIMULATOR: &str = "simulator_compositor_unobservable";
pub const MOBILE_TIMING_UNOBSERVABLE_REASON_UNSUPPORTED: &str = "presentation_time_unsupported";
pub const WEB_GL2_BLIT_VERT_SHADER: &str = "#version 300 es\n\
precision highp float;\n\
precision highp int;\n\
void main() {\n\
vec2 pos = vec2((gl_VertexID == 1) ? 3.0 : -1.0, (gl_VertexID == 2) ? 3.0 : -1.0);\n\
gl_Position = vec4(pos, 0.0, 1.0);\n\
}\n";
pub const WEB_GL2_BLIT_FRAG_SHADER: &str = "#version 300 es\n\
precision highp float;\n\
precision highp int;\n\
precision highp sampler2D;\n\
uniform highp sampler2D u_tex;\n\
uniform highp vec2 u_view;\n\
out highp vec4 out_color;\n\
void main() {\n\
ivec2 tex_size = textureSize(u_tex, 0);\n\
highp vec2 view = max(u_view, vec2(1.0));\n\
ivec2 view_size = ivec2(view + vec2(0.5));\n\
if (tex_size == view_size) {\n\
ivec2 texel = ivec2(int(gl_FragCoord.x), tex_size.y - 1 - int(gl_FragCoord.y));\n\
out_color = texelFetch(u_tex, clamp(texel, ivec2(0), tex_size - ivec2(1)), 0);\n\
} else {\n\
highp vec2 uv = vec2(gl_FragCoord.x, view.y - gl_FragCoord.y) / view;\n\
out_color = texture(u_tex, uv);\n\
}\n\
}\n";
pub const WGSL_FLUID_OCEAN_SHADER: &str = r#"struct OceanUniforms {
viewport_time_agitation: vec4<f32>,
sun_dir_horizon: vec4<f32>,
roll_cos_sin_pad: vec4<f32>,
};
@group(0) @binding(0) var<uniform> u_ocean: OceanUniforms;
struct OceanVertOut {
@builtin(position) pos: vec4<f32>,
@location(0) uv: vec2<f32>,
};
@vertex
fn euv_ocean_vertex(@builtin(vertex_index) vid: u32) -> OceanVertOut {
let px = select(-1.0, 3.0, vid == 1u);
let py = select(-1.0, 3.0, vid == 2u);
var out: OceanVertOut;
out.pos = vec4<f32>(px, py, 0.0, 1.0);
out.uv = vec2<f32>(px * 0.5 + 0.5, 0.5 - py * 0.5);
return out;
}
fn euv_ocean_aces(hdr: vec3<f32>) -> vec3<f32> {
let num = hdr * (2.51 * hdr + 0.03);
let den = hdr * (2.43 * hdr + 0.59) + 0.14;
return clamp(num / max(den, vec3<f32>(0.0001)), vec3<f32>(0.0), vec3<f32>(1.0));
}
@fragment
fn euv_ocean_fragment(in: OceanVertOut) -> @location(0) vec4<f32> {
let sim_time = u_ocean.viewport_time_agitation.z;
let agitation = max(u_ocean.viewport_time_agitation.w, 1.0);
let sun_dir = normalize(u_ocean.sun_dir_horizon.xyz);
let horizon_v = u_ocean.sun_dir_horizon.w;
let ray = normalize(vec3<f32>((in.uv.x - 0.5) * 2.0, (horizon_v - in.uv.y) * 2.0, 1.62));
var col = vec3<f32>(0.0);
if (ray.y >= 0.0) {
let sdot = clamp(dot(ray, sun_dir), 0.0, 1.0);
let glow = pow(sdot, 16.0);
let disk = smoothstep(0.9991, 0.9997, sdot);
let sky_t = smoothstep(0.0, 0.62, ray.y);
let horiz = vec3<f32>(0.76, 0.88, 0.98) + vec3<f32>(0.78, 0.54, 0.24) * glow;
col = mix(horiz, vec3<f32>(0.09, 0.36, 0.96), sky_t) + vec3<f32>(4.2, 3.6, 2.7) * disk;
} else {
let dist = min(1.42 / max(-ray.y, 0.0024), 240.0);
let wp = ray.xz * dist;
let w0 = sin(wp.x * 0.05 + wp.y * 0.62 + sim_time * 0.88) * 0.22 * agitation;
let w1 = sin(-wp.x * 0.19 + wp.y * 1.06 + sim_time * 1.18) * 0.15 * agitation;
let norm = normalize(vec3<f32>(-(w0 * 0.12 - w1 * 0.20), 1.0, -(w0 * 0.62 + w1 * 1.06)));
let vdir = -ray;
let ndv = clamp(dot(norm, vdir), 0.002, 1.0);
let fresnel = clamp(0.0204 + 0.9796 * pow(1.0 - ndv, 5.0), 0.022, 0.88);
let hvec = normalize(vdir + sun_dir);
let ndh = max(dot(norm, hvec), 0.0);
let a2 = 0.0014;
let den = ndh * ndh * (a2 - 1.0) + 1.0;
let ggx = min(a2 / (3.14159265 * den * den), 14.0);
let body = vec3<f32>(0.004, 0.095, 0.185) + vec3<f32>(0.018, 0.48, 0.58) * clamp(w0 + w1 + 0.18, 0.0, 1.0) * exp(-dist * 0.05);
col = mix(body, vec3<f32>(0.24, 0.56, 0.94), fresnel * 0.54) + vec3<f32>(1.36, 1.24, 1.02) * ggx * 0.55;
}
return vec4<f32>(pow(euv_ocean_aces(col), vec3<f32>(1.0 / 2.2)), 1.0);
}
"#;
pub const MSL_FLUID_OCEAN_SHADER: &str = r#"#include <metal_stdlib>
using namespace metal;
struct OceanUniforms {
float4 viewport_time_agitation;
float4 sun_dir_horizon;
float4 roll_cos_sin_pad;
};
struct OceanVertOut {
float4 pos [[position]];
float2 uv;
};
vertex OceanVertOut euv_ocean_vertex(uint vid [[vertex_id]]) {
float2 pos = float2((vid == 1) ? 3.0 : -1.0, (vid == 2) ? 3.0 : -1.0);
OceanVertOut out;
out.pos = float4(pos, 0.0, 1.0);
out.uv = float2(pos.x * 0.5 + 0.5, 0.5 - pos.y * 0.5);
return out;
}
static inline float3 euv_ocean_aces(float3 hdr) {
float3 num = hdr * (2.51 * hdr + 0.03);
float3 den = hdr * (2.43 * hdr + 0.59) + 0.14;
return clamp(num / max(den, float3(0.0001)), float3(0.0), float3(1.0));
}
fragment float4 euv_ocean_fragment(
OceanVertOut in [[stage_in]],
constant OceanUniforms& u [[buffer(0)]]
) {
float sim_time = u.viewport_time_agitation.z;
float agitation = max(u.viewport_time_agitation.w, 1.0);
float3 sun_dir = normalize(u.sun_dir_horizon.xyz);
float horizon_v = u.sun_dir_horizon.w;
float2 centered = float2((in.uv.x - 0.5) * 2.0, (horizon_v - in.uv.y) * 2.0);
float3 ray = normalize(float3(centered.x, centered.y, 1.62));
float3 color;
if (ray.y >= 0.0) {
float sun_dot = clamp(dot(ray, sun_dir), 0.0, 1.0);
float glow = pow(sun_dot, 16.0);
float disk = smoothstep(0.9991, 0.9997, sun_dot);
float sky_t = smoothstep(0.0, 0.62, ray.y);
float3 horiz = float3(0.76, 0.88, 0.98) + float3(0.78, 0.54, 0.24) * glow;
float3 zenith = float3(0.09, 0.36, 0.96);
color = mix(horiz, zenith, sky_t) + float3(4.2, 3.6, 2.7) * disk;
} else {
float dist = min(1.42 / max(-ray.y, 0.0024), 240.0);
float2 wp = ray.xz * dist;
float w0 = sin(wp.x * 0.05 + wp.y * 0.62 + sim_time * 0.88) * 0.22 * agitation;
float w1 = sin(-wp.x * 0.19 + wp.y * 1.06 + sim_time * 1.18) * 0.15 * agitation;
float3 norm = normalize(float3(-(w0 * 0.12 - w1 * 0.20), 1.0, -(w0 * 0.62 + w1 * 1.06)));
float3 view_dir = -ray;
float ndv = clamp(dot(norm, view_dir), 0.002, 1.0);
float fresnel = clamp(0.0204 + 0.9796 * pow(1.0 - ndv, 5.0), 0.022, 0.88);
float3 half_vec = normalize(view_dir + sun_dir);
float ndh = max(dot(norm, half_vec), 0.0);
float a2 = 0.0014;
float denom = ndh * ndh * (a2 - 1.0) + 1.0;
float ggx = min(a2 / (3.14159265 * denom * denom), 14.0);
float3 body = float3(0.004, 0.095, 0.185) + float3(0.018, 0.48, 0.58) * clamp(w0 + w1 + 0.18, 0.0, 1.0) * exp(-dist * 0.05);
float3 sky_refl = float3(0.24, 0.56, 0.94);
color = mix(body, sky_refl, fresnel * 0.54) + float3(1.36, 1.24, 1.02) * ggx * 0.55;
}
float3 ldr = pow(euv_ocean_aces(color), float3(1.0 / 2.2));
return float4(ldr, 1.0);
}
"#;
pub const GLSL_ES3_FLUID_OCEAN_FRAGMENT_SHADER: &str = r#"#version 300 es
precision highp float;
in highp vec2 v_uv;
uniform highp vec4 u_viewport_time_agitation;
uniform highp vec4 u_sun_dir_horizon;
out vec4 out_color;
vec3 euv_ocean_aces(vec3 hdr) {
vec3 num = hdr * (2.51 * hdr + 0.03);
vec3 den = hdr * (2.43 * hdr + 0.59) + 0.14;
return clamp(num / max(den, vec3(0.0001)), vec3(0.0), vec3(1.0));
}
void main() {
float sim_time = u_viewport_time_agitation.z;
float agitation = max(u_viewport_time_agitation.w, 1.0);
vec3 sun_dir = normalize(u_sun_dir_horizon.xyz);
vec3 ray = normalize(vec3((v_uv.x - 0.5) * 2.0, (u_sun_dir_horizon.w - v_uv.y) * 2.0, 1.62));
vec3 color;
if (ray.y >= 0.0) {
float sdot = clamp(dot(ray, sun_dir), 0.0, 1.0);
color = mix(vec3(0.76, 0.88, 0.98) + vec3(0.78, 0.54, 0.24) * pow(sdot, 16.0), vec3(0.09, 0.36, 0.96), smoothstep(0.0, 0.62, ray.y));
} else {
float dist = min(1.42 / max(-ray.y, 0.0024), 240.0);
vec2 wp = ray.xz * dist;
float w0 = sin(wp.x * 0.05 + wp.y * 0.62 + sim_time * 0.88) * 0.22 * agitation;
vec3 norm = normalize(vec3(-w0 * 0.12, 1.0, -w0 * 0.62));
float ndv = clamp(dot(norm, -ray), 0.002, 1.0);
float fresnel = clamp(0.0204 + 0.9796 * pow(1.0 - ndv, 5.0), 0.022, 0.88);
color = mix(vec3(0.004, 0.095, 0.185), vec3(0.24, 0.56, 0.94), fresnel * 0.54);
}
out_color = vec4(pow(euv_ocean_aces(color), vec3(1.0 / 2.2)), 1.0);
}
"#;
pub const HLSL_FLUID_OCEAN_SHADER: &str = r#"cbuffer OceanUniforms : register(b0) {
float4 viewport_time_agitation;
float4 sun_dir_horizon;
float4 roll_cos_sin_pad;
};
struct OceanVertOut {
float4 pos : SV_Position;
float2 uv : TEXCOORD0;
};
OceanVertOut euv_ocean_vertex(uint vid : SV_VertexID) {
float2 p = float2((vid == 1) ? 3.0 : -1.0, (vid == 2) ? 3.0 : -1.0);
OceanVertOut o;
o.pos = float4(p, 0.0, 1.0);
o.uv = float2(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5);
return o;
}
float3 euv_ocean_aces(float3 hdr) {
float3 num = hdr * (2.51 * hdr + 0.03);
float3 den = hdr * (2.43 * hdr + 0.59) + 0.14;
return saturate(num / max(den, float3(0.0001, 0.0001, 0.0001)));
}
float4 euv_ocean_fragment(OceanVertOut i) : SV_Target {
float3 sun_dir = normalize(sun_dir_horizon.xyz);
float3 ray = normalize(float3((i.uv.x - 0.5) * 2.0, (sun_dir_horizon.w - i.uv.y) * 2.0, 1.62));
float3 col = (ray.y >= 0.0) ? lerp(float3(0.76, 0.88, 0.98), float3(0.09, 0.36, 0.96), smoothstep(0.0, 0.62, ray.y)) : float3(0.006, 0.12, 0.20);
return float4(pow(euv_ocean_aces(col), 1.0 / 2.2), 1.0);
}
"#;
pub const MSL_GPU_SCENE_SHADER: &str = r#"#include <metal_stdlib>
using namespace metal;
struct GpuOceanUniform {
float4 time_agit_hor_aspect;
float4 roll_boat_uv;
float4 sun_dir_wake;
float4 view_dims;
};
struct GpuOceanOut {
float4 pos [[position]];
float2 uv;
};
struct GpuBoatVert {
float4 pos_ndc;
float4 color;
};
struct GpuBoatOut {
float4 pos [[position]];
float4 color;
};
struct GpuWorld3dUniform {
float4x4 view_proj;
float4 camera_pos;
float4 sun_dir_fog;
float4 sun_color_ambient;
float4 sky_horizon_tod;
float4 sky_zenith_aspect;
};
struct GpuWorld3dVert {
float4 position;
float4 normal;
float4 color_submat;
};
struct GpuWorld3dInst {
float4x4 model;
float4 albedo_metallic;
float4 emissive_roughness;
};
struct GpuWorld3dOut {
float4 pos [[position]];
float3 world_pos;
float3 world_normal;
float4 base_metallic;
float4 emissive_rough;
float submat_mode;
float detail_mode;
};
static inline float3 euv_scene_aces(float3 hdr) {
float3 x = max(hdr, float3(0.0));
float luma = dot(x, float3(0.2126, 0.7152, 0.0722));
float sat_roll = 1.0 / (1.0 + luma * 0.14);
float3 agx_in = mix(float3(luma), x, 0.78 + 0.22 * sat_roll);
float3 num = agx_in * (2.51 * agx_in + 0.03);
float3 den = agx_in * (2.43 * agx_in + 0.59) + 0.14;
return pow(clamp(num / max(den, float3(0.0001)), float3(0.0), float3(1.0)), float3(1.0 / 2.2));
}
static inline float euv_hash_i2(int2 cell) {
uint n = as_type<uint>(cell.x) * 374761393u + as_type<uint>(cell.y) * 668265263u;
n = (n ^ (n >> 13u)) * 1274126177u;
n ^= n >> 16u;
return float(n & 0x00FFFFFFu) * (1.0 / 16777215.0);
}
static inline float euv_scene_hash(float2 p) {
return euv_hash_i2(int2(floor(p)));
}
static inline float euv_scene_noise(float2 p) {
float2 fl = floor(p);
float2 f = p - fl;
float2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
int2 i = int2(fl);
float a = euv_hash_i2(i);
float b = euv_hash_i2(i + int2(1, 0));
float c = euv_hash_i2(i + int2(0, 1));
float d = euv_hash_i2(i + int2(1, 1));
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}
static inline float euv_cloud_fbm(float2 p, int octs) {
float val = 0.0;
float amp = 0.54;
float2 q = p;
for (int i = 0; i < octs; ++i) {
val += euv_scene_noise(q) * amp;
q = float2(q.x * 1.92 - q.y * 0.58 + 3.1, q.x * 0.58 + q.y * 1.92 - 1.7);
amp *= 0.50;
}
return clamp(val, 0.0, 1.0);
}
static inline float3 euv_ocean_sky(float3 ray, float3 sun_dir, float sim_time, bool high_detail) {
float ry = max(ray.y, 0.0);
float sdot = clamp(dot(ray, sun_dir), 0.0, 1.0);
float sp2 = sdot * sdot;
float sp4 = sp2 * sp2;
float sp16 = sp4 * sp4 * sp4 * sp4;
float sp64 = sp16 * sp16 * sp16 * sp16;
float az = clamp(dot(normalize(float2(ray.x, ray.z)), normalize(float2(sun_dir.x, sun_dir.z))), 0.0, 1.0);
float az2 = az * az;
float sun_az_glow = az2 * az2;
float disk = smoothstep(0.99910, 0.99968, sdot);
float horiz_band = exp(-ry * 7.5);
float3 horiz_mist = float3(0.56, 0.70, 0.76)
+ float3(0.62, 0.34, 0.08) * (sun_az_glow * (0.45 + 0.55 * horiz_band))
+ float3(0.85, 0.58, 0.24) * sp16
+ float3(1.25, 0.96, 0.58) * sp64;
float3 mid_sky = high_detail ? float3(0.11, 0.30, 0.42) : float3(0.12, 0.32, 0.70);
float3 zenith = high_detail ? float3(0.042, 0.165, 0.275) : float3(0.050, 0.175, 0.52);
float sky_t1 = smoothstep(0.0, 0.22, ry);
float sky_t2 = smoothstep(0.14, 0.68, ry);
float3 base_sky = mix(mix(horiz_mist, mid_sky, sky_t1), zenith, sky_t2);
base_sky += float3(0.32, 0.22, 0.11) * (sp4 * (0.30 + 0.70 * horiz_band));
float horiz_clear = smoothstep(0.014, 0.115, ry);
float cloud_alpha = 0.0;
if (horiz_clear > 0.001) {
float t_shell = (sqrt(ry * ry + 0.08) - ry) * 25.0;
float2 base_c = ray.xz * (t_shell * 0.46) + float2(sim_time * 0.016, -sim_time * 0.009);
float warp_a = euv_scene_noise(base_c * 0.48 + float2(3.1, -1.4));
float warp_b = high_detail ? euv_scene_noise(base_c * 1.35 + float2(-2.3, 5.7)) : 0.5;
float2 c_uv = base_c + float2((warp_a - 0.5) * 0.72 + (warp_b - 0.5) * 0.24, (warp_a - 0.5) * 0.72 - (warp_b - 0.5) * 0.24);
float cloud_raw = euv_cloud_fbm(c_uv, high_detail ? 4 : 2);
float puff_a = high_detail ? (1.0 - abs(euv_scene_noise(c_uv * 2.4 + float2(8.4, -3.9)) * 2.0 - 1.0)) : 0.0;
float puff_b = high_detail ? (1.0 - abs(euv_scene_noise(c_uv * 5.2 + float2(1.9, -2.6)) * 2.0 - 1.0)) : 0.0;
float cloud_field = clamp(cloud_raw * 0.76 + puff_a * 0.16 + puff_b * 0.08, 0.0, 1.0);
float clearing = sun_az_glow * exp(-ry * 5.5) * 0.20;
float cloud_cov = smoothstep(0.50, 0.76, cloud_field - clearing);
float light_sample = high_detail ? euv_cloud_fbm(c_uv + sun_dir.xz * 0.22, 3) : (cloud_field * 0.92);
float sun_lit = clamp((cloud_field - light_sample) * 3.1 + 0.54, 0.0, 1.0);
float puff_top = smoothstep(0.48, 0.84, cloud_field);
float edge_thin = (1.0 - cloud_cov * 0.55) * smoothstep(0.04, 0.42, cloud_cov);
float silver_gold = (edge_thin * (0.34 + 0.90 * sp4) + (1.0 - cloud_cov) * sp16 * 0.35) * (0.40 + 0.60 * sun_lit);
float3 cloud_shadow = float3(0.32, 0.44, 0.58);
float3 cloud_bright = float3(1.22, 1.18, 1.08);
float3 cloud_col = mix(cloud_shadow, cloud_bright, clamp(sun_lit * 0.72 + puff_top * 0.28, 0.0, 1.0));
cloud_col += float3(1.18, 0.94, 0.62) * (silver_gold * 0.56);
float dist_aerial = smoothstep(0.015, 0.17, ry);
cloud_col = mix(horiz_mist, cloud_col, dist_aerial);
cloud_alpha = clamp(cloud_cov * 0.90 * horiz_clear, 0.0, 0.92);
base_sky = mix(base_sky, cloud_col, cloud_alpha);
}
if (high_detail) {
float sun_trans = 1.0 - cloud_alpha * 0.45;
float corona_inner = exp(-(1.0 - sdot) * 420.0);
float corona_outer = exp(-(1.0 - sdot) * 42.0);
base_sky += (float3(4.6, 3.95, 2.95) * disk + float3(1.35, 1.02, 0.60) * corona_inner + float3(0.32, 0.24, 0.13) * corona_outer) * sun_trans;
}
return base_sky;
}
vertex GpuOceanOut euv_scene_ocean_vert(uint vid [[vertex_id]]) {
float2 p = float2((vid == 1) ? 3.0 : -1.0, (vid == 2) ? 3.0 : -1.0);
GpuOceanOut out;
out.pos = float4(p, 0.0, 1.0);
out.uv = float2(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5);
return out;
}
fragment float4 euv_scene_ocean_frag(
GpuOceanOut in [[stage_in]],
constant GpuOceanUniform& u [[buffer(0)]],
texture2d<float> wake_tex [[texture(0)]]
) {
constexpr sampler s_lin(address::clamp_to_edge, filter::linear);
const float INV_TAU = 0.15915494;
const float TAU = 6.283185307;
float sim_time = u.time_agit_hor_aspect.x;
float agitation = max(u.time_agit_hor_aspect.y, 1.0);
float horizon_v = u.time_agit_hor_aspect.z;
float aspect = max(u.time_agit_hor_aspect.w, 0.25);
float roll_cos = u.roll_boat_uv.x;
float roll_sin = u.roll_boat_uv.y;
float2 boat_uv = u.roll_boat_uv.zw;
float3 sun_dir = normalize(u.sun_dir_wake.xyz);
float wake_active = u.sun_dir_wake.w;
float raw_dx = (in.uv.x - 0.5) * 2.0 * aspect;
float raw_dy = (horizon_v - in.uv.y) * 2.0;
float rx_u = raw_dx * roll_cos + raw_dy * roll_sin;
float ry_u = -raw_dx * roll_sin + raw_dy * roll_cos;
float3 ray_u = float3(rx_u, ry_u, 1.62);
float inv_rlen = rsqrt(dot(ray_u, ray_u));
float3 ray = ray_u * inv_rlen;
float inv_res_y = (u.view_dims.y > 0.5) ? u.view_dims.w : max(abs(dfdy(in.uv.y)), 1.0 / 16384.0);
float d_ry = (2.0 * inv_res_y) * inv_rlen * max(1.0 - ray.y * ray.y, 0.15);
float d_rx = (2.0 * inv_res_y) * inv_rlen;
float3 hdr;
if (ray.y >= 0.0) {
hdr = euv_ocean_sky(ray, sun_dir, sim_time, true);
} else {
float neg_ry_true = max(-ray.y, 1.0e-4);
float dist_true = 1.42 / neg_ry_true;
float dist = min(dist_true, 600.0);
float px_span_z = dist_true * (d_ry / neg_ry_true);
float px_span_x = dist_true * d_rx;
float px_span = max(px_span_z, px_span_x);
float2 wp0 = ray.xz * dist;
if (dist < 18.0) {
float p_fade = 1.0 - smoothstep(10.0, 18.0, dist);
float t0 = fract(sim_time * 0.84 * INV_TAU);
float ph0 = (fract(dot(wp0, float2(0.2419, 0.9703)) * 0.56 * INV_TAU) + t0) * TAU;
float h_p = 0.205 * agitation * (exp(-(1.0 - sin(ph0))) - 0.42) * p_fade;
dist = clamp((1.42 - h_p) / neg_ry_true, 0.5, 600.0);
wp0 = ray.xz * dist;
}
const float4 waves[8] = {
float4( 0.2419, 0.9703, 0.56, 0.205),
float4(-0.5592, 0.8290, 0.94, 0.145),
float4( 0.7986, 0.6018, 1.58, 0.092),
float4(-0.9455, 0.3256, 2.63, 0.056),
float4( 0.5299, 0.8480, 4.38, 0.034),
float4(-0.7880, -0.6157, 7.21, 0.021),
float4( 0.7314, -0.6820, 11.85, 0.013),
float4(-0.3746, 0.9272, 19.30, 0.0078)
};
const float speeds[8] = { 0.84, 1.12, 1.48, 1.92, 2.46, 3.08, 3.82, 4.68 };
float2 fwd_xz = normalize(ray.xz);
float2 right_xz = float2(fwd_xz.y, -fwd_xz.x);
float2 wp = wp0;
float h = 0.0;
float2 grad = float2(0.0);
float crest_acc = 0.0;
float normal_var = 0.0009;
for (int wi = 0; wi < 8; ++wi) {
float2 wdir = waves[wi].xy;
float freq = waves[wi].z;
float amp = waves[wi].w * agitation;
float w_span = max(max(abs(dot(wdir, fwd_xz)) * px_span_z, abs(dot(wdir, right_xz)) * px_span_x), px_span_z * 0.55);
float nyq = freq * w_span * 2.25;
float aa_w = (nyq < 4.5) ? exp(-0.5 * nyq * nyq) : 0.0;
float rms_s = waves[wi].w * min(agitation, 1.45) * freq;
normal_var += 0.10 * rms_s * rms_s * (1.0 - aa_w * aa_w);
if (aa_w > 0.0005) {
float t_ph = fract(sim_time * speeds[wi] * INV_TAU);
float s_ph = fract(dot(wp, wdir) * freq * INV_TAU);
float ph = (s_ph + t_ph) * TAU;
float cp;
float sp = sincos(ph, cp);
float steep_k = 0.42 + 0.58 * aa_w;
float sharp_e = exp(-(1.0 - sp) * steep_k);
h += amp * (sharp_e - 0.42) * aa_w;
float slope = amp * freq * steep_k * sharp_e * cp * aa_w;
grad += wdir * slope;
crest_acc += sharp_e * amp * aa_w;
wp += wdir * (cp * amp * 0.78 * aa_w);
}
}
float near_steep = 1.0 + 0.36 * exp(-dist * 0.082);
grad *= near_steep;
float cap_nyq1 = px_span * 14.5 * 2.25;
float cap_aa1 = (cap_nyq1 < 4.5) ? exp(-0.5 * cap_nyq1 * cap_nyq1) : 0.0;
normal_var += 0.0012 * (1.0 - cap_aa1 * cap_aa1) * min(agitation, 1.45);
if (cap_aa1 > 0.001) {
float p1a = (fract(dot(wp0, float2( 0.8572, 0.5150)) * 14.2 * INV_TAU) + fract(sim_time * 3.7 * INV_TAU)) * TAU;
float p1b = (fract(dot(wp0, float2(-0.4226, 0.9063)) * 18.7 * INV_TAU) + fract(sim_time * 4.4 * INV_TAU)) * TAU;
float p1c = (fract(dot(wp0, float2( 0.9613, -0.2756)) * 23.4 * INV_TAU) + fract(sim_time * 5.1 * INV_TAU)) * TAU;
float g1a = cos(p1a) * 0.044 * cap_aa1 * agitation;
float g1b = cos(p1b) * 0.036 * cap_aa1 * agitation;
float g1c = cos(p1c) * 0.028 * cap_aa1 * agitation;
grad += float2(0.8572, 0.5150) * g1a + float2(-0.4226, 0.9063) * g1b + float2(0.9613, -0.2756) * g1c;
}
float cap_nyq2 = px_span * 34.0 * 2.25;
float cap_aa2 = (cap_nyq2 < 4.5) ? exp(-0.5 * cap_nyq2 * cap_nyq2) : 0.0;
normal_var += 0.0006 * (1.0 - cap_aa2 * cap_aa2) * min(agitation, 1.45);
if (cap_aa2 > 0.001) {
float p2a = (fract(dot(wp0, float2(-0.7547, -0.6561)) * 31.8 * INV_TAU) + fract(sim_time * 6.2 * INV_TAU)) * TAU;
float p2b = (fract(dot(wp0, float2( 0.2924, -0.9563)) * 41.3 * INV_TAU) + fract(sim_time * 7.3 * INV_TAU)) * TAU;
float g2a = cos(p2a) * 0.022 * cap_aa2 * agitation;
float g2b = cos(p2b) * 0.016 * cap_aa2 * agitation;
grad += float2(-0.7547, -0.6561) * g2a + float2(0.2924, -0.9563) * g2b;
}
normal_var = clamp(normal_var + min(px_span * 0.006, 0.016), 0.0005, 0.036);
float wake_foam = 0.0;
if (wake_active > 0.001) {
float2 wake_uv = clamp(in.uv, float2(0.5 / 96.0, 0.5 / 72.0), float2(1.0 - 0.5 / 96.0, 1.0 - 0.5 / 72.0));
float4 wk = wake_tex.sample(s_lin, wake_uv);
float2 edge_d = min(in.uv, float2(1.0) - in.uv);
float edge_win = smoothstep(0.0, 0.045, edge_d.x) * smoothstep(0.0, 0.045, edge_d.y);
float w_gain = clamp(wake_active, 0.0, 1.0) * edge_win;
float2 flow = clamp((wk.rg - float2(128.0 / 255.0)) * 4.0 * 0.22, float2(-0.20), float2(0.20)) * w_gain;
grad += flow;
wake_foam = wk.b * w_gain;
}
float2 raw_bd = float2((in.uv.x - boat_uv.x) * aspect, in.uv.y - boat_uv.y);
float2 rot_bd = float2(raw_bd.x * roll_cos - raw_bd.y * roll_sin, raw_bd.x * roll_sin + raw_bd.y * roll_cos);
float2 boat_local = float2(rot_bd.x / 0.145, rot_bd.y / 0.036);
float boat_ring_d2 = dot(boat_local, boat_local);
if (boat_ring_d2 > 0.30 && boat_ring_d2 < 12.8) {
float r_hull = sqrt(boat_ring_d2);
float rip_env = exp(-max(r_hull - 0.85, 0.0) * 1.08) * smoothstep(0.55, 0.92, r_hull);
float rip_nyq = px_span * 16.5 * 1.8;
float rip_aa = (rip_nyq < 4.5) ? exp(-0.5 * rip_nyq * rip_nyq) : 0.0;
float rip_ph = (fract(r_hull * 16.5 * INV_TAU) - fract(sim_time * 4.2 * INV_TAU)) * TAU;
float rip_wave = cos(rip_ph) * 0.34 * rip_env * rip_aa;
float inv_rh = 1.0 / max(r_hull, 0.1);
grad += float2(boat_local.x * inv_rh * rip_wave, boat_local.y * inv_rh * rip_wave * 1.38);
}
float3 norm = normalize(float3(-grad.x, 1.0, -grad.y));
float3 dndx = dfdx(norm);
float3 dndy = dfdy(norm);
float dn_sq = dot(dndx, dndx) + dot(dndy, dndy);
float screen_nvar = (neg_ry_true > d_ry * 2.5 && dn_sq < 64.0)
? min(dn_sq * 0.48, 0.16) * smoothstep(d_ry * 2.5, d_ry * 5.0, neg_ry_true)
: 0.0;
float eff_nvar = clamp(normal_var + screen_nvar, 0.0012, 0.18);
float3 view_dir = -ray;
float ndv = clamp(dot(norm, view_dir), 0.005, 1.0);
float om_nv = 1.0 - ndv;
float om_nv2 = om_nv * om_nv;
float fresnel = clamp(0.0204 + (0.94 - min(eff_nvar * 1.6, 0.34)) * (om_nv2 * om_nv2 * om_nv), 0.022, 0.90);
float3 refl_dir = reflect(ray, norm);
refl_dir.y = max(refl_dir.y, 0.008);
float3 sky_refl = euv_ocean_sky(normalize(refl_dir), sun_dir, sim_time, false);
float3 half_vec = normalize(view_dir + sun_dir);
float ndl = max(dot(norm, sun_dir), 0.0);
float ndh = max(dot(norm, half_vec), 0.0);
float vdh = clamp(dot(view_dir, half_vec), 0.0, 1.0);
float om_vh = 1.0 - vdh;
float om_vh2 = om_vh * om_vh;
float fresnel_h = 0.0204 + 0.9796 * (om_vh2 * om_vh2 * om_vh);
float a1_sq = 0.0012 + eff_nvar * 0.56;
float d1 = ndh * ndh * (a1_sq - 1.0) + 1.0;
float ndf1 = a1_sq / max(3.14159265 * d1 * d1, 1.0e-5);
float k1 = sqrt(a1_sq) * 0.5;
float vis1 = 0.25 / max((ndv * (1.0 - k1) + k1) * (ndl * (1.0 - k1) + k1), 0.014);
float a2_sq = 0.0068 + eff_nvar * 0.72;
float d2 = ndh * ndh * (a2_sq - 1.0) + 1.0;
float ndf2 = a2_sq / max(3.14159265 * d2 * d2, 1.0e-5);
float k2 = sqrt(a2_sq) * 0.5;
float vis2 = 0.25 / max((ndv * (1.0 - k2) + k2) * (ndl * (1.0 - k2) + k2), 0.034);
float core_e = min(ndf1 * vis1 * ndl * fresnel_h, 11.0);
float sheen_e = min(ndf2 * vis2 * ndl * fresnel_h, 2.0);
float3 spec = float3(1.52, 1.38, 1.12) * (core_e * 0.76) + float3(1.28, 0.96, 0.60) * (sheen_e * 0.20);
float sss_dot = clamp(dot(-view_dir, sun_dir), 0.0, 1.0);
float sss = clamp(h * 2.35 + 0.28, 0.0, 1.0) * exp(-dist * 0.045) * (0.48 + 0.52 * (sss_dot * sss_dot * sss_dot));
float3 deep_body = float3(0.004, 0.145, 0.54) + float3(0.018, 0.52, 0.98) * sss;
float refl_weight = clamp(fresnel * 0.54 + 0.035, 0.035, 0.72);
hdr = mix(deep_body, sky_refl, refl_weight) + spec;
if (rot_bd.y > -0.01 && rot_bd.y < 0.24 && abs(rot_bd.x) < 0.22) {
float ripple = sin(rot_bd.y * 95.0 - sim_time * 4.5 + grad.x * 6.0) * 0.012;
float rx_b = abs(rot_bd.x + ripple);
float y_fade = smoothstep(-0.01, 0.032, rot_bd.y) * smoothstep(0.24, 0.10, rot_bd.y);
float tri_mask = smoothstep(0.14, 0.02, rx_b + max(rot_bd.y, 0.0) * 0.55) * y_fade;
hdr = mix(hdr, float3(0.55, 0.52, 0.48), tri_mask * 0.32);
}
float crest_norm = crest_acc / max(agitation, 1.0);
float steep_foam = smoothstep(0.54, 0.74, crest_norm) * clamp(agitation - 1.08, 0.0, 1.0);
float total_foam = clamp(steep_foam * 0.45 + wake_foam * 0.28, 0.0, 0.54);
hdr = mix(hdr, float3(0.78, 0.90, 0.96), total_foam);
if (boat_ring_d2 < 4.5) {
if (boat_ring_d2 < 1.12) {
float contact_ao = (1.0 - smoothstep(0.18, 1.06, boat_ring_d2)) * 0.44;
hdr *= float3(1.0 - contact_ao, 1.0 - contact_ao * 0.82, 1.0 - contact_ao * 0.72);
}
float foam_ny = boat_local.y - 0.16;
float foam_d2 = boat_local.x * boat_local.x * 1.16 + foam_ny * foam_ny * 1.08;
float rim_band = smoothstep(0.42, 0.82, foam_d2) * (1.0 - smoothstep(0.88, 1.54, foam_d2)) * smoothstep(-0.45, 0.24, boat_local.y);
float aft_wake = smoothstep(0.22, 0.82, boat_local.x) * (1.0 - smoothstep(0.88, 1.62, boat_local.x)) * (1.0 - smoothstep(0.18, 1.20, abs(boat_local.y - 0.26))) * 0.46;
float collar_mask = clamp(rim_band + aft_wake, 0.0, 1.0);
if (collar_mask > 0.02) {
float lacy_a = euv_scene_noise(wp0 * 8.2 + float2(2.3, -1.7));
float lacy_b = euv_scene_noise(wp0 * 21.0 + float2(-sim_time * 0.85, 4.1));
float flecks = euv_scene_noise(wp0 * 42.0 + float2(7.1, -sim_time * 1.35));
float foam_pat = smoothstep(0.46, 0.78, lacy_a * 0.42 + lacy_b * 0.36 + flecks * 0.22);
float spray_dots = smoothstep(0.74, 0.88, flecks) * rim_band * 0.72 * smoothstep(0.08, 0.015, px_span);
float hull_foam = clamp(collar_mask * foam_pat * 0.78 + spray_dots, 0.0, 0.86);
hdr = mix(hdr, float3(0.92, 0.97, 1.0), hull_foam);
}
}
float horiz_blend = exp(-neg_ry_true * 56.0);
float dist_haze = 1.0 - exp(-dist * 0.0020);
float pixel_hor_aa = 1.0 - smoothstep(0.0, d_ry * 1.75, neg_ry_true);
float atm_mix = clamp(max(max(horiz_blend, dist_haze), pixel_hor_aa), 0.0, 1.0);
float atm_w = clamp((atm_mix - 0.002) * (1.0 / 0.998), 0.0, 1.0);
if (atm_w > 0.0) {
float3 fog_col = euv_ocean_sky(normalize(float3(ray.x, max(0.0005, d_ry * 0.5), ray.z)), sun_dir, sim_time, false);
hdr = mix(hdr, fog_col, atm_w);
}
}
return float4(euv_scene_aces(hdr), 1.0);
}
vertex GpuBoatOut euv_scene_boat_vert(
uint vid [[vertex_id]],
device const GpuBoatVert* verts [[buffer(0)]]
) {
GpuBoatVert v = verts[vid];
GpuBoatOut out;
out.pos = float4(v.pos_ndc.xy, 0.0, 1.0);
out.color = v.color;
return out;
}
fragment float4 euv_scene_boat_frag(GpuBoatOut in [[stage_in]]) {
return in.color;
}
vertex GpuOceanOut euv_scene_3d_sky_vert(uint vid [[vertex_id]]) {
float2 p = float2((vid == 1) ? 3.0 : -1.0, (vid == 2) ? 3.0 : -1.0);
GpuOceanOut out;
out.pos = float4(p, 0.9999, 1.0);
out.uv = float2(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5);
return out;
}
static inline float euv_box_pulse(float x, float a, float b, float fw) {
float w = b - a;
float f = max(fw, 1.0e-4);
float x0 = x - 0.5 * f;
float x1 = x + 0.5 * f;
float i0 = floor(x0) * w + clamp(fract(x0) - a, 0.0, w);
float i1 = floor(x1) * w + clamp(fract(x1) - a, 0.0, w);
return clamp((i1 - i0) / f, 0.0, 1.0);
}
static inline float euv_box_band(float x, float lo, float hi, float fw) {
float f = max(fw, 1.0e-4);
float x0 = x - 0.5 * f;
float x1 = x + 0.5 * f;
return clamp((min(x1, hi) - max(x0, lo)) / f, 0.0, 1.0);
}
static inline float euv_box_step(float x, float edge, float fw) {
float f = max(fw, 1.0e-4);
return clamp((x - edge) / f + 0.5, 0.0, 1.0);
}
static inline float3 euv_city_env_radiance(
float3 origin,
float3 refl_dir,
float3 sun_dir,
float3 sky_hor,
float3 sky_zen,
float3 sun_col,
float roughness
) {
float ry = clamp(refl_dir.y, 0.0, 1.0);
float3 env = mix(sky_hor, sky_zen, smoothstep(0.0, 0.72, ry));
float r_sun = clamp(dot(refl_dir, sun_dir), 0.0, 1.0);
float rs2 = r_sun * r_sun;
float rs4 = rs2 * rs2;
float rs16 = rs4 * rs4 * rs4 * rs4;
float sun_lobe = mix(rs16 * rs16 * rs16, rs4, clamp(roughness * 1.4, 0.0, 1.0));
env += sun_col * (sun_lobe * (1.85 - roughness * 1.25));
float ax = abs(refl_dir.x);
if (ax > 0.05 && refl_dir.y > -0.25) {
float wall_x = (refl_dir.x >= 0.0) ? 15.2 : -15.2;
float t_hit = (wall_x - origin.x) / refl_dir.x;
if (t_hit > 0.5 && t_hit < 110.0) {
float hit_y = origin.y + refl_dir.y * t_hit;
float hit_z = origin.z + refl_dir.z * t_hit;
if (hit_y > 0.15 && hit_y < 46.0) {
float rough_att = 1.0 / (1.0 + roughness * 8.5);
float dist_att = exp(-t_hit * 0.016);
float3 facade_col = sky_hor * 0.24 + float3(0.025, 0.030, 0.042);
float refl_blur = clamp(roughness * 1.8 + t_hit * 0.012, 0.08, 1.25);
if (hit_y < 3.45) {
float su_s = hit_z * 0.26;
float sh = euv_scene_hash(float2(floor(su_s), 7.0));
float3 shop_glow = (sh < 0.40) ? float3(1.22, 0.80, 0.36) : ((sh < 0.62) ? float3(0.30, 0.92, 1.24) : ((sh < 0.80) ? float3(1.16, 0.34, 0.72) : float3(0.0)));
float3 mean_shop = float3(0.76, 0.58, 0.54);
float shop_coh = 1.0 - smoothstep(0.22, 0.80, refl_blur);
facade_col += mix(mean_shop, shop_glow, shop_coh) * (0.72 * rough_att);
} else {
float su = hit_z * 0.48;
float sy = hit_y * 0.33;
float pane = euv_box_pulse(su, 0.14, 0.86, refl_blur) * euv_box_pulse(sy, 0.18, 0.84, refl_blur);
float ch = euv_scene_hash(float2(floor(su), floor(sy)));
float3 win_glow = (ch < 0.22) ? float3(1.28, 0.88, 0.44) : ((ch < 0.33) ? float3(0.30, 0.90, 1.28) : ((ch < 0.42) ? float3(0.98, 0.96, 0.90) : ((ch < 0.50) ? float3(1.10, 0.36, 0.74) : float3(0.0))));
float3 mean_win = float3(0.49, 0.40, 0.36);
float win_coh = 1.0 - smoothstep(0.20, 0.75, refl_blur);
facade_col += mix(mean_win, win_glow, win_coh) * (pane * (0.38 + 0.56 * rough_att));
}
env = mix(env, facade_col, clamp((0.42 + 0.48 * rough_att) * dist_att, 0.0, 0.90));
}
}
}
if (refl_dir.y > 0.02 && origin.y < 6.6) {
float t_lamp = (6.8 - origin.y) / refl_dir.y;
if (t_lamp > 0.5 && t_lamp < 95.0) {
float lx = origin.x + refl_dir.x * t_lamp;
float lz = origin.z + refl_dir.z * t_lamp;
float dx_l = abs(abs(lx) - 10.4);
float z_idx = floor((lz + 42.0) / 24.0 + 0.5);
float dz_l = abs(lz - (z_idx * 24.0 - 42.0));
float spread = 0.72 + roughness * 4.4;
float lamp_glow = exp(-(dx_l * dx_l + dz_l * dz_l * 0.32) / (spread * spread)) * exp(-t_lamp * 0.020);
float lp_h = fract(abs(z_idx) * 0.25);
float3 lamp_c = (lp_h < 0.25) ? float3(1.48, 0.96, 0.42) : ((lp_h < 0.50) ? float3(0.45, 1.15, 1.50) : ((lp_h < 0.75) ? float3(1.40, 0.58, 0.90) : float3(1.44, 1.06, 0.58)));
env += lamp_c * (lamp_glow * (1.28 - roughness * 0.72));
}
}
return env;
}
fragment float4 euv_scene_3d_sky_frag(
GpuOceanOut in [[stage_in]],
constant GpuWorld3dUniform& u [[buffer(0)]]
) {
float2 ndc = float2(in.uv.x * 2.0 - 1.0, 1.0 - in.uv.y * 2.0);
float3 r0 = float3(u.view_proj[0].x, u.view_proj[1].x, u.view_proj[2].x);
float3 r1 = float3(u.view_proj[0].y, u.view_proj[1].y, u.view_proj[2].y);
float3 r3 = float3(u.view_proj[0].w, u.view_proj[1].w, u.view_proj[2].w);
float3 c0 = cross(r1, r3);
float3 c1 = cross(r3, r0);
float3 c2 = cross(r0, r1);
float det = dot(r0, c0);
float sgn = (det < 0.0) ? -1.0 : 1.0;
float3 world_ray = normalize((c0 * ndc.x + c1 * ndc.y + c2) * sgn);
float3 sun_dir = normalize(u.sun_dir_fog.xyz);
float ry = max(world_ray.y, 0.0);
float sky_t = smoothstep(0.0, 0.62, pow(ry, 0.72));
float3 col = mix(u.sky_horizon_tod.rgb, u.sky_zenith_aspect.rgb, sky_t);
if (world_ray.y < 0.0) {
col = mix(u.sky_horizon_tod.rgb, u.sky_horizon_tod.rgb * 0.52, smoothstep(0.0, 0.35, -world_ray.y));
}
float sdot = clamp(dot(world_ray, sun_dir), 0.0, 1.0);
float sp2 = sdot * sdot;
float sp4 = sp2 * sp2;
float sp8 = sp4 * sp4;
float horiz_band = exp(-ry * 6.5);
float sun_aureole = exp(-(1.0 - sdot) * 28.0);
float sun_corona = exp(-(1.0 - sdot) * 420.0);
float sun_disk = smoothstep(0.99925, 0.99975, sdot);
float above_hor = smoothstep(-0.02, 0.03, world_ray.y);
col += u.sun_color_ambient.rgb * (sp8 * 0.36 * horiz_band + sun_aureole * 0.42 + (sun_corona * 0.95 + sun_disk * 3.4) * above_hor);
if (ry > 0.015) {
float2 dome_uv = world_ray.xz / (ry + 0.16);
float2 cloud_p = dome_uv * 0.85 + float2(u.sky_horizon_tod.w * 0.04, -u.sky_horizon_tod.w * 0.02);
float wisp_n = euv_scene_noise(cloud_p * 1.45) * 0.65 + euv_scene_noise(cloud_p * 3.10 + float2(4.2, -2.7)) * 0.35;
float wisp_mask = smoothstep(0.42, 0.78, wisp_n) * smoothstep(0.015, 0.16, ry) * (1.0 - smoothstep(0.55, 0.92, ry));
float3 wisp_col = u.sky_horizon_tod.rgb * 1.15 + u.sun_color_ambient.rgb * (0.14 + 0.34 * sp4);
col = mix(col, wisp_col, wisp_mask * 0.28);
}
return float4(euv_scene_aces(col * u.camera_pos.w), 1.0);
}
vertex GpuWorld3dOut euv_scene_3d_mesh_vert(
uint vid [[vertex_id]],
uint iid [[instance_id]],
constant GpuWorld3dUniform& u [[buffer(0)]],
device const GpuWorld3dVert* verts [[buffer(1)]],
device const GpuWorld3dInst* insts [[buffer(2)]]
) {
GpuWorld3dVert v = verts[vid];
GpuWorld3dInst inst = insts[iid];
float detail_mode = inst.model[3].w;
float4x4 m = inst.model;
m[3].w = 1.0;
float4 world_p = m * float4(v.position.xyz, 1.0);
float4 clip_p = u.view_proj * world_p;
clip_p.z = clip_p.z * 0.5 + clip_p.w * 0.5;
float3 c0 = m[0].xyz;
float3 c1 = m[1].xyz;
float3 c2 = m[2].xyz;
float3x3 cof = float3x3(cross(c1, c2), cross(c2, c0), cross(c0, c1));
float3 wn = normalize(cof * v.normal.xyz);
GpuWorld3dOut out;
out.pos = clip_p;
out.world_pos = world_p.xyz;
out.world_normal = wn;
if (v.color_submat.w > 0.5) {
out.base_metallic = float4(v.color_submat.rgb, inst.albedo_metallic.w);
} else {
out.base_metallic = float4(inst.albedo_metallic.rgb * v.color_submat.rgb, inst.albedo_metallic.w);
}
out.emissive_rough = inst.emissive_roughness;
out.submat_mode = v.color_submat.w;
out.detail_mode = detail_mode;
return out;
}
fragment float4 euv_scene_3d_mesh_frag(
GpuWorld3dOut in [[stage_in]],
constant GpuWorld3dUniform& u [[buffer(0)]]
) {
float3 norm = normalize(in.world_normal);
float3 view_dir = normalize(u.camera_pos.xyz - in.world_pos);
float3 sun_dir = normalize(u.sun_dir_fog.xyz);
float dist = length(u.camera_pos.xyz - in.world_pos);
float3 fw_p = fwidth(in.world_pos);
float fw_xz = length(fw_p.xz);
float3 base_col = in.base_metallic.rgb;
float metallic = clamp(in.base_metallic.w, 0.0, 1.0);
float roughness = clamp(in.emissive_rough.w, 0.05, 1.0);
float3 emissive = (in.submat_mode > 1.5) ? base_col * 1.55 : in.emissive_rough.rgb;
float env_boost = 0.95;
float clearcoat = (in.detail_mode < 0.5 && in.submat_mode < 1.5 && (metallic > 0.22 || roughness < 0.36)) ? 0.85 : 0.0;
float surface_ao = mix(0.56, 1.0, smoothstep(0.0, 1.85, max(in.world_pos.y, 0.0)));
float3 local_lamp_light = float3(0.0);
if (in.detail_mode > 0.5 && in.detail_mode < 1.5 && norm.y > 0.82) {
float wpx = in.world_pos.x;
float wpz = in.world_pos.z;
float abs_x = abs(wpx);
float fw_x = max(fw_p.x, 0.015);
float fw_z = max(fw_p.z, 0.015);
float curb_w = euv_box_step(abs_x, 9.9, fw_x);
float walk_w = euv_box_step(abs_x, 10.6, fw_x);
float micro_fade = (1.0 - smoothstep(14.0, 48.0, dist)) * (1.0 - smoothstep(0.06, 0.22, max(fw_x, fw_z)));
float grain_n = (micro_fade > 0.005) ? (euv_scene_hash(floor(float2(wpx * 4.3, wpz * 4.3))) - 0.5) : 0.0;
float om_curb = 1.0 - curb_w;
float inner_lin = 1.0 - clamp(abs(abs_x - 3.65) * 0.85, 0.0, 1.0);
float outer_lin = 1.0 - clamp(abs(abs_x - 6.85) * 0.95, 0.0, 1.0);
float tire_wear = clamp(inner_lin * inner_lin + outer_lin * outer_lin, 0.0, 1.0) * om_curb;
float gutter_band = (1.0 - clamp(abs(abs_x - 9.75) * 2.8, 0.0, 1.0)) * om_curb;
float puddle_fade = 1.0 - smoothstep(52.0, 135.0, dist);
float p_coarse = euv_scene_noise(float2(wpx * 0.14 + 3.1, wpz * 0.08 - 1.7));
float p_fine = euv_scene_noise(float2(wpx * 0.38 - 5.4, wpz * 0.24 + 2.9));
float center_crown = (1.0 - clamp(abs_x * 0.65, 0.0, 1.0)) * om_curb;
float puddle_raw = p_coarse * 0.66 + p_fine * 0.34 + tire_wear * 0.14 + gutter_band * 0.16 - center_crown * 0.24;
float puddle = smoothstep(0.42, 0.88, puddle_raw) * om_curb * puddle_fade;
float tarmac_scale = (1.0 + grain_n * 0.24 * micro_fade * (1.0 - puddle)) * (1.0 - 0.14 * tire_wear) * (1.0 - 0.40 * puddle) * (1.0 - 0.30 * gutter_band);
float3 road_col = base_col * tarmac_scale;
float yellow_w = euv_box_band(abs_x, 0.135, 0.305, fw_x) * om_curb;
if (yellow_w > 0.005) {
float pv = (1.0 - 0.14 * puddle) * (0.92 + grain_n * 0.14 * micro_fade);
road_col = mix(road_col, float3(0.92, 0.65, 0.10) * pv, yellow_w * 0.95);
}
float dash_on = euv_box_pulse(wpz * 0.125, 0.0, 0.42, fw_z * 0.125);
float lane_w = euv_box_band(abs_x, 4.565, 4.735, fw_x) * dash_on * om_curb;
float shoulder_w = euv_box_band(abs_x, 8.85, 9.05, fw_x) * om_curb;
float cross_z = euv_box_pulse((wpz + 18.0) * 0.025, 0.455, 0.545, fw_z * 0.025);
float cross_x_mask = euv_box_band(abs_x, 0.55, 8.40, fw_x);
float cross_bars = euv_box_pulse(wpx * 0.85, 0.0, 0.50, fw_x * 0.85);
float cross_w = cross_z * cross_x_mask * cross_bars * 0.88 * om_curb;
float white_w = max(max(shoulder_w, lane_w), cross_w);
if (white_w > 0.005) {
float pv = (1.0 - 0.16 * puddle) * (0.90 + grain_n * 0.12 * micro_fade);
road_col = mix(road_col, float3(0.82, 0.85, 0.90) * pv, white_w * 0.92);
}
float3 curb_col = float3(0.36, 0.38, 0.42) * (1.0 + grain_n * 0.10 * micro_fade);
float seam_u = euv_box_pulse(wpx * 0.45, 0.0, 0.045, fw_x * 0.45);
float seam_v = euv_box_pulse(wpz * 0.45, 0.0, 0.045, fw_z * 0.45);
float tile_seam = mix(1.0, 0.72, clamp(seam_u + seam_v - seam_u * seam_v, 0.0, 1.0));
float3 walk_col = float3(0.24, 0.26, 0.30) * tile_seam * (1.0 + grain_n * 0.10 * micro_fade);
base_col = mix(mix(road_col, curb_col, curb_w), walk_col, walk_w);
roughness = mix(mix(roughness, 0.045, puddle), 0.76, walk_w);
env_boost = mix(0.95, 2.25, puddle);
clearcoat = puddle * 0.65;
surface_ao = mix(1.0, 0.66, smoothstep(9.4, 14.0, abs_x));
float z_idx = floor((wpz + 42.0) / 24.0 + 0.5);
float z_lamp = z_idx * 24.0 - 42.0;
float x_lamp = (wpx >= 0.0) ? 10.4 : -10.4;
float3 to_lamp = float3(x_lamp - wpx, 6.8, z_lamp - wpz);
float d2_lamp = dot(to_lamp, to_lamp);
float lamp_att = 1.0 / (1.0 + d2_lamp * 0.018);
float3 lamp_dir = to_lamp * rsqrt(max(d2_lamp, 0.1));
float3 lamp_h = normalize(view_dir + lamp_dir);
float l_ndh = max(dot(norm, lamp_h), 0.0);
float l_a2 = max(roughness * roughness, 0.010);
float l_den = l_ndh * l_ndh * (l_a2 - 1.0) + 1.0;
float l_spec = min(l_a2 / max(3.14159265 * l_den * l_den, 0.0002), 14.0);
float lp_h = fract(abs(z_idx) * 0.25);
float3 lamp_col = (lp_h < 0.25) ? float3(1.15, 0.78, 0.34) : ((lp_h < 0.50) ? float3(0.36, 0.88, 1.18) : ((lp_h < 0.75) ? float3(1.10, 0.44, 0.72) : float3(1.12, 0.84, 0.46)));
local_lamp_light = lamp_col * lamp_att * (base_col * 0.52 + float3(0.08 + 0.32 * puddle) * l_spec);
} else if (in.detail_mode > 1.5 && in.detail_mode < 2.5 && abs(norm.y) < 0.35 && in.submat_mode < 0.5) {
float u_coord = (abs(norm.x) > abs(norm.z)) ? in.world_pos.z : in.world_pos.x;
float fw_u_w = (abs(norm.x) > abs(norm.z)) ? fw_p.z : fw_p.x;
float world_y = in.world_pos.y;
float fw_y_w = fw_p.y;
float dist_fade = 1.0 - smoothstep(130.0, 320.0, dist);
surface_ao = mix(0.54, 1.0, smoothstep(0.0, 4.2, max(world_y, 0.0)));
if (world_y < 3.45) {
float su_s = u_coord * 0.26;
float fw_su_s = max(fw_u_w * 0.26, 0.005);
float fy_s = clamp(world_y / 3.45, 0.0, 1.0);
float fw_fy_s = max(fw_y_w / 3.45, 0.005);
float pane_w = euv_box_pulse(su_s, 0.11, 0.89, fw_su_s) * euv_box_band(fy_s, 0.18, 0.89, fw_fy_s) * dist_fade;
float sh = euv_scene_hash(float2(floor(su_s), 7.0));
float3 shop_glow = (sh < 0.40) ? float3(1.24, 0.82, 0.38) : ((sh < 0.62) ? float3(0.30, 0.92, 1.24) : ((sh < 0.80) ? float3(1.18, 0.34, 0.72) : float3(0.0)));
float shop_coh = 1.0 - smoothstep(0.28, 0.78, fw_su_s);
float3 shop_eff = mix(float3(0.77, 0.59, 0.55), shop_glow, shop_coh);
base_col = mix(base_col * 0.64, base_col * 0.40, pane_w);
emissive += shop_eff * (pane_w * (0.58 + 0.56 * (1.0 - fy_s)) * 0.96);
roughness = mix(roughness, 0.10, pane_w);
env_boost = mix(0.95, 1.65, pane_w);
} else {
float su = u_coord * 0.48;
float sy = world_y * 0.33;
float fw_su = max(fw_u_w * 0.48, 0.005);
float fw_sy = max(fw_y_w * 0.33, 0.005);
float fy_win = fract(sy);
float pane_u = euv_box_pulse(su, 0.14, 0.86, fw_su);
float pane_v = euv_box_pulse(sy, 0.18, 0.84, fw_sy);
float pane_w = clamp(pane_u * pane_v * dist_fade, 0.0, 1.0);
float spandrel = mix(0.70, 0.84, euv_box_pulse(sy, 0.14, 0.88, fw_sy));
float3 wall_base = base_col * spandrel;
float ch = euv_scene_hash(float2(floor(su), floor(sy)));
float room_lvl = 0.70 + fract(ch * 17.3) * 0.46;
float blind_grad = clamp(0.48 + 0.66 * (1.0 - fy_win), 0.38, 1.14);
float cell_detail = 1.0 - smoothstep(0.22, 0.72, max(fw_su, fw_sy));
float3 cell_em = float3(0.0);
float cell_glass_mul = clamp(0.34 + 0.22 * fy_win, 0.30, 0.60);
if (ch < 0.22) {
cell_glass_mul = 0.86;
cell_em = float3(1.28, 0.88, 0.44) * (room_lvl * blind_grad);
} else if (ch < 0.33) {
cell_glass_mul = 0.84;
cell_em = float3(0.30, 0.90, 1.28) * (room_lvl * blind_grad);
} else if (ch < 0.42) {
cell_glass_mul = 0.88;
cell_em = float3(0.98, 0.96, 0.90) * (room_lvl * blind_grad * 0.84);
} else if (ch < 0.50) {
cell_glass_mul = 0.84;
cell_em = float3(1.10, 0.36, 0.74) * (room_lvl * blind_grad * 0.88);
}
float3 mean_em = float3(0.36, 0.29, 0.26);
base_col = mix(wall_base, base_col * mix(0.65, cell_glass_mul, cell_detail), pane_w);
emissive += mix(mean_em, cell_em, cell_detail) * pane_w;
roughness = mix(roughness, mix(0.24, 0.08, cell_detail), pane_w);
env_boost = mix(0.90, 1.65, pane_w);
}
} else if (in.detail_mode > 2.5 && norm.y > 0.80) {
float2 wp = in.world_pos.xz;
float aa_w = 1.0 / (1.0 + fw_xz * 0.85);
float w_a = cos(wp.x * 0.42 + wp.y * 0.64 + u.sky_horizon_tod.w * 2.4) * 0.08 * aa_w;
float w_b = cos(-wp.x * 0.78 + wp.y * 0.52 + u.sky_horizon_tod.w * 3.1) * 0.06 * aa_w;
norm = normalize(float3(w_a - w_b, 1.0, w_a + w_b));
base_col = float3(0.015, 0.095, 0.145);
roughness = 0.06;
metallic = 0.02;
env_boost = 1.85;
surface_ao = 1.0;
}
float3 dndx = dfdx(norm);
float3 dndy = dfdy(norm);
float norm_var = clamp(dot(dndx, dndx) + dot(dndy, dndy), 0.0, 0.50);
float rough_aa = sqrt(clamp(roughness * roughness + min(norm_var * 0.50, 0.18), 0.0025, 1.0));
float3 half_vec = normalize(view_dir + sun_dir);
float ndl = max(dot(norm, sun_dir), 0.0);
float ndv = max(dot(norm, view_dir), 0.002);
float ndh = max(dot(norm, half_vec), 0.0);
float hdv = max(dot(half_vec, view_dir), 0.0);
float om_hdv = 1.0 - hdv;
float om_hdv2 = om_hdv * om_hdv;
float fresnel_h = om_hdv2 * om_hdv2 * om_hdv;
float om_ndv = 1.0 - ndv;
float om_ndv2 = om_ndv * om_ndv;
float fresnel_v = om_ndv2 * om_ndv2 * om_ndv;
float r2 = rough_aa * rough_aa;
float a2 = max(r2 * r2, 0.0004);
float d_den = ndh * ndh * (a2 - 1.0) + 1.0;
float ndf = a2 / max(3.14159265 * d_den * d_den, 0.0001);
float3 f0 = mix(float3(0.04), base_col, metallic);
float3 fresnel = f0 + (float3(1.0) - f0) * fresnel_h;
float k_g = (rough_aa + 1.0);
k_g = (k_g * k_g) * 0.125;
float g_v = ndv / (ndv * (1.0 - k_g) + k_g);
float g_l = ndl / (ndl * (1.0 - k_g) + k_g);
float3 spec = (ndf * g_v * g_l * fresnel) / max(4.0 * ndv * ndl, 0.001);
if (clearcoat > 0.01) {
float cc_a2 = clamp(0.0045 + norm_var * 0.45, 0.0045, 0.25);
float cc_den = ndh * ndh * (cc_a2 - 1.0) + 1.0;
float cc_ndf = min(cc_a2 / max(3.14159265 * cc_den * cc_den, 0.0001), 24.0);
float cc_f = 0.04 + 0.96 * fresnel_h;
spec += float3(cc_ndf * cc_f * 0.25 * clearcoat);
}
float3 kd = (float3(1.0) - fresnel) * (1.0 - metallic);
float contact_shadow = mix(0.68, 1.0, surface_ao);
float3 direct = (kd * base_col / 3.14159265 + spec) * u.sun_color_ambient.rgb * (ndl * 1.48 * contact_shadow);
float sky_w = norm.y * 0.5 + 0.5;
float side_w = 1.0 - abs(norm.y);
float3 upper_gi = u.sky_zenith_aspect.rgb * 0.92 + u.sky_horizon_tod.rgb * 0.38;
float3 lower_gi = u.sky_horizon_tod.rgb * 0.28 + float3(0.07, 0.06, 0.08);
float3 city_bounce = (float3(0.20, 0.15, 0.14) + u.sky_horizon_tod.rgb * 0.22) * side_w;
float3 hemi = mix(lower_gi, upper_gi, sky_w) + city_bounce * 0.45;
float3 refl_dir = reflect(-view_dir, norm);
float3 env_refl = euv_city_env_radiance(
in.world_pos,
refl_dir,
sun_dir,
u.sky_horizon_tod.rgb,
u.sky_zenith_aspect.rgb,
u.sun_color_ambient.rgb,
rough_aa
);
float3 f_env = f0 + (max(float3(1.0 - rough_aa), f0) - f0) * fresnel_v;
float3 cc_refl = (clearcoat > 0.01) ? (env_refl * ((0.04 + 0.96 * fresnel_v) * clearcoat * 0.62)) : float3(0.0);
float3 ambient = (base_col * (1.0 - metallic * 0.65) * hemi * surface_ao + (env_refl * f_env * env_boost + cc_refl) * (0.65 + 0.35 * surface_ao)) * (0.46 + u.sun_color_ambient.w);
float3 hdr = direct + ambient + local_lamp_light + emissive;
float v_sun = clamp(dot(-view_dir, sun_dir), 0.0, 1.0);
float vs2 = v_sun * v_sun;
float vs8 = (vs2 * vs2) * (vs2 * vs2);
float3 haze_col = u.sky_horizon_tod.rgb + u.sun_color_ambient.rgb * (vs8 * 0.36);
float height_fog = exp(-max(in.world_pos.y, 0.0) * 0.022);
float fog_t = 1.0 - exp(-dist * u.sun_dir_fog.w * (0.72 + 0.45 * height_fog));
hdr = mix(hdr, haze_col, clamp(fog_t, 0.0, 0.88));
return float4(euv_scene_aces(hdr * u.camera_pos.w), 1.0);
}
"#;
pub(crate) const MTL_SIMULATOR_TOKEN: &str = "simulator";
pub(crate) const MTL_VIRTUAL_TOKEN: &str = "virtual";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_NS_STRING: &str = "NSString\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_NS_URL: &str = "NSURL\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_NS_ARRAY: &str = "NSArray\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_PIPELINE_DESC: &str = "MTLRenderPipelineDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_PASS_DESC: &str = "MTLRenderPassDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_TEX_DESC: &str = "MTLTextureDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_BINARY_ARCHIVE_DESC: &str = "MTLBinaryArchiveDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_ALLOC: &str = "alloc\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_INIT: &str = "init\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_RETAIN: &str = "retain\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_STRING_UTF8: &str = "stringWithUTF8String:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_FILE_URL_WITH_PATH: &str = "fileURLWithPath:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_ARRAY_WITH_OBJECT: &str = "arrayWithObject:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_UTF8_STRING: &str = "UTF8String\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NAME: &str = "name\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_CMD_QUEUE: &str = "newCommandQueue\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_LIBRARY: &str = "newLibraryWithSource:options:error:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_FUNCTION: &str = "newFunctionWithName:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_PIPELINE_STATE: &str = "newRenderPipelineStateWithDescriptor:error:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_BINARY_ARCHIVE: &str = "newBinaryArchiveWithDescriptor:error:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_ADD_PIPELINE_TO_ARCHIVE: &str =
"addRenderPipelineFunctionsWithDescriptor:error:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SERIALIZE_TO_URL: &str = "serializeToURL:error:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_URL: &str = "setUrl:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_BINARY_ARCHIVES: &str = "setBinaryArchives:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_VERTEX_FUNCTION: &str = "setVertexFunction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_FRAGMENT_FUNCTION: &str = "setFragmentFunction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_COLOR_ATTACHMENTS: &str = "colorAttachments\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_OBJECT_AT_INDEX: &str = "objectAtIndexedSubscript:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_PIXEL_FORMAT: &str = "setPixelFormat:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_BLENDING_ENABLED: &str = "setBlendingEnabled:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_RGB_BLEND_OP: &str = "setRgbBlendOperation:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_ALPHA_BLEND_OP: &str = "setAlphaBlendOperation:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_SRC_RGB_BLEND: &str = "setSourceRGBBlendFactor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DST_RGB_BLEND: &str = "setDestinationRGBBlendFactor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_SRC_ALPHA_BLEND: &str = "setSourceAlphaBlendFactor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DST_ALPHA_BLEND: &str = "setDestinationAlphaBlendFactor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_TEX_2D_DESC: &str =
"texture2DDescriptorWithPixelFormat:width:height:mipmapped:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_USAGE: &str = "setUsage:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_TEXTURE: &str = "newTextureWithDescriptor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_REPLACE_REGION: &str =
"replaceRegion:mipmapLevel:withBytes:bytesPerRow:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_BUFFER: &str = "newBufferWithBytes:length:options:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_BUFFER_LENGTH: &str = "newBufferWithLength:options:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_CONTENTS: &str = "contents\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_CMD_BUFFER: &str = "commandBuffer\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_RENDER_ENCODER: &str = "renderCommandEncoderWithDescriptor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_PIPELINE_STATE: &str = "setRenderPipelineState:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_VERTEX_BUFFER: &str = "setVertexBuffer:offset:atIndex:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_VERTEX_BYTES: &str = "setVertexBytes:length:atIndex:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_FRAGMENT_TEXTURE: &str = "setFragmentTexture:atIndex:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_SCISSOR_RECT: &str = "setScissorRect:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_DRAW_PRIMITIVES_INSTANCED: &str =
"drawPrimitives:vertexStart:vertexCount:instanceCount:baseInstance:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_END_ENCODING: &str = "endEncoding\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_PRESENT_DRAWABLE: &str = "presentDrawable:\0";
#[cfg(all(any(target_os = "macos", target_os = "ios"), not(target_abi = "sim")))]
pub(crate) const MTL_SEL_ADD_PRESENTED_HANDLER: &str = "addPresentedHandler:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_ADD_COMPLETED_HANDLER: &str = "addCompletedHandler:\0";
#[cfg(all(any(target_os = "macos", target_os = "ios"), not(target_abi = "sim")))]
pub(crate) const MTL_SEL_PRESENTED_TIME: &str = "presentedTime\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_STORAGE_MODE: &str = "storageMode\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_COPY_FROM_TEX_TO_BUF: &str = "copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:destinationBytesPerRow:destinationBytesPerImage:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const ENV_METAL_DISPLAY_SYNC: &str = "EUV_METAL_DISPLAY_SYNC";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const ENV_UNCAPPED_PRESENT: &str = "EUV_UNCAPPED_PRESENT";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ENV_VALUE_OFF: &str = "0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ENV_VALUE_FALSE: &str = "false";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ENV_VALUE_ON: &str = "1";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ENV_VALUE_TRUE: &str = "true";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_STATUS: &str = "status\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_WAIT_UNTIL_COMPLETED: &str = "waitUntilCompleted\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_GPU_START_TIME: &str = "GPUStartTime\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_GPU_END_TIME: &str = "GPUEndTime\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEXT_DRAWABLE: &str = "nextDrawable\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_TEXTURE: &str = "texture\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_WIDTH: &str = "width\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_HEIGHT: &str = "height\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_RENDER_PASS_DESC: &str = "renderPassDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_TEXTURE: &str = "setTexture:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_LOAD_ACTION: &str = "setLoadAction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_STORE_ACTION: &str = "setStoreAction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_CLEAR_COLOR: &str = "setClearColor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DEVICE: &str = "setDevice:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_FRAMEBUFFER_ONLY: &str = "setFramebufferOnly:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_MAX_DRAWABLE_COUNT: &str = "setMaximumDrawableCount:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DISPLAY_SYNC: &str = "setDisplaySyncEnabled:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_DRAWABLE_SIZE: &str = "drawableSize\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DRAWABLE_SIZE: &str = "setDrawableSize:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_RESPONDS_TO_SEL: &str = "respondsToSelector:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_FRAGMENT_BYTES: &str = "setFragmentBytes:length:atIndex:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_VIEWPORT: &str = "setViewport:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_COMMIT: &str = "commit\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_RELEASE: &str = "release\0";
pub(crate) const SHADER_STATE_LABEL_VALIDATED_FALLBACK: &str = "LUT + Hash Warm";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_VERTEX: &str = "euv_ui_vertex";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_FRAGMENT: &str = "euv_ui_fragment";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_BLUR_VERTEX: &str = "euv_blur_vertex";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_BLUR_DOWN: &str = "euv_blur_downsample";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_BLUR_UP: &str = "euv_blur_upsample";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_3D_VERTEX: &str = "euv_3d_vertex";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_3D_FRAGMENT: &str = "euv_3d_fragment";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_OCEAN_VERTEX: &str = "euv_ocean_vertex";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_OCEAN_FRAGMENT: &str = "euv_ocean_fragment";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_OCEAN_VERT: &str = "euv_scene_ocean_vert";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_OCEAN_FRAG: &str = "euv_scene_ocean_frag";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_BOAT_VERT: &str = "euv_scene_boat_vert";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_BOAT_FRAG: &str = "euv_scene_boat_frag";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_3D_SKY_VERT: &str = "euv_scene_3d_sky_vert";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_3D_SKY_FRAG: &str = "euv_scene_3d_sky_frag";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_3D_MESH_VERT: &str = "euv_scene_3d_mesh_vert";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_FN_SCENE_3D_MESH_FRAG: &str = "euv_scene_3d_mesh_frag";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_DEPTH_STENCIL_DESC: &str = "MTLDepthStencilDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DEPTH_COMPARE_FN: &str = "setDepthCompareFunction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DEPTH_WRITE_ENABLED: &str = "setDepthWriteEnabled:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_NEW_DEPTH_STENCIL_STATE: &str = "newDepthStencilStateWithDescriptor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DEPTH_STENCIL_STATE: &str = "setDepthStencilState:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_DEPTH_ATTACHMENT_PIXEL_FORMAT: &str =
"setDepthAttachmentPixelFormat:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_DEPTH_ATTACHMENT: &str = "depthAttachment\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_CLEAR_DEPTH: &str = "setClearDepth:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_PIXEL_FORMAT_DEPTH32_FLOAT: usize = 252;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_COMPARE_FUNC_LESS: usize = 1;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_STORE_ACTION_DONT_CARE: usize = 0;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_STORAGE_MODE_GPU: &str = "setStorageMode:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_STORAGE_MODE_PRIVATE_GPU: usize = 2;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_TEX_USAGE_RENDER_TARGET_GPU: usize = 4;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CLS_VERTEX_DESC: &str = "MTLVertexDescriptor\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_ATTRIBUTES: &str = "attributes\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_LAYOUTS: &str = "layouts\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_FORMAT: &str = "setFormat:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_OFFSET: &str = "setOffset:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_BUFFER_INDEX: &str = "setBufferIndex:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_STRIDE: &str = "setStride:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_STEP_FUNCTION: &str = "setStepFunction:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_STEP_RATE: &str = "setStepRate:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_SEL_SET_VERTEX_DESC: &str = "setVertexDescriptor:\0";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_VERTEX_FORMAT_FLOAT3: usize = 30;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_VERTEX_STEP_PER_VERTEX: usize = 1;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const GPU_DEVICE_APPLE_METAL: &str = "Apple Metal GPU";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ARCHIVE_FILE_PREFIX: &str = "euv-mtl-pipeline-";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_ARCHIVE_FILE_SUFFIX: &str = ".metallib.archive";
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_PIXEL_FORMAT_R8_UNORM: usize = 10;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_PIXEL_FORMAT_RGBA8_UNORM: usize = 70;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_PIXEL_FORMAT_BGRA8_UNORM: usize = 80;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_LOAD_ACTION_LOAD: usize = 1;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_LOAD_ACTION_CLEAR: usize = 2;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_STORE_ACTION_STORE: usize = 1;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_PRIMITIVE_TYPE_TRIANGLE: usize = 3;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_CMD_BUFFER_STATUS_COMPLETED: usize = 4;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_BLEND_FACTOR_ONE: usize = 1;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_BLEND_FACTOR_SRC_ALPHA: usize = 4;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const MTL_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA: usize = 5;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub(crate) const OBJC_BLOCK_IS_GLOBAL: i32 = 1 << 28;
#[cfg(target_os = "windows")]
pub(crate) const DLL_D3D12: &[u8] = b"d3d12.dll\0";
#[cfg(target_os = "windows")]
pub(crate) const DLL_D3DCOMPILER: &[u8] = b"d3dcompiler_47.dll\0";
#[cfg(target_os = "windows")]
pub(crate) const SYM_D3D12_CREATE_DEVICE: &[u8] = b"D3D12CreateDevice\0";
#[cfg(target_os = "windows")]
pub(crate) const SYM_D3D_COMPILE: &[u8] = b"D3DCompile\0";
#[cfg(target_os = "linux")]
pub(crate) const LIB_VULKAN_SONAME: &str = "libvulkan.so.1";
#[cfg(target_os = "android")]
pub(crate) const LIB_VULKAN_SONAME: &str = "libvulkan.so";
#[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) const SYM_VK_CREATE_INSTANCE: &str = "vkCreateInstance";
#[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) const SYM_VK_ENUM_DEVICES: &str = "vkEnumeratePhysicalDevices";
#[cfg(any(target_os = "linux", target_os = "android"))]
pub(crate) const RTLD_LAZY_GPU: i32 = 1;