skybox.slang

cross platform rendering playground

src/passes/skybox/skybox.slang

928 B
#include "shared.h"
#include "renderer_types.h"

[[vk::push_constant]]
SkyboxPushConstants pc;

struct VSOutput {
    vec4 position : SV_Position;
    vec3 ray_dir : TEXCOORD0;
};

static vec2 pos[3] = { vec2(-1.0, -1.0), vec2(3.0, -1.0), vec2(-1.0, 3.0) };

[shader("vertex")]
VSOutput vsMain(u32 vertexID: SV_VertexID) {
    VSOutput o;

    vec2 ndc = pos[vertexID];

    FrameUBO frame = *pc.frame;

    vec4 clip = vec4(ndc, 1.0, 1.0);
    vec4 world = clip * frame.inv_view_proj;

    world.xyz /= world.w;

    o.ray_dir = world.xyz - frame.position_ws.xyz;

    o.position = vec4(ndc, 0.0, 1.0);

    return o;
}

[shader("fragment")]
vec4 fsMain(VSOutput input) : SV_Target {
    FrameUBO frame = *pc.frame;
    vec3 dir = normalize(input.ray_dir);
    vec3 hdr = pc.cubemap.SampleLevel(frame.linear_clamp, dir, 0.0).rgb;
    f32 exposure = 1.5;
    vec3 ldr = 1.0 - exp(-hdr * exposure);
    return vec4(ldr, 1.0);
}