fog clipping

The frustum now respect the maximum fog distance. It should roughly match the previous far plane (though it is a lot more precise than before). It will improve performance a lot when being submerged in fluids or have blindness effect. Maybe it does fix some skin/entity renderer issues in the distance
This commit is contained in:
Moritz Zwerger 2024-03-01 15:41:47 +01:00
parent b6b106ef83
commit 41880b0ada
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -95,7 +95,12 @@ class MatrixHandler(
}
private fun calculateProjectionMatrix(fov: Float, screenDimensions: Vec2 = context.window.sizef) {
projectionMatrix = GLM.perspective(fov.rad, screenDimensions.x / screenDimensions.y, NEAR_PLANE, FAR_PLANE)
val fog = camera.fogManager.state
var far = FAR_PLANE
if (fog.enabled) {
far = fog.end * (1.0f / 0.7f) + 2.0f // y axis is weighted differently
}
projectionMatrix = GLM.perspective(fov.rad, screenDimensions.x / screenDimensions.y, NEAR_PLANE, maxOf(far, 5.0f))
}
fun init() {

View File

@ -42,7 +42,7 @@ float fog_alpha_from_distance(float distance2) {
float fog_calculate_distance() {
vec3 distance = finFragmentPosition.xyz - uCameraPosition.xyz;
distance.y *= 0.7f;// increase possible distance on y axis
distance.y *= 0.7f;// increase possible distance on y axis; if you change this, also update fog clipping in MatrixHandler.kt
return dot(distance, distance);
}