mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
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.
3.2 KiB
3.2 KiB
Библиотека gfx.posteffects
Библиотека для работы с эффектами пост-обработки.
Слот эффектов является ресурсом, и должен быть объявлен в resources.json в корневой директории пака:
{
"post-effect-slot": [
"имя_слота"
]
}
-- Возвращает индекс слота эффектов по имени (пак:имя_слота).
-- При отсутствии указанного слота возвращает -1
gfx.posteffects.index(name: string) -> int
-- Назначает эффект на слот
gfx.posteffects.set_effect(slot: int, effect: string)
-- Возвращает интенсивность эффекта (от 0.0 до 1.0)
-- Если слот пуст, возвращает 0.0
gfx.posteffects.get_intensity(slot: int) -> number
-- Устанавливает интенсивность эффекта (от 0.0 до 1.0)
-- (Корректность обработки параметра между значениями 0.0 и 1.0 зависит
-- от эффекта
gfx.posteffects.set_intensity(slot: int, intensity: number)
-- Возвращает true если слот не пуст и интенсивность эффекта ненулевая
gfx.posteffects.is_active(slot: int) -> boolean
-- Устанавливает значения параметров (директивы 'param')
gfx.posteffects.set_params(slot: int, params: table)
-- Устанавливает значения в массив
gfx.posteffects.set_array(
-- индекс слота эффектов
slot: int,
-- имя параметра (массива)
name: string
-- данные
data: Bytearray
)
-- Пример заполнения массива `#param vec3 u_имяМассива[64]`:
local buffer = Bytearray(0)
for i = 0, 63 do
local x = math.random() * 2.0 - 1.0
local y = math.random() * 2.0 - 1.0
local z = math.random() * 2.0 - 1.0
Bytearray.append(buffer, byteutil.pack("fff", x, y, z))
end
gfx.posteffects.set_array(slot, "u_имяМассива", Bytearray_as_string(buffer))
Координаты в шейдерах
Значения в мировом пространстве, доступные в шейдерах (u_cameraPos, u_view, u_inverseView, позиции вершин и моделей), заданы относительно начала координат рендера, а не начала координат мира. Начало координат рендера - целочисленная точка рядом с камерой: X и Z кратны 1024 блокам, Y равен 0. Так float сохраняет точность вдали от начала координат мира.
Направления, расстояния и позиции относительно камеры от начала координат рендера не зависят. Не зависит и эффект, привязанный к сетке блоков или повторяющийся с периодом, на который делится 1024.