35 lines
1.1 KiB
HLSL
35 lines
1.1 KiB
HLSL
// XC_BUILTIN_SKYBOX_D3D12_PS
|
|
cbuffer EnvironmentConstants : register(b0) {
|
|
float4 gSkyboxTopColor;
|
|
float4 gSkyboxHorizonColor;
|
|
float4 gSkyboxBottomColor;
|
|
float4 gCameraRightAndTanHalfFov;
|
|
float4 gCameraUpAndAspect;
|
|
float4 gCameraForwardAndUnused;
|
|
}
|
|
|
|
struct PSInput {
|
|
float4 position : SV_POSITION;
|
|
float2 ndc : TEXCOORD0;
|
|
};
|
|
|
|
float4 MainPS(PSInput input) : SV_Target {
|
|
const float tanHalfFov = gCameraRightAndTanHalfFov.w;
|
|
const float aspect = gCameraUpAndAspect.w;
|
|
|
|
float3 viewRay = normalize(
|
|
gCameraForwardAndUnused.xyz +
|
|
input.ndc.x * aspect * tanHalfFov * gCameraRightAndTanHalfFov.xyz +
|
|
input.ndc.y * tanHalfFov * gCameraUpAndAspect.xyz);
|
|
|
|
const float vertical = clamp(viewRay.y, -1.0f, 1.0f);
|
|
float3 color = gSkyboxHorizonColor.rgb;
|
|
if (vertical >= 0.0f) {
|
|
color = lerp(gSkyboxHorizonColor.rgb, gSkyboxTopColor.rgb, pow(saturate(vertical), 0.65f));
|
|
} else {
|
|
color = lerp(gSkyboxHorizonColor.rgb, gSkyboxBottomColor.rgb, pow(saturate(-vertical), 0.55f));
|
|
}
|
|
|
|
return float4(color, 1.0f);
|
|
}
|