Insert float epsilon to prevent NaN and other artifacts in infinite perspectives
This commit is contained in:
parent
d798d1328e
commit
e1205662ec
3 changed files with 3 additions and 5 deletions
|
@ -31,9 +31,9 @@ Matrix4x4 transform::infinite_perspective(const float field_of_view, const float
|
||||||
Matrix4x4 result(0.0f);
|
Matrix4x4 result(0.0f);
|
||||||
result[0][0] = (2.0f * z_near) / (right - left);
|
result[0][0] = (2.0f * z_near) / (right - left);
|
||||||
result[1][1] = (2.0f * z_near) / (top - bottom);
|
result[1][1] = (2.0f * z_near) / (top - bottom);
|
||||||
result[2][2] = 1.0f;
|
result[2][2] = 1.0f - std::numeric_limits<float>::epsilon(); // prevent NaN
|
||||||
result[2][3] = 1.0f;
|
result[2][3] = 1.0f;
|
||||||
result[3][2] = -2.0 * z_near;
|
result[3][2] = -(2.0 - std::numeric_limits<float>::epsilon()) * z_near;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -683,7 +683,6 @@ void Renderer::create_mesh_pipeline(Material& material) {
|
||||||
pipelineInfo.render_pass = offscreenRenderPass;
|
pipelineInfo.render_pass = offscreenRenderPass;
|
||||||
pipelineInfo.depth.depth_mode = GFXDepthMode::Less;
|
pipelineInfo.depth.depth_mode = GFXDepthMode::Less;
|
||||||
pipelineInfo.rasterization.culling_mode = GFXCullingMode::Backface;
|
pipelineInfo.rasterization.culling_mode = GFXCullingMode::Backface;
|
||||||
//pipelineInfo.blending.enable_blending = true;
|
|
||||||
pipelineInfo.blending.src_rgb = GFXBlendFactor::SrcAlpha;
|
pipelineInfo.blending.src_rgb = GFXBlendFactor::SrcAlpha;
|
||||||
pipelineInfo.blending.dst_rgb = GFXBlendFactor::OneMinusSrcAlpha;
|
pipelineInfo.blending.dst_rgb = GFXBlendFactor::OneMinusSrcAlpha;
|
||||||
|
|
||||||
|
|
|
@ -193,8 +193,7 @@ void CommonEditor::update(float deltaTime) {
|
||||||
Vector4 ray_start = view_proj_inverse * Vector4(n.x, n.y, 0.0f, 1.0f);
|
Vector4 ray_start = view_proj_inverse * Vector4(n.x, n.y, 0.0f, 1.0f);
|
||||||
ray_start *= 1.0f / ray_start.w;
|
ray_start *= 1.0f / ray_start.w;
|
||||||
|
|
||||||
// note: we take the lowest visible floating point below 1.0 because we use infinite perspective martrix. if we simply inserted 1.0, then it would return NaN
|
Vector4 ray_end = view_proj_inverse * Vector4(n.x, n.y, 1.0f, 1.0f);
|
||||||
Vector4 ray_end = view_proj_inverse * Vector4(n.x, n.y, 1.0f - std::numeric_limits<float>::epsilon(), 1.0f);
|
|
||||||
ray_end *= 1.0f / ray_end.w;
|
ray_end *= 1.0f / ray_end.w;
|
||||||
|
|
||||||
Ray camera_ray;
|
Ray camera_ray;
|
||||||
|
|
Reference in a new issue