Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doublesided area lights support #72

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
2 changes: 2 additions & 0 deletions SceneBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ struct spot_light_desc_t {
struct rect_light_desc_t {
float color[3] = {1.0f, 1.0f, 1.0f};
float width = 1.0f, height = 1.0f;
bool doublesided = false;
bool sky_portal = false;
bool visible = true;
bool cast_shadow = true;
Expand All @@ -245,6 +246,7 @@ struct rect_light_desc_t {
struct disk_light_desc_t {
float color[3] = {1.0f, 1.0f, 1.0f};
float size_x = 1.0f, size_y = 1.0f;
bool doublesided = false;
bool sky_portal = false;
bool visible = true;
bool cast_shadow = true;
Expand Down
12 changes: 7 additions & 5 deletions internal/SceneCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ Ray::LightHandle Ray::Cpu::Scene::AddLight(const rect_light_desc_t &_l, const fl
light_t l = {};

l.type = LIGHT_TYPE_RECT;
l.doublesided = _l.doublesided;
l.visible = _l.visible;
l.cast_shadow = _l.cast_shadow;
l.sky_portal = _l.sky_portal;
Expand Down Expand Up @@ -689,6 +690,7 @@ Ray::LightHandle Ray::Cpu::Scene::AddLight(const disk_light_desc_t &_l, const fl
light_t l = {};

l.type = LIGHT_TYPE_DISK;
l.doublesided = _l.doublesided;
l.visible = _l.visible;
l.cast_shadow = _l.cast_shadow;
l.sky_portal = _l.sky_portal;
Expand Down Expand Up @@ -813,10 +815,10 @@ Ray::MeshInstanceHandle Ray::Cpu::Scene::AddMeshInstance(const mesh_instance_des

new_lights.emplace_back();
light_t &new_light = new_lights.back();
new_light.visible = 0;
new_light.cast_shadow = 1;
new_light.type = LIGHT_TYPE_TRI;
new_light.doublesided = (back_emissive != 0xffff) ? 1 : 0;
new_light.cast_shadow = 1;
new_light.visible = 0;
new_light.sky_portal = 0;
new_light.ray_visibility = mi.ray_visibility;
new_light.ray_visibility &= ~RAY_TYPE_CAMERA_BIT;
Expand Down Expand Up @@ -1258,7 +1260,7 @@ void Ray::Cpu::Scene::RebuildLightTree_nolock() {
area = l.rect.area;

axis = normalize(Ray::Cpu::cross(u, v));
omega_n = 0.0f; // single normal
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_DISK: {
Expand All @@ -1272,7 +1274,7 @@ void Ray::Cpu::Scene::RebuildLightTree_nolock() {
area = l.disk.area;

axis = normalize(Ray::Cpu::cross(u, v));
omega_n = 0.0f; // single normal
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_TRI: {
Expand All @@ -1297,7 +1299,7 @@ void Ray::Cpu::Scene::RebuildLightTree_nolock() {
area = 0.5f * length(light_forward);

axis = normalize(light_forward);
omega_n = PI; // normals in all directions (triangle lights are double-sided)
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_ENV: {
Expand Down
8 changes: 5 additions & 3 deletions internal/SceneGPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ inline Ray::LightHandle Ray::NS::Scene::AddLight(const rect_light_desc_t &_l, co
light_t l = {};

l.type = LIGHT_TYPE_RECT;
l.doublesided = _l.doublesided;
l.visible = _l.visible;
l.cast_shadow = _l.cast_shadow;
l.sky_portal = _l.sky_portal;
Expand Down Expand Up @@ -1291,6 +1292,7 @@ inline Ray::LightHandle Ray::NS::Scene::AddLight(const disk_light_desc_t &_l, co
light_t l = {};

l.type = LIGHT_TYPE_DISK;
l.doublesided = _l.doublesided;
l.visible = _l.visible;
l.cast_shadow = _l.cast_shadow;
l.sky_portal = _l.sky_portal;
Expand Down Expand Up @@ -2276,7 +2278,7 @@ inline void Ray::NS::Scene::RebuildLightTree_nolock() {
area = l.rect.area;

axis = normalize(NS::cross(u, v));
omega_n = 0.0f; // single normal
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_DISK: {
Expand All @@ -2290,7 +2292,7 @@ inline void Ray::NS::Scene::RebuildLightTree_nolock() {
area = l.disk.area;

axis = normalize(NS::cross(u, v));
omega_n = 0.0f; // single normal
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_TRI: {
Expand All @@ -2315,7 +2317,7 @@ inline void Ray::NS::Scene::RebuildLightTree_nolock() {
area = 0.5f * length(light_forward);

axis = normalize(light_forward);
omega_n = PI; // normals in all directions (triangle lights are double-sided)
omega_n = l.doublesided ? PI : 0.0f;
omega_e = PI / 2.0f;
} break;
case LIGHT_TYPE_ENV: {
Expand Down
Loading