procedural-3d-engine/shaders/slang/texturecubemap/skybox.slang
2025-04-27 11:07:30 +02:00

47 lines
No EOL
858 B
Text

/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: MIT
*
*/
struct VSInput
{
float3 Pos;
};
struct VSOutput
{
float4 Pos : SV_POSITION;
float3 UVW;
};
struct UBO
{
float4x4 projection;
float4x4 model;
};
ConstantBuffer<UBO> ubo;
SamplerCube samplerCubeMap;
[shader("vertex")]
VSOutput vertexMain(VSInput input)
{
VSOutput output;
output.UVW = input.Pos;
// Convert cubemap coordinates into Vulkan coordinate space
output.UVW.xy *= -1.0;
// Remove translation from view matrix
float4x4 viewMat = ubo.model;
viewMat[0][3] = 0.0;
viewMat[1][3] = 0.0;
viewMat[2][3] = 0.0;
output.Pos = mul(ubo.projection, mul(viewMat, float4(input.Pos.xyz, 1.0)));
return output;
}
[shader("fragment")]
float4 fragmentMain(VSOutput input)
{
return samplerCubeMap.Sample(input.UVW);
}