Add screen-space contact shadows

TotK fills a full-resolution G-buffer with a B10G11R11 scene colour, an R32F linear depth and a D32F depth, lights it
in half resolution, and composites the lighting into the scene colour in one pass whose only target is that colour,
with a D16 class depth. vk_contact.c recognises both passes, and when the pass after the composite begins (or a
dispatch or copy comes first) runtime/shaders/contact_shadow.comp marches each pixel 16 steps toward the sun through
the linear depth and darkens the scene colour where nearby geometry blocks the ray: the small shadows at feet, under
stones and in grass that the shadow maps miss. Transparent surfaces, the sky and post-processing come after.

The projection, far plane and sun direction come from the fragment stage's 0x940-byte camera block (c4): c4[7].x,
c4[8].y, c4[14].y, and the first cascade's depth row c4[44].xyz, whose negation points toward the sun. Scene colour
images get STORAGE usage while the setting is on.

contact_shadows (percent strength, default 0) is in totk.ini.example and on the Screen tab of the menu (English and
Russian). TOTK_CONTACT_DEBUG=1 shows the shadow factor in grey instead of the frame. It costs about 0.45 ms per frame
at a 3840x2160 scene on an RTX 4080 SUPER.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
itaskaev2andClaude Opus 5.5 committed 2026-10-30 15:29:53 +01:00
1 parent 386e70453b
commit 4af60604de
15 files changed
+440 -3

No files matched your search

+6
View File
@@ -70,6 +70,9 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_SCALE] = "Shadow resolution",
[UI_MENU_SHADOW_SCALE_DESC] = "Draws the sun's shadow maps this many times larger on each side than the game's 960x960: "
"sharper shadow edges and leaf shadows. Takes effect at the next start.",
[UI_MENU_CONTACT_SHADOWS] = "Contact shadows",
[UI_MENU_CONTACT_SHADOWS_DESC] = "Small sun shadows the shadow maps miss: at feet, under stones, in grass and creases. "
"Traced on the screen after lighting. Takes effect at the next start.",
[UI_MENU_SHADOW_RANGE] = "Shadow cascade range",
[UI_MENU_SHADOW_RANGE_DESC] = "Moves the steps where shadows turn softer (the game's 20, 40, 80 and 160 m) further "
"away. Spreads the shadow map over more ground: raise Shadow resolution with it. "
@@ -299,6 +302,9 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_SCALE] = "Разрешение теней",
[UI_MENU_SHADOW_SCALE_DESC] = "Карты теней от солнца рисуются во столько раз больше по каждой стороне, чем 960x960 "
"самой игры: края теней и тени листвы чётче. Действует после перезапуска.",
[UI_MENU_CONTACT_SHADOWS] = "Контактные тени",
[UI_MENU_CONTACT_SHADOWS_DESC] = "Мелкие тени от солнца, которых нет на картах теней: у ног, под камнями, в траве и "
"складках. Считаются по экрану после освещения. Действует после перезапуска.",
[UI_MENU_SHADOW_RANGE] = "Дальность каскадов теней",
[UI_MENU_SHADOW_RANGE_DESC] = "Отодвигает границы, за которыми тени становятся мягче (в игре 20, 40, 80 и 160 м). "
"Карта теней растягивается на большую площадь, поэтому вместе с этим поднимайте "