From 908f4006c183affcc4cfc0b1b251129b16381591 Mon Sep 17 00:00:00 2001 From: iv4n-t3a Date: Tue, 25 Feb 2025 14:10:31 +0300 Subject: [PATCH 1/2] Add light --- shaders/render.frag | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/shaders/render.frag b/shaders/render.frag index 526a650..7a7961c 100644 --- a/shaders/render.frag +++ b/shaders/render.frag @@ -33,6 +33,7 @@ struct Material { float opticalDensity; bool transparent; float dispersionCoefficient; + bool is_light; }; struct Sphere { @@ -316,9 +317,14 @@ float castRay(Ray ray) { return res * castRayWithSky(ray); } + res *= materials[material].color[ray.color]; + + if (materials[material].is_light) { + return res; + } + vec3 refvector = reflectOrRefract(ray, materials[material], refl.normal); ray = Ray(refl.intersection, refvector, ray.color, ray.opticalDensity, ray.isInside); - res *= materials[material].color[ray.color]; } return res; From 0b1abf75b788161688e2952bbe46598244f6be9a Mon Sep 17 00:00:00 2001 From: iv4n-t3a Date: Tue, 25 Feb 2025 14:11:12 +0300 Subject: [PATCH 2/2] Add light --- engine/scene.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/engine/scene.py b/engine/scene.py index a139a66..e67ad94 100644 --- a/engine/scene.py +++ b/engine/scene.py @@ -74,13 +74,14 @@ def blue(self): class Material(LoadableObject): - def __init__(self, color: Color, roughness: float, scene_loader, transparent: bool = False, optical_density: float = 1, dispersion_coefficient: float = 0.01): + def __init__(self, color: Color, roughness: float, scene_loader, transparent: bool = False, optical_density: float = 1, dispersion_coefficient: float = 0.01, is_light: bool = False): super().__init__() self.color = color self.roughness = roughness self.transparent = transparent self.optical_density = optical_density self.dispersion_coefficient = dispersion_coefficient + self.is_light = is_light self.index = scene_loader.new_material_index() @typing.override @@ -91,7 +92,7 @@ def as_array(self): self.optical_density, self.transparent, self.dispersion_coefficient, - None + self.is_light, ] return res