2025-03-20 23:08:26 +01:00
|
|
|
|
|
|
|
|
#[set(everything)]
|
|
|
|
|
const constants: {
|
|
|
|
|
SMVP: float4x4;
|
2025-05-02 08:42:28 +02:00
|
|
|
envmap_data_world: float4; // angle, empty, empty, strength
|
2025-03-20 23:08:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[set(everything)]
|
2025-04-24 22:19:44 +02:00
|
|
|
const sampler_linear: sampler;
|
2025-03-20 23:08:26 +01:00
|
|
|
|
|
|
|
|
#[set(everything)]
|
2025-04-24 22:19:44 +02:00
|
|
|
const envmap: tex2d;
|
2025-03-20 23:08:26 +01:00
|
|
|
|
|
|
|
|
const PI: float = 3.1415926535;
|
|
|
|
|
const PI2: float = 6.283185307;
|
|
|
|
|
|
|
|
|
|
struct vert_in {
|
|
|
|
|
pos: float3;
|
|
|
|
|
nor: float3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct vert_out {
|
|
|
|
|
pos: float4;
|
|
|
|
|
nor: float3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun world_pass_vert(input: vert_in): vert_out {
|
|
|
|
|
var output: vert_out;
|
|
|
|
|
output.pos = constants.SMVP * float4(input.pos, 1.0);
|
|
|
|
|
output.nor = input.nor;
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun envmap_equirect(normal: float3, angle: float): float2 {
|
|
|
|
|
var phi: float = acos(normal.z);
|
|
|
|
|
var theta: float = atan2(normal.x, -normal.y) + PI + angle;
|
|
|
|
|
return float2(theta / PI2, phi / PI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun world_pass_frag(input: vert_out): float4 {
|
|
|
|
|
var n: float3 = normalize(input.nor);
|
|
|
|
|
var color: float4;
|
2025-04-19 12:29:49 +02:00
|
|
|
color.rgb = sample(envmap, sampler_linear, envmap_equirect(-n, constants.envmap_data_world.x)).rgb * constants.envmap_data_world.w;
|
2025-03-20 23:08:26 +01:00
|
|
|
color.a = 0.0; // Mark as non-opaque
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[pipe]
|
|
|
|
|
struct pipe {
|
|
|
|
|
vertex = world_pass_vert;
|
|
|
|
|
fragment = world_pass_frag;
|
|
|
|
|
}
|