From 00f17ddd622e6f4b128bf18f4b9fba5754f975df Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Thu, 12 Mar 2026 00:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=93=E7=A7=AF=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=EF=BC=9A=E6=B7=BB=E5=8A=A0=20phase=5Ffunction=20?= =?UTF-8?q?=E5=92=8C=E4=BF=AE=E6=AD=A3=E7=B4=AF=E7=A7=AF=E5=85=AC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增功能: - 添加 phase_function()(返回 1.0) - 使用 Unity 的累积公式:Sint = (S - S * exp(-sigmaE * step)) / sigmaE - 添加 sigmaE 避免除零 与 Unity 版本的主要差异: - 缺少 volumetric_shadow 体积阴影 - 缺少 ambient_light 环境光 - 缺少 acc_density 累积限制 - 缺少 Gamma 校正 --- Res/Shader/volume.hlsl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Res/Shader/volume.hlsl b/Res/Shader/volume.hlsl index 9c156d50..e2f05418 100644 --- a/Res/Shader/volume.hlsl +++ b/Res/Shader/volume.hlsl @@ -85,6 +85,11 @@ bool get_hdda_hit(inout pnanovdb_readaccessor_t acc, inout float tmin, float3 or return hit; } +float phase_function() +{ + return 1.0; +} + PSInput MainVS(VSInput input) { PSInput output; @@ -167,9 +172,12 @@ float4 MainPS(PSInput input) : SV_TARGET continue; } - float3 S = density * float3(1, 1, 1); - color += transmittance * S * _StepSize; - transmittance *= exp(-density * _StepSize); + float sigmaS = density; + float sigmaE = max(0.000001, sigmaS); + float3 S = sigmaS * phase_function() * float3(1, 1, 1); + float3 Sint = (S - S * exp(-sigmaE * _StepSize)) / sigmaE; + color += transmittance * Sint; + transmittance *= exp(-sigmaE * _StepSize); tmin += _StepSize; }