Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions engine/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -91,7 +92,7 @@ def as_array(self):
self.optical_density,
self.transparent,
self.dispersion_coefficient,
None
self.is_light,
]
return res

Expand Down
8 changes: 7 additions & 1 deletion shaders/render.frag
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct Material {
float opticalDensity;
bool transparent;
float dispersionCoefficient;
bool is_light;
};

struct Sphere {
Expand Down Expand Up @@ -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;
Expand Down