Fix blocky terrain SDF

#3975
This commit is contained in:
2026-03-11 19:25:18 +01:00
parent 96bbae8e28
commit 22c88eb59d
4 changed files with 18 additions and 11 deletions
@@ -170,15 +170,14 @@ void CS_RasterizeHeightfield(uint3 DispatchThreadId : SV_DispatchThreadID)
// Convert voxel world-space position into heightfield local-space position and get heightfield UV
float4x4 worldToLocal = ToMatrix4x4(objectData.WorldToVolume);
float3 volumePos = mul(float4(voxelWorldPos, 1), worldToLocal).xyz;
float3 volumeUV = volumePos * objectData.VolumeToUVWMul + objectData.VolumeToUVWAdd;
float2 heightfieldUV = float2(volumeUV.x, volumeUV.z);
// Sample heightfield around the voxel location (heightmap uses point sampler)
Texture2D<float4> heightmap = ObjectsTextures[i];
float4 localToUV = float4(objectData.VolumeToUVWMul.xz, objectData.VolumeToUVWAdd.xz);
#if 1
float3 n00, n10, n01, n11;
bool h00, h10, h01, h11;
float offset = CascadeVoxelSize * 2;
float offset = CascadeVoxelSize;
float3 p00 = SampleHeightmap(heightmap, volumePos + float3(-offset, 0, 0), localToUV, n00, h00, objectData.MipOffset);
float3 p10 = SampleHeightmap(heightmap, volumePos + float3(+offset, 0, 0), localToUV, n10, h10, objectData.MipOffset);
float3 p01 = SampleHeightmap(heightmap, volumePos + float3(0, 0, -offset), localToUV, n01, h01, objectData.MipOffset);
@@ -189,6 +188,11 @@ void CS_RasterizeHeightfield(uint3 DispatchThreadId : SV_DispatchThreadID)
float3 heightfieldNormal = (n00 + n10 + n01 + n11) * 0.25f;
heightfieldNormal = normalize(heightfieldNormal);
bool isHole = h00 || h10 || h01 || h11;
#else
float3 heightfieldNormal;
bool isHole;
float3 heightfieldPosition = SampleHeightmap(heightmap, volumePos, localToUV, heightfieldNormal, isHole, objectData.MipOffset);
#endif
// Skip holes and pixels outside the heightfield
if (isHole)
+2 -2
View File
@@ -35,11 +35,11 @@ float3 SampleHeightmap(Texture2D<float4> heightmap, float3 localPosition, float4
{
// Sample heightmap
float2 uv = localPosition.xz * localToUV.xy + localToUV.zw;
float4 value = heightmap.SampleLevel(SamplerPointClamp, uv, mipOffset);
float4 value = heightmap.SampleLevel(SamplerLinearClamp, uv, mipOffset);
// Decode heightmap
normal = DecodeHeightmapNormal(value, isHole);
float height = DecodeHeightmapHeight(value);;
float height = DecodeHeightmapHeight(value);
float3 position = float3(localPosition.x, height, localPosition.z);
// UVs outside the heightmap are empty