voxelcore/res/shaders/clouds.glslv
ostermine 89bdadd6aa 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.
2026-11-12 10:05:06 +03:00

52 lines
1.5 KiB
GLSL

#include <commons>
layout (location = 0) in vec3 v_position;
layout (location = 1) in vec2 v_texCoord;
layout (location = 2) in vec4 v_light;
layout (location = 3) in vec4 v_normal;
#include <world_vertex_header>
#include <lighting>
#include <fog>
#include <sky>
uniform float u_dayTime;
uniform vec2 u_waveOffset;
out vec4 a_torchLight;
void main() {
a_modelpos = u_model * vec4(v_position, 1.0f);
a_modelpos.xz += u_waveOffset;
a_modelpos.x += sin(u_timer * 0.05 + a_modelpos.z * 0.002) * 1.5;
a_modelpos.z += sin(u_timer * 0.2 + a_modelpos.x * 0.002) * 1.5;
a_modelpos.y += sin(u_timer * 0.1 + (a_modelpos.x + a_modelpos.z) * 0.001) * 2.0;
a_modelpos.xz -= u_waveOffset;
vec3 pos3d = a_modelpos.xyz - u_cameraPos;
a_realnormal = vec3(0.0, 1.0, 0.0);
a_normal = calc_screen_normal(a_realnormal);
a_torchLight = vec4(calc_torch_light(
v_light.rgb, a_realnormal, a_modelpos.xyz, u_torchlightColor, u_gamma
), 1.0);
a_texCoord = v_texCoord;
a_dir = a_modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_skybox, u_dayTime, u_minSkyLight);
a_skyLight = skyLightColor.rgb*v_light.a;
mat4 viewmodel = u_view * u_model;
a_distance = length(viewmodel * vec4(pos3d, 0.0));
#ifndef ADVANCED_RENDER
a_fog = calc_fog(length(viewmodel * vec4(pos3d * FOG_POS_SCALE, 0.0)) / 256.0);
#endif
a_emission = v_normal.w;
vec4 viewmodelpos = u_view * a_modelpos;
a_position = viewmodelpos.xyz;
gl_Position = u_proj * viewmodelpos;
}