mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
render the world relative to an origin near the camera
World coordinates were passed to GPU as floats: u_model of a chunk and of a model had the world translation, vertices of translucent blocks, particles, precipitation, block wrappers, lines and 3D texts were built in the world space, and the camera position was subtracted in shaders. The float step grows with the distance from the world origin (6 cm at 1M blocks, 2 m at 30M): blocks got skewed, then stuck together. Camera::getOrigin() is an integer point near the camera (X and Z are rounded to 1024 blocks, Y is 0). Camera::getView() is relative to it, and every position passed to GPU is "world - origin" calculated on CPU, so the shaders keep working with small numbers and do not change: u_cameraPos, a_modelpos, u_inverseView and the shadows matrices are in the same space as before, shifted by the origin. Matrices of a shadow map are converted from the origin of its camera to the origin of the player camera. The clouds shader gets the origin wrapped by the period of its waves, the waves stay bound to the world. Vertices of translucent blocks are local to the chunk now, as vertices of opaque ones, and drawn with u_model of the chunk.
This commit is contained in:
parent
e1f6daabb7
commit
89bdadd6aa
30 changed files with 283 additions and 127 deletions
|
|
@ -44,7 +44,10 @@ void TextsRenderer::renderNote(
|
|||
}
|
||||
}
|
||||
|
||||
if (util::distance2(pos, camera.position) >
|
||||
pos = util::to_local(pos, camera.getOrigin());
|
||||
const glm::vec3 cameraPos = camera.getLocalPosition();
|
||||
|
||||
if (util::distance2(pos, cameraPos) >
|
||||
util::sqr(preset.renderDistance / camera.zoom)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -70,7 +73,7 @@ void TextsRenderer::renderNote(
|
|||
int height = font.getLineHeight();
|
||||
if (preset.displayMode == NoteDisplayMode::Y_FREE_BILLBOARD ||
|
||||
preset.displayMode == NoteDisplayMode::XY_FREE_BILLBOARD) {
|
||||
xvec = camera.position - pos;
|
||||
xvec = cameraPos - pos;
|
||||
xvec.y = 0;
|
||||
std::swap(xvec.x, xvec.z);
|
||||
xvec.z *= -1;
|
||||
|
|
@ -80,9 +83,7 @@ void TextsRenderer::renderNote(
|
|||
}
|
||||
float scale =
|
||||
(1.0f - preset.perspective) *
|
||||
glm::pow(
|
||||
glm::distance(camera.position, pos), 1.0f - preset.perspective
|
||||
);
|
||||
glm::pow(glm::distance(cameraPos, pos), 1.0f - preset.perspective);
|
||||
xvec *= 1.0f + scale;
|
||||
yvec *= 1.0f + scale;
|
||||
}
|
||||
|
|
@ -91,7 +92,7 @@ void TextsRenderer::renderNote(
|
|||
float scale = 1.0f;
|
||||
if (glm::abs(preset.perspective) > 0.0001f) {
|
||||
float scale2 =
|
||||
scale / (glm::distance(camera.position, pos) * camera.zoom *
|
||||
scale / (glm::distance(cameraPos, pos) * camera.zoom *
|
||||
glm::sqrt(glm::tan(camera.getFov() * 0.5f)));
|
||||
scale = scale2 * preset.perspective +
|
||||
scale * (1.0f - preset.perspective);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue