Skip to content

Commit

Permalink
[HDRP] APV - Fix voxelization issues with planes at the origin (#5897)
Browse files Browse the repository at this point in the history
* Fix precision issues with the scene voxelization, especially with geometry at the origin.

* Updated changelog

* Fix renderer bounds for the plane case

* disable debug

* rename epsilon

Co-authored-by: JulienIgnace-Unity <julien@unity3d.com>
  • Loading branch information
alelievr and JulienIgnace-Unity committed Oct 8, 2021
1 parent 2e61b9b commit cbb6423
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public void Initialize(ProbeReferenceVolumeProfile profile, Vector3 refVolOrigin
if ((flags & StaticEditorFlags.ContributeGI) == 0)
continue;

var volume = ProbePlacement.ToVolume(r.bounds);
// Inflate a bit the volume in case it's too small (plane case)
var volume = ProbePlacement.ToVolume(new Bounds(r.bounds.center, r.bounds.size + Vector3.one * 0.01f));

renderers.Add((r, volume));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Shader "Hidden/ProbeVolume/VoxelizeScene"
Tags { "RenderType"="Opaque" }
LOD 100

HLSLINCLUDE
#define EPSILON (1e-10)
ENDHLSL

Pass
{
Name "Voxelize Mesh"
Expand Down Expand Up @@ -68,10 +72,10 @@ Shader "Hidden/ProbeVolume/VoxelizeScene"

float4 frag(VertexToFragment i) : COLOR
{
if (any(i.cellPos01 < 0) || any(i.cellPos01 >= 1))
if (any(i.cellPos01 < -EPSILON) || any(i.cellPos01 >= 1 + EPSILON))
return 0;

uint3 pos = uint3(i.cellPos01 * _OutputSize);
uint3 pos = min(uint3(i.cellPos01 * _OutputSize), _OutputSize);

_Output[pos] = 1;

Expand All @@ -93,7 +97,7 @@ Shader "Hidden/ProbeVolume/VoxelizeScene"
#pragma vertex vert
#pragma fragment frag
#pragma target 4.5
#pragma enable_d3d11_debug_symbols
// #pragma enable_d3d11_debug_symbols

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"

Expand Down Expand Up @@ -167,14 +171,14 @@ Shader "Hidden/ProbeVolume/VoxelizeScene"

float4 frag(VertexToFragment i) : COLOR
{
if (any(i.cellPos01 < 0) || any(i.cellPos01 >= 1))
if (any(i.cellPos01 < -EPSILON) || any(i.cellPos01 >= 1 + EPSILON))
return 0;

// Offset the cellposition with the heightmap
float hole = _TerrainHolesTexture.Sample(s_point_clamp_sampler, float3(i.uv, 0));
clip(hole == 0.0f ? -1 : 1);

uint3 pos = uint3(i.cellPos01 * _OutputSize);
uint3 pos = min(uint3(i.cellPos01 * _OutputSize), _OutputSize);
_Output[pos] = 1;

return float4(i.cellPos01.xyz, 1);
Expand Down
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed the clouds not taking properly into account the fog when in distant mode and with a close far plane (case 1367993).
- Fixed overwriting of preview camera background color. [case 1357004](https://issuetracker.unity3d.com/product/unity/issues/guid/1361557/)
- Fixed selection of light types (point, area, directional) for path-traced Unlit shadow mattes.
- Fixed precision issues with the scene voxelization for APV, especially with geometry at the origin.

## [13.0.0] - 2021-09-01

Expand Down

0 comments on commit cbb6423

Please sign in to comment.