From 5b7eaa8e1c7183982ec916d5c2962a0e3882be7d Mon Sep 17 00:00:00 2001
From: Ivan 'provod' Avdeev <me@w23.ru>
Date: Thu, 22 Apr 2021 10:42:19 -0700
Subject: [PATCH] rtx: fix light surfaces bleeding backwards

---
 ref_vk/TODO.md          | 23 +++++++++++++++--------
 ref_vk/shaders/rtx.comp |  4 ++--
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/ref_vk/TODO.md b/ref_vk/TODO.md
index 05cbf64c..ec4357e2 100644
--- a/ref_vk/TODO.md
+++ b/ref_vk/TODO.md
@@ -1,24 +1,26 @@
-## 2021-04-19
-- [x] rtx: light intensity-based light clusters visibility
-- [x] rtx: check multiple variants of texture name (wad and non-wad)
-- [x] rtx: rad liquids/xeno/... textures
+## 2021-04-22
+- [x] rtx: fix backlight glitch
 
 # Next
+- [ ] rtx: dynamic surface lights / dynamic light clusters
+- [ ] rtx: better light culling: normal, bsp visibility, light volumes and intensity, ...
+- [ ] rtx: live rad file reloading (or other solution for tuning lights)
 - [ ] rtx: restore studio models
-- [ ] rtx: textures
 - [ ] rtx: restore dynamic stuff like particles, beams, etc
+- [ ] rtx: textures
 - [ ] rtx: emissive particles
 - [ ] rtx: better random
 - [ ] rtx: some studio models have glitchy geometry
 - [ ] rtx: simple convolution denoise (bilateral?)
-- [ ] rtx: live rad file reloading (or other solution for tuning lights)
 - [ ] rtx: map name to rad files mapping
 - [ ] water surfaces
-- [ ] rtx: better light culling: normal, bsp visibility, light volumes and intensity, ...
-- [ ] rtx: dynamic surface lights / dynamic light clusters
 - [ ] rtx: cluster dlights
 - [ ] rtx: entity lights
 - [ ] rtx: light styles
+- [ ] rtx: dynamically sized light clusters
+	Split into 2 buffers:
+		struct LightCluster { uint16 offset, length; }
+		uint8_t data[];
 
 # Planned
 - [ ] rtx: denoise
@@ -204,3 +206,8 @@
 
 ## 2021-04-17
 - [x] rtx: read rad file data
+
+## 2021-04-19
+- [x] rtx: light intensity-based light clusters visibility
+- [x] rtx: check multiple variants of texture name (wad and non-wad)
+- [x] rtx: rad liquids/xeno/... textures
diff --git a/ref_vk/shaders/rtx.comp b/ref_vk/shaders/rtx.comp
index 29ee3450..e3731344 100644
--- a/ref_vk/shaders/rtx.comp
+++ b/ref_vk/shaders/rtx.comp
@@ -286,7 +286,7 @@ void main() {
 		const Kusok kusok = kusochki[kusok_index];
 		//const uint leaf = kusochki[kusok_index].leaf-1;
 
-		//C = fract(pos / 256.);	break;
+		//C = fract(pos / LIGHT_GRID_CELL_SIZE);	break;
 		//C = vec3(hash(float(geom_index)), hash(float(geom_index)+15.43), hash(float(geom_index)+34.));
 		//C = vec3(hash(float(leaf)), hash(float(leaf)+15.43), hash(float(leaf)+34.));
 		//C = vec3(hash(float(leaf)), float(kusok.num_surface_lights) / 63., float(kusok.is_emissive));
@@ -384,7 +384,7 @@ void main() {
 					// const vec3 n3 = vertices[vi3].normal;
 
 					vec3 light_dir = sample_pos - pos;
-					if (dot(light_dir, normal) <= 0.) {
+					if (dot(light_dir, n1) >= 0.) {
 						//C = vec3(1., 0., 1.);
 						continue;
 					}