[Bf-blender-cvs] [826086c7be2] soc-2022-many-lights-sampling: WIP: handle single- or double-sided emissive triangles differently
Weizhen Huang
noreply at git.blender.org
Wed Nov 16 16:47:01 CET 2022
Commit: 826086c7be2c05ad8a46209881bb81606c0e1bd0
Author: Weizhen Huang
Date: Wed Nov 16 16:45:53 2022 +0100
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rB826086c7be2c05ad8a46209881bb81606c0e1bd0
WIP: handle single- or double-sided emissive triangles differently
===================================================================
M intern/cycles/scene/light.cpp
M intern/cycles/scene/light_tree.cpp
M intern/cycles/scene/light_tree.h
===================================================================
diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp
index af6623811a5..ffa5c28ea22 100644
--- a/intern/cycles/scene/light.cpp
+++ b/intern/cycles/scene/light.cpp
@@ -295,7 +295,7 @@ void LightManager::device_update_distribution(Device *device,
if (light->is_enabled) {
if (light_tree_enabled) {
/* -prim_id - 1 is a light source index. */
- LightTreePrimitive light_prim(scene, ~device_light_index, scene_light_index);
+ LightTreePrimitive light_prim(scene, ~device_light_index, scene_light_index, false);
/* Distant lights get added to a separate vector. */
if (light->light_type == LIGHT_DISTANT || light->light_type == LIGHT_BACKGROUND) {
@@ -320,6 +320,8 @@ void LightManager::device_update_distribution(Device *device,
/* Similarly, we also want to keep track of the index of triangles that are emissive. */
int object_id = 0;
+ /* TODO: add an option in the UI */
+ bool is_double_sided = true;
foreach (Object *object, scene->objects) {
if (progress.get_cancel())
return;
@@ -345,7 +347,7 @@ void LightManager::device_update_distribution(Device *device,
if (shader->get_use_mis() && shader->has_surface_emission) {
if (light_tree_enabled) {
- LightTreePrimitive light_prim(scene, i, object_id);
+ LightTreePrimitive light_prim(scene, i, object_id, is_double_sided);
light_prims.push_back(light_prim);
}
diff --git a/intern/cycles/scene/light_tree.cpp b/intern/cycles/scene/light_tree.cpp
index c9891fe6544..4838903522b 100644
--- a/intern/cycles/scene/light_tree.cpp
+++ b/intern/cycles/scene/light_tree.cpp
@@ -59,8 +59,11 @@ OrientationBounds merge(const OrientationBounds &cone_a, const OrientationBounds
return OrientationBounds({new_axis, theta_o, theta_e});
}
-LightTreePrimitive::LightTreePrimitive(Scene *scene, int prim_id, int object_id)
- : prim_id(prim_id), object_id(object_id)
+LightTreePrimitive::LightTreePrimitive(Scene *scene,
+ int prim_id,
+ int object_id,
+ bool is_double_sided)
+ : prim_id(prim_id), object_id(object_id), is_double_sided(is_double_sided)
{
if (is_triangle()) {
calculate_triangle_vertices(scene);
@@ -148,11 +151,16 @@ void LightTreePrimitive::calculate_bcone(Scene *scene)
bcone = OrientationBounds::empty;
if (is_triangle()) {
- bcone.axis = safe_normalize(cross(vertices[1] - vertices[0], vertices[2] - vertices[0]));
+ if (is_double_sided) {
+ /* Any vector in the plane */
+ bcone.axis = safe_normalize(vertices[0] - vertices[1]);
+ bcone.theta_o = M_PI_2_F;
+ }
+ else {
+ bcone.axis = safe_normalize(cross(vertices[1] - vertices[0], vertices[2] - vertices[0]));
+ bcone.theta_o = 0;
+ }
- /* TODO: instance emissive triangle twice in the light tree when it is double-sided. Right now,
- * we assume that the normal axis is within pi radians of the triangle normal. */
- bcone.theta_o = M_PI_F;
bcone.theta_e = M_PI_2_F;
}
else {
diff --git a/intern/cycles/scene/light_tree.h b/intern/cycles/scene/light_tree.h
index 19d21c1872a..670590f44fc 100644
--- a/intern/cycles/scene/light_tree.h
+++ b/intern/cycles/scene/light_tree.h
@@ -63,6 +63,7 @@ struct LightTreePrimitive {
/* Only used for emissive triangles */
float3 vertices[3];
+ bool is_double_sided;
float3 centroid;
BoundBox bbox;
@@ -70,7 +71,7 @@ struct LightTreePrimitive {
float energy;
int prim_num;
- LightTreePrimitive(Scene *scene, int prim_id, int object_id);
+ LightTreePrimitive(Scene *scene, int prim_id, int object_id, bool is_double_sided);
void calculate_triangle_vertices(Scene *scene);
void calculate_centroid(Scene *scene);
void calculate_bbox(Scene *scene);
More information about the Bf-blender-cvs
mailing list