完善体积云渲染:添加旋转和参数优化
新增功能: - 添加云的旋转动画(绕 Y 轴) - 修复 HDDA 在旋转坐标系中的坐标转换问题 参数优化: - tmax: 1000 → 5000(修复远处云消失的问题) - MaxSteps: 500 → 2000 - StepSize: 0.5 → 2.0 - DensityScale: 0.05 → 0.1 - 相机位置调整到 z=-1200 已知问题: - 缺少光照计算(phase_function 和 volumetric_shadow) - 渲染结果比 Unity 版本更亮
This commit is contained in:
@@ -11,6 +11,7 @@ cbuffer CB0 : register(b1)
|
||||
float _StepSize;
|
||||
float3 _BBoxMax;
|
||||
uint _MaxSteps;
|
||||
float _RotationY;
|
||||
};
|
||||
|
||||
StructuredBuffer<uint> buf : register(t1);
|
||||
@@ -113,7 +114,7 @@ float4 MainPS(PSInput input) : SV_TARGET
|
||||
float3 rayDir = normalize(input.worldPos - _CameraPos);
|
||||
|
||||
float tmin = 0.01;
|
||||
float tmax = 1000.0;
|
||||
float tmax = 5000.0;
|
||||
|
||||
NanoVolume volume;
|
||||
initVolume(volume);
|
||||
@@ -121,8 +122,19 @@ float4 MainPS(PSInput input) : SV_TARGET
|
||||
float3 color = float3(0, 0, 0);
|
||||
float transmittance = 1.0;
|
||||
|
||||
float cosR = cos(_RotationY);
|
||||
float sinR = sin(_RotationY);
|
||||
float3x3 invRotY = float3x3(
|
||||
cosR, 0, sinR,
|
||||
0, 1, 0,
|
||||
-sinR, 0, cosR
|
||||
);
|
||||
|
||||
float3 localCameraPos = mul(invRotY, _CameraPos);
|
||||
float3 localRayDir = mul(invRotY, rayDir);
|
||||
|
||||
float not_used;
|
||||
bool hit = get_hdda_hit(volume.acc, tmin, _CameraPos, rayDir, tmax, not_used);
|
||||
bool hit = get_hdda_hit(volume.acc, tmin, localCameraPos, localRayDir, tmax, not_used);
|
||||
if (!hit) { return float4(0, 0, 0, 0); }
|
||||
|
||||
float skip = 0;
|
||||
@@ -130,9 +142,9 @@ float4 MainPS(PSInput input) : SV_TARGET
|
||||
for (uint i = 0; i < _MaxSteps; i++) {
|
||||
if (tmin >= tmax || transmittance < 0.01) break;
|
||||
|
||||
float3 worldPos = _CameraPos + rayDir * tmin;
|
||||
float3 localPos = localCameraPos + localRayDir * tmin;
|
||||
|
||||
uint dim = get_dim_coord(volume.acc, worldPos);
|
||||
uint dim = get_dim_coord(volume.acc, localPos);
|
||||
if (dim > 1) {
|
||||
float skip_step = 15.0;
|
||||
tmin += skip_step;
|
||||
@@ -140,7 +152,7 @@ float4 MainPS(PSInput input) : SV_TARGET
|
||||
continue;
|
||||
}
|
||||
|
||||
float density = get_value_coord(volume.acc, worldPos) * _DensityScale;
|
||||
float density = get_value_coord(volume.acc, localPos) * _DensityScale;
|
||||
|
||||
if (density < 0.001) {
|
||||
float skip_step = 5.0;
|
||||
|
||||
Reference in New Issue
Block a user