| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #[set(everything)]
- const constants: {
- SMVP: float4x4;
- envmap_data_world: float4; // angle, empty, empty, strength
- };
- #[set(everything)]
- const sampler_linear: sampler;
- #[set(everything)]
- const envmap: tex2d;
- 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;
- color.rgb = sample(envmap, sampler_linear, envmap_equirect(-n, constants.envmap_data_world.x)).rgb * constants.envmap_data_world.w;
- color.a = 0.0; // Mark as non-opaque
- return color;
- }
- #[pipe]
- struct pipe {
- vertex = world_pass_vert;
- fragment = world_pass_frag;
- }
|