Skip to content

Commit bff35ab

Browse files
Scale pointcloud points with distance (#169)
* Scale pointcloud points with distance Signed-off-by: Mateusz Wasilewski <mateusz.wasilewski@robotec.ai> * Bump Pointcloud Gem to 3.0.2 Signed-off-by: Mateusz Wasilewski <mateusz.wasilewski@robotec.ai> --------- Signed-off-by: Mateusz Wasilewski <mateusz.wasilewski@robotec.ai>
1 parent 1b9f713 commit bff35ab

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Gems/Pointcloud/Assets/Shaders/Pointclouds/Pointclouds.azsl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@ struct VSOutput
3030
[[vk::builtin("PointSize")]] float PointSize : PSIZE;
3131
};
3232

33+
float LinearizeDepth(const float depth)
34+
{
35+
return ViewSrg::GetFarZTimesNearZ() / (ViewSrg::GetFarZ() - depth * ViewSrg::GetFarZMinusNearZ());
36+
}
37+
38+
float GetPointSize(float4 position)
39+
{
40+
// Arbitrary scale factor to adjust point size falloff with depth.
41+
// Value of 10.0 results in points with m_pointSize of 1.0 appearing as if they are 1cm in diameter.
42+
const float depthScale = 10.0;
43+
44+
float depth = position.z / position.w;
45+
float linearDepth = LinearizeDepth(depth) / depthScale;
46+
float pointSize = PerDrawSrg::m_pointSize / linearDepth;
47+
48+
return pointSize;
49+
}
50+
3351
VSOutput MainVS(VSInput IN)
3452
{
3553
VSOutput OUT;
3654
const float4 pos = float4(IN.m_position, 1.0);
3755
const float4 pos2 = mul(PerDrawSrg::m_modelMatrix, pos);
3856
OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, pos2);
3957
OUT.m_color = IN.m_color;
40-
OUT.PointSize = PerDrawSrg::m_pointSize;
58+
OUT.PointSize = GetPointSize(OUT.m_position);
4159
return OUT;
4260
};
4361

0 commit comments

Comments
 (0)