Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Dinges <blender@dingto.org>2015-05-13 17:04:43 +0300
committerThomas Dinges <blender@dingto.org>2015-05-13 17:05:30 +0300
commit0a6e32173eaeaf35d194a8787458cb05194854a2 (patch)
tree19baa6049fe6b6646d3b9eb39fa425dc8e67be69 /intern/cycles/kernel/kernel_light.h
parent730e61b446879f71eae7267de42026069a53d66f (diff)
Cleanup / Cycles: De-Duplicate Portal data fetch and side check.
Diffstat (limited to 'intern/cycles/kernel/kernel_light.h')
-rw-r--r--intern/cycles/kernel/kernel_light.h51
1 files changed, 25 insertions, 26 deletions
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index 704fb49efc9..39839472737 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -249,6 +249,25 @@ float background_map_pdf(KernelGlobals *kg, float3 direction)
return (cdf_u.x * cdf_v.x)/(M_2PI_F * M_PI_F * sin_theta * denom);
}
+ccl_device_inline bool background_portal_data_fetch_and_check_side(KernelGlobals *kg,
+ float3 P,
+ int index,
+ float3 *lightpos,
+ float3 *dir)
+{
+ float4 data0 = kernel_tex_fetch(__light_data, (index + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 0);
+ float4 data3 = kernel_tex_fetch(__light_data, (index + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 3);
+
+ *lightpos = make_float3(data0.y, data0.z, data0.w);
+ *dir = make_float3(data3.y, data3.z, data3.w);
+
+ /* Check whether portal is on the right side. */
+ if(dot(*dir, P - *lightpos) > 1e-5f)
+ return true;
+
+ return false;
+}
+
ccl_device float background_portal_pdf(KernelGlobals *kg,
float3 P,
float3 direction,
@@ -261,19 +280,9 @@ ccl_device float background_portal_pdf(KernelGlobals *kg,
if(p == ignore_portal)
continue;
- /* TODO(sergey): Consider moving portal data fetch to a
- * dedicated function.
- */
- float4 data0 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 0);
- float4 data3 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 3);
-
- float3 lightpos = make_float3(data0.y, data0.z, data0.w);
- float3 dir = make_float3(data3.y, data3.z, data3.w);
-
- if(dot(dir, P - lightpos) <= 1e-5f) {
- /* P is on the wrong side or too close. */
+ float3 lightpos, dir;
+ if(!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir))
continue;
- }
if(is_possible) {
/* There's a portal that could be sampled from this position. */
@@ -310,13 +319,8 @@ ccl_device int background_num_possible_portals(KernelGlobals *kg, float3 P)
{
int num_possible_portals = 0;
for(int p = 0; p < kernel_data.integrator.num_portals; p++) {
- float4 data0 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 0);
- float4 data3 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 3);
- float3 lightpos = make_float3(data0.y, data0.z, data0.w);
- float3 dir = make_float3(data3.y, data3.z, data3.w);
-
- /* Check whether portal is on the right side. */
- if(dot(dir, P - lightpos) > 1e-5f)
+ float3 lightpos, dir;
+ if(background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir))
num_possible_portals++;
}
return num_possible_portals;
@@ -340,13 +344,8 @@ ccl_device float3 background_portal_sample(KernelGlobals *kg,
*/
for(int p = 0; p < kernel_data.integrator.num_portals; p++) {
/* Search for the sampled portal. */
- float4 data0 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 0);
- float4 data3 = kernel_tex_fetch(__light_data, (p + kernel_data.integrator.portal_offset)*LIGHT_SIZE + 3);
- float3 lightpos = make_float3(data0.y, data0.z, data0.w);
- float3 dir = make_float3(data3.y, data3.z, data3.w);
-
- /* Check whether portal is on the right side. */
- if(dot(dir, P - lightpos) <= 1e-5f)
+ float3 lightpos, dir;
+ if(!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir))
continue;
if(portal == 0) {