Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions shaders/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,22 @@ suffix.sunPathRotation=°
option.PCSS_SEARCH_SAMPLES=PCSS检索采样数
option.PCSS_FILTER_SAMPLES=PCSS过滤采样数
option.COLORED_SHADOWS=彩色阴影
option.SHADOW_SOFT_TYPE=阴影过滤
value.SHADOW_SOFT_TYPE.0=不过滤
value.SHADOW_SOFT_TYPE.1=PCF过滤(较慢)
value.SHADOW_SOFT_TYPE.2=PCSS过滤(慢)
option.PCF_SOFT_RADIUS=PCF模糊半径
option.SHADOW_BIAS_STRENGTH=阴影偏移
option.SHADOW_BIAS_STRENGTH.comment=如果表面出现阴影错误请提高此数值
option.SHADOW_CONTRAST_STRENGTH=PCF的次表面散射补偿





option.SHADOW_BACKFACE_CULLING=阴影背面剔除
option.SHADOW_DISTORTION_STRENGTH=阴影形变强度

option.SHADOW_DISTORTION=阴影扭曲开关
option.SCREEN_SPACE_SHADOWS=屏幕空间阴影
option.SCREEN_SPACE_SHADOWS_SAMPLES=屏幕空间阴影采样数

Expand Down Expand Up @@ -307,8 +319,8 @@ option.SUBSURFACE_SCATTERING_STRENGTH=次表面散射强度
option.SUBSURFACE_SCATTERING_BRIGHTNESS=次表面散射亮度
option.SUBSURFACE_SCATTERING_RADIUS=次表面散射半径

option.SSRT_MAX_SAMPLES=光线追踪采样数
option.SSRT_REFINEMENT=光线追踪重采样
option.SSRT_MAX_SAMPLES=反射采样数
option.SSRT_REFINEMENT=反射重采样
option.SSRT_REFINEMENT_STEPS=重采样精度
option.SSRT_SKY_TRACING=追踪天空

Expand All @@ -321,6 +333,20 @@ option.REFLECTION_FILTER=反射过滤
option.RAYTRACED_REFRACTION=光线追踪折射
option.REFRACTION_STRENGTH=折射强度

option.REFLECTION_SCREEN_SPACE=屏幕空间反射
option.REFLECTION_SCREEN_SPACE.comment=方块的屏幕空间反射开关,关闭可以在保留质感的情况下提升性能
option.REFLECTION_SKY=天空反射
option.REFLECTION_SKY.comment=控制方块是否反射天空,以防有的人不喜欢
option.LIGHT_REFLECTION_SAMPLES=反射最高采样数
option.LIGHT_REFLECTION_SAMPLES.comment=屏幕空间反射和光线追踪反射的采样数都不会高于本选项的数值
option.FRESNEL_EXPONENT=菲涅尔透镜亮度
option.FRESNEL_EXPONENT.comment=关闭屏幕空间反射时的金属反光效果亮度
option.FRESNEL_STRENGTH=菲涅尔透镜强度
option.FRESNEL_STRENGTH.comment=关闭屏幕空间反射时的金属反光效果强度
option.REF_MIN=菲涅尔透镜最小亮度
option.REF_MIN.comment=关闭屏幕空间反射时的金属反光效果最小亮度
option.REF_MAX=菲涅尔透镜最大亮度
option.REF_MAX.comment=关闭屏幕空间反射时的金属反光效果亮度
# Transparent
option.WATER_PARALLAX=水体视差
option.WATER_CAUSTICS=水体焦散
Expand Down
132 changes: 86 additions & 46 deletions shaders/lib/SpatialUpscale.glsl
Original file line number Diff line number Diff line change
@@ -1,63 +1,103 @@
//================================================================================================//
// SVGF Upscale Diffuse Indirect (with quality & blur radius control)
//================================================================================================//
#if defined PASS_DEFERRED_LIGHTING
#if defined SSILVB_ENABLED && defined SVGF_ENABLED
vec3 UpscaleDiffuseIndirect(in ivec2 texelPos, in vec3 worldNormal, in float viewDistance, in float NdotV) {
// ivec2 randTexel = ivec2(vec2(texelPos >> 1) + BlueNoise(texelPos, frameCounter + 3));
texelPos >>= 1;

vec3 sum = texelFetch(colortex3, texelPos, 0).rgb;
float sumWeight = 1.0;

float sigmaZ = -4.0 * NdotV;

ivec2 texelEnd = ivec2(halfViewEnd) - 1;

for (uint i = 0u; i < 8u; ++i) {
ivec2 sampleTexel = clamp(texelPos + offset3x3N[i], ivec2(1), texelEnd);

vec3 sampleAux = texelFetch(colortex14, sampleTexel, 0).rgb;

float weight = pow16(saturate(dot(OctDecodeSnorm(sampleAux.xy), worldNormal)));
weight *= exp2(distance(sampleAux.z, viewDistance) * sigmaZ);

vec3 sampleLight = texelFetch(colortex3, sampleTexel, 0).rgb;

sum += sampleLight * weight;
sumWeight += weight;
}

return sum * rcp(sumWeight);
}
// ========== 可调节参数 ==========
#ifndef SVGF_QUALITY
#define SVGF_QUALITY 0 // [0 1 2] // 0=仅自身, 1=十字形(4样本), 2=完整3x3(8样本)
#endif
#ifndef SVGF_BLUR_RADIUS
#define SVGF_BLUR_RADIUS 15.0 // [1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0 15.0 20.0 25.0 30.0 50.0] 采样半径倍数(1.0=原始相邻像素,>1.0扩大模糊范围)
#endif
// ================================

