blob: 5b4caffa4f12dd3057fbbf592f553d453501b657 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// equirectangular HDRI -> cubemap face projection. NOTE: the OpenGL path uses the
// hand-written assets/shaders/EquirectToCubemap.glsl instead; this Slang version
// feeds the Vulkan cubemap bake (vulkan_cubemap.cpp), which binds the view /
// projection as a $Globals UBO. kept as loose `uniform` globals (not a
// ConstantBuffer) so both paths bind them the same way.
uniform float4x4 u_projection;
uniform float4x4 u_view;
struct VSInput { float3 position : POSITION; };
struct VSOutput { float4 position : SV_Position; float3 worldPos : TEXCOORD0; };
[shader("vertex")]
VSOutput vertexMain(VSInput input)
{
VSOutput output;
output.worldPos = input.position;
output.position = mul(u_projection, mul(u_view, float4(input.position, 1.0)));
return output;
}
Sampler2D u_EquirectangularMap;
static const float2 invAtan = float2(0.1591, 0.3183);
float2 SampleSphericalMap(float3 v)
{
float2 uv = float2(atan2(v.z, v.x), asin(v.y));
uv *= invAtan;
uv += 0.5;
return uv;
}
[shader("fragment")]
float4 fragmentMain(VSOutput input) : SV_Target
{
float2 uv = SampleSphericalMap(normalize(input.worldPos));
float3 color = u_EquirectangularMap.Sample(uv).rgb;
return float4(color, 1.0);
}
|