Restore panoramic skybox path for skybox integration

This commit is contained in:
2026-04-06 02:42:08 +08:00
parent ae4c06d7b6
commit dc17685099
10 changed files with 22265 additions and 13051 deletions

View File

@@ -1,7 +1,8 @@
// XC_BUILTIN_SKYBOX_OPENGL_PS
#version 430
layout(binding = 0) uniform samplerCube uSkyboxTexture;
layout(binding = 0) uniform sampler2D uSkyboxPanoramicTexture;
layout(binding = 1) uniform samplerCube uSkyboxTexture;
layout(std140, binding = 0) uniform EnvironmentConstants {
vec4 gSkyboxTopColor;
@@ -47,6 +48,13 @@ vec3 RotateAroundY(vec3 viewRay) {
viewRay.x * sinTheta + viewRay.z * cosTheta));
}
vec2 ComputePanoramicUv(vec3 viewRay) {
vec3 rotatedRay = RotateAroundY(viewRay);
float u = fract(atan(rotatedRay.z, rotatedRay.x) * XC_INV_TWO_PI + 0.5);
float v = acos(clamp(rotatedRay.y, -1.0, 1.0)) * XC_INV_PI;
return vec2(u, clamp(v, 0.0, 1.0));
}
void main() {
float tanHalfFov = gCameraRightAndTanHalfFov.w;
float aspect = gCameraUpAndAspect.w;
@@ -57,10 +65,14 @@ void main() {
vNdc.y * tanHalfFov * gCameraUpAndAspect.xyz);
vec3 color = EvaluateProceduralSkybox(viewRay);
if (gSkyboxRotationAndMode.y > 0.5) {
if (gSkyboxRotationAndMode.y > 1.5) {
color = texture(uSkyboxTexture, RotateAroundY(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
} else if (gSkyboxRotationAndMode.y > 0.5) {
color = texture(uSkyboxPanoramicTexture, ComputePanoramicUv(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
}
fragColor = vec4(color, 1.0);

View File

@@ -15,8 +15,9 @@ layout(set = 1, binding = 0, std140) uniform MaterialConstants {
vec4 gSkyboxRotationAndMode;
};
layout(set = 2, binding = 0) uniform textureCube uSkyboxTexture;
layout(set = 3, binding = 0) uniform sampler uLinearSampler;
layout(set = 2, binding = 0) uniform texture2D uSkyboxPanoramicTexture;
layout(set = 3, binding = 0) uniform textureCube uSkyboxTexture;
layout(set = 4, binding = 0) uniform sampler uLinearSampler;
layout(location = 0) in vec2 vNdc;
@@ -48,6 +49,13 @@ vec3 RotateAroundY(vec3 viewRay) {
viewRay.x * sinTheta + viewRay.z * cosTheta));
}
vec2 ComputePanoramicUv(vec3 viewRay) {
vec3 rotatedRay = RotateAroundY(viewRay);
float u = fract(atan(rotatedRay.z, rotatedRay.x) * XC_INV_TWO_PI + 0.5);
float v = acos(clamp(rotatedRay.y, -1.0, 1.0)) * XC_INV_PI;
return vec2(u, clamp(v, 0.0, 1.0));
}
void main() {
float tanHalfFov = gCameraRightAndTanHalfFov.w;
float aspect = gCameraUpAndAspect.w;
@@ -58,10 +66,14 @@ void main() {
vNdc.y * tanHalfFov * gCameraUpAndAspect.xyz);
vec3 color = EvaluateProceduralSkybox(viewRay);
if (gSkyboxRotationAndMode.y > 0.5) {
if (gSkyboxRotationAndMode.y > 1.5) {
color = texture(samplerCube(uSkyboxTexture, uLinearSampler), RotateAroundY(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
} else if (gSkyboxRotationAndMode.y > 0.5) {
color = texture(sampler2D(uSkyboxPanoramicTexture, uLinearSampler), ComputePanoramicUv(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
}
fragColor = vec4(color, 1.0);

View File

@@ -1,5 +1,6 @@
// XC_BUILTIN_SKYBOX_D3D12_PS
TextureCube gSkyboxTexture : register(t0);
Texture2D gSkyboxPanoramicTexture : register(t0);
TextureCube gSkyboxTexture : register(t1);
SamplerState gLinearSampler : register(s0);
cbuffer EnvironmentConstants : register(b0) {
@@ -47,6 +48,13 @@ float3 RotateAroundY(float3 viewRay) {
viewRay.x * sinTheta + viewRay.z * cosTheta));
}
float2 ComputePanoramicUv(float3 viewRay) {
const float3 rotatedRay = RotateAroundY(viewRay);
const float u = frac(atan2(rotatedRay.z, rotatedRay.x) * XC_INV_TWO_PI + 0.5f);
const float v = acos(clamp(rotatedRay.y, -1.0f, 1.0f)) * XC_INV_PI;
return float2(u, saturate(v));
}
float4 MainPS(PSInput input) : SV_Target {
const float tanHalfFov = gCameraRightAndTanHalfFov.w;
const float aspect = gCameraUpAndAspect.w;
@@ -57,10 +65,14 @@ float4 MainPS(PSInput input) : SV_Target {
input.ndc.y * tanHalfFov * gCameraUpAndAspect.xyz);
float3 color = EvaluateProceduralSkybox(viewRay);
if (gSkyboxRotationAndMode.y > 0.5f) {
if (gSkyboxRotationAndMode.y > 1.5f) {
color = gSkyboxTexture.Sample(gLinearSampler, RotateAroundY(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
} else if (gSkyboxRotationAndMode.y > 0.5f) {
color = gSkyboxPanoramicTexture.Sample(gLinearSampler, ComputePanoramicUv(viewRay)).rgb *
gSkyboxTintAndExposure.rgb *
gSkyboxTintAndExposure.w;
}
return float4(color, 1.0f);

View File

@@ -5,6 +5,7 @@ Shader "Builtin Skybox"
_Tint ("Tint", Color) = (1,1,1,1) [Semantic(Tint)]
_Exposure ("Exposure", Float) = 1.0 [Semantic(Exposure)]
_Rotation ("Rotation", Float) = 0.0 [Semantic(Rotation)]
_MainTex ("Panoramic", 2D) = "white" [Semantic(SkyboxPanoramicTexture)]
_Tex ("Cubemap (HDR)", Cube) = "white" [Semantic(SkyboxTexture)]
}
SubShader
@@ -17,8 +18,9 @@ Shader "Builtin Skybox"
{
EnvironmentConstants (ConstantBuffer, 0, 0) [Semantic(Environment)]
MaterialConstants (ConstantBuffer, 1, 0) [Semantic(Material)]
SkyboxTexture (TextureCube, 2, 0) [Semantic(SkyboxTexture)]
LinearClampSampler (Sampler, 3, 0) [Semantic(LinearClampSampler)]
SkyboxPanoramicTexture (Texture2D, 2, 0) [Semantic(SkyboxPanoramicTexture)]
SkyboxTexture (TextureCube, 3, 0) [Semantic(SkyboxTexture)]
LinearClampSampler (Sampler, 4, 0) [Semantic(LinearClampSampler)]
}
HLSLPROGRAM
#pragma vertex MainVS