vec3 UpscaleDiffuseIndirect(in ivec2 texelPos, in vec3 worldNormal, in float viewDistance, in float NdotV) {
texelPos >>= 1;
ivec2 texelEnd = ivec2(halfViewEnd) - 1;

vec3 sum = texelFetch(colortex3, texelPos, 0).rgb;
float sumWeight = 1.0;

#if SVGF_QUALITY == 0
return sum;
#endif

float sigmaZ = -4.0 * NdotV;
float depthCenter = viewDistance;

// 计算缩放后的偏移量(模糊半径)
float radius = max(1.0, SVGF_BLUR_RADIUS);
ivec2 offsetScale = ivec2(round(radius));

#if SVGF_QUALITY == 1
// 十字形采样(4个方向)
const ivec2 offsets[4] = ivec2[](ivec2(1,0), ivec2(-1,0), ivec2(0,1), ivec2(0,-1));
for (int i = 0; i < 4; ++i) {
ivec2 sampleTexel = clamp(texelPos + offsets[i] * offsetScale, ivec2(1), texelEnd);
vec3 sampleAux = texelFetch(colortex14, sampleTexel, 0).rgb;
float ndot = saturate(dot(OctDecodeSnorm(sampleAux.xy), worldNormal));
float weight = ndot * ndot; // 平方代替 pow16
float depthDiff = abs(sampleAux.z - depthCenter);
weight *= exp2(depthDiff * sigmaZ);
if (weight < 0.001) continue;
vec3 sampleLight = texelFetch(colortex3, sampleTexel, 0).rgb;
sum += sampleLight * weight;
sumWeight += weight;
}
#else
// 完整3x3采样(8个邻居)
for (uint i = 0u; i < 8u; ++i) {
ivec2 sampleTexel = clamp(texelPos + offset3x3N[i] * offsetScale, ivec2(1), texelEnd);
vec3 sampleAux = texelFetch(colortex14, sampleTexel, 0).rgb;
float ndot = saturate(dot(OctDecodeSnorm(sampleAux.xy), worldNormal));
float weight = ndot * ndot;
weight = weight * weight; // ndot^4 (接近原始pow16)
float depthDiff = abs(sampleAux.z - depthCenter);
weight *= exp2(depthDiff * sigmaZ);
if (weight < 0.001) continue;
vec3 sampleLight = texelFetch(colortex3, sampleTexel, 0).rgb;
sum += sampleLight * weight;
sumWeight += weight;
}
#endif

return sum * rcp(sumWeight);
}
#endif
#endif

//================================================================================================//

// Volumetric Fog Upscale (original logic, unchanged)
//================================================================================================//
#if defined PASS_COMPOSITE
#if defined VOLUMETRIC_FOG || defined UW_VOLUMETRIC_FOG
mat2x3 UnpackFogData(in uvec2 data) {
return mat2x3(DecodeRGBE8U(data.x), DecodeRGBE8U(data.y));
}

mat2x3 UpscaleVolumetricFog(in ivec2 texelPos, in float linearDepth) {
ivec2 randTexel = ivec2(vec2(texelPos >> 1) + BlueNoise(texelPos, frameCounter + 7));
float sigmaZ = -64.0 / linearDepth;
mat2x3 UnpackFogData(in uvec2 data) {
return mat2x3(DecodeRGBE8U(data.x), DecodeRGBE8U(data.y));
}

mat2x3 UpscaleVolumetricFog(in ivec2 texelPos, in float linearDepth) {
ivec2 randTexel = ivec2(vec2(texelPos >> 1) + BlueNoise(texelPos, frameCounter + 7));
float sigmaZ = -64.0 / linearDepth;

mat2x3 sum = UnpackFogData(texelFetch(colortex11, randTexel, 0).xy);
float sumWeight = 1.0;
mat2x3 sum = UnpackFogData(texelFetch(colortex11, randTexel, 0).xy);
float sumWeight = 1.0;

for (uint i = 0u; i < 8u; ++i) {
ivec2 sampleTexel = randTexel + offset3x3N[i];
uvec3 sampleFogData = texelFetch(colortex11, sampleTexel, 0).xyz;
for (uint i = 0u; i < 8u; ++i) {
ivec2 sampleTexel = randTexel + offset3x3N[i];
uvec3 sampleFogData = texelFetch(colortex11, sampleTexel, 0).xyz;

float sampleDepth = uintBitsToFloat(sampleFogData.z);
float weight = exp2(abs(sampleDepth - linearDepth) * sigmaZ);
float sampleDepth = uintBitsToFloat(sampleFogData.z);
float weight = exp2(abs(sampleDepth - linearDepth) * sigmaZ);

sum += UnpackFogData(sampleFogData.xy) * weight;
sumWeight += weight;
}
sum += UnpackFogData(sampleFogData.xy) * weight;
sumWeight += weight;
}

sum *= rcp(sumWeight);
return sum;
}
sum *= rcp(sumWeight);
return sum;
}
#endif
#endif
Loading