36 lines
1.1 KiB
GLSL
36 lines
1.1 KiB
GLSL
#version 450
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_nonuniform_qualifier : enable
|
|
|
|
#include "bindless.glsl"
|
|
|
|
layout(location = 0) in vec2 uv; // from fullscreen triangle: 0..2 range
|
|
layout(location = 0) out vec4 outColor;
|
|
|
|
layout(push_constant) uniform SkyboxPC {
|
|
mat4 invViewProj; // inverse(Proj * View) (your current setup)
|
|
vec4 cameraPos; // xyz = camera world position
|
|
uint skyboxTextureId; // index into textureCubes[]
|
|
} pcs;
|
|
|
|
void main()
|
|
{
|
|
// Fullscreen-triangle trick gives uv in [0..2]. Convert to [0..1].
|
|
vec2 uv01 = uv * 0.5;
|
|
|
|
// Build an NDC point on the far plane.
|
|
// Vulkan NDC is x,y in [-1..1], z in [0..1]. Using z=1 means "far".
|
|
vec4 ndc = vec4(uv01 * 2.0 - 1.0, 1.0, 1.0);
|
|
|
|
// Unproject to world space
|
|
vec4 world = pcs.invViewProj * ndc;
|
|
vec3 worldPos = world.xyz / world.w;
|
|
|
|
// Direction from camera through this pixel
|
|
vec3 dir = normalize(worldPos - pcs.cameraPos.xyz);
|
|
|
|
// Sample cubemap directly
|
|
outColor = sampleTextureCubeLinear(pcs.skyboxTextureId, dir);
|
|
// outColor = sampleTextureCubeNearest(pcs.skyboxTextureId, dir);
|
|
}
|