[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54210] trunk/blender/intern/cycles: Cycles: make multiple importance sampling for lamps an option per lamp now ,
Brecht Van Lommel
brechtvanlommel at pandora.be
Wed Jan 30 16:57:15 CET 2013
Revision: 54210
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54210
Author: blendix
Date: 2013-01-30 15:57:15 +0000 (Wed, 30 Jan 2013)
Log Message:
-----------
Cycles: make multiple importance sampling for lamps an option per lamp now,
disabled by default for backwards compatibility.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Integrator
Modified Paths:
--------------
trunk/blender/intern/cycles/blender/addon/properties.py
trunk/blender/intern/cycles/blender/addon/ui.py
trunk/blender/intern/cycles/blender/blender_object.cpp
trunk/blender/intern/cycles/kernel/kernel_emission.h
trunk/blender/intern/cycles/kernel/kernel_light.h
trunk/blender/intern/cycles/kernel/kernel_path.h
trunk/blender/intern/cycles/kernel/kernel_types.h
trunk/blender/intern/cycles/render/light.cpp
trunk/blender/intern/cycles/render/light.h
Modified: trunk/blender/intern/cycles/blender/addon/properties.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/properties.py 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/blender/addon/properties.py 2013-01-30 15:57:15 UTC (rev 54210)
@@ -462,8 +462,8 @@
type=cls,
)
cls.sample_as_light = BoolProperty(
- name="Sample as Lamp",
- description="Use direct light sampling for this material, "
+ name="Multiple Importance Sample",
+ description="Use multiple importance sampling for this material, "
"disabling may reduce overall noise for large "
"objects that emit little light compared to other light sources",
default=True,
@@ -499,6 +499,12 @@
min=1, max=10000,
default=1,
)
+ cls.use_multiple_importance_sampling = BoolProperty(
+ name="Multiple Importance Sample",
+ description="Use multiple importance sampling for the lamp, "
+ "reduces noise for area lamps and sharp glossy materials",
+ default=False,
+ )
@classmethod
def unregister(cls):
@@ -514,8 +520,8 @@
type=cls,
)
cls.sample_as_light = BoolProperty(
- name="Sample as Lamp",
- description="Use direct light sampling for the environment, "
+ name="Multiple Importance Sample",
+ description="Use multiple importance sampling for the environment, "
"enabling for non-solid colors is recommended",
default=False,
)
Modified: trunk/blender/intern/cycles/blender/addon/ui.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/ui.py 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/blender/addon/ui.py 2013-01-30 15:57:15 UTC (rev 54210)
@@ -574,6 +574,8 @@
col = split.column()
col.prop(clamp, "cast_shadow")
+ layout.prop(clamp, "use_multiple_importance_sampling")
+
if lamp.type == 'HEMI':
layout.label(text="Not supported, interpreted as sun lamp.")
@@ -807,10 +809,11 @@
col.prop(mat, "diffuse_color", text="Viewport Color")
col = split.column()
- col.prop(cmat, "sample_as_light")
col.prop(mat, "pass_index")
+ layout.prop(cmat, "sample_as_light")
+
class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
bl_label = ""
bl_context = "texture"
Modified: trunk/blender/intern/cycles/blender/blender_object.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_object.cpp 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/blender/blender_object.cpp 2013-01-30 15:57:15 UTC (rev 54210)
@@ -156,6 +156,7 @@
/* shadow */
PointerRNA clamp = RNA_pointer_get(&b_lamp.ptr, "cycles");
light->cast_shadow = get_boolean(clamp, "cast_shadow");
+ light->use_mis = get_boolean(clamp, "use_multiple_importance_sampling");
light->samples = get_int(clamp, "samples");
/* tag */
Modified: trunk/blender/intern/cycles/kernel/kernel_emission.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_emission.h 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/kernel/kernel_emission.h 2013-01-30 15:57:15 UTC (rev 54210)
@@ -93,7 +93,7 @@
}
/* return lamp index for MIS */
- if(ls.use_mis)
+ if(ls.shader & SHADER_USE_MIS)
*lamp = ls.lamp;
else
*lamp= ~0;
@@ -114,7 +114,7 @@
shader_bsdf_eval(kg, sd, ls.D, eval, &bsdf_pdf);
- if(ls.use_mis) {
+ if(ls.shader & SHADER_USE_MIS) {
/* multiple importance sampling */
float mis_weight = power_heuristic(ls.pdf, bsdf_pdf);
light_eval *= mis_weight;
Modified: trunk/blender/intern/cycles/kernel/kernel_light.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_light.h 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/kernel/kernel_light.h 2013-01-30 15:57:15 UTC (rev 54210)
@@ -31,7 +31,6 @@
int prim; /* primitive id for triangle/curve ligths */
int shader; /* shader id */
int lamp; /* lamp id */
- int use_mis; /* for lamps with size zero */
LightType type; /* type of light */
} LightSample;
@@ -218,11 +217,10 @@
LightType type = (LightType)__float_as_int(data0.x);
ls->type = type;
-#ifdef __LAMP_MIS__
- ls->use_mis = true;
-#else
- ls->use_mis = false;
-#endif
+ ls->shader = __float_as_int(data1.x);
+ ls->object = ~0;
+ ls->prim = ~0;
+ ls->lamp = lamp;
if(type == LIGHT_DISTANT) {
/* distant light */
@@ -233,10 +231,6 @@
if(radius > 0.0f)
D = distant_light_sample(D, radius, randu, randv);
-#ifdef __LAMP_MIS__
- else
- ls->use_mis = false;
-#endif
ls->P = D;
ls->Ng = D;
@@ -257,9 +251,6 @@
ls->D = -D;
ls->t = FLT_MAX;
ls->eval_fac = 1.0f;
-#ifndef __LAMP_MIS__
- ls->use_mis = true;
-#endif
}
#endif
else {
@@ -271,10 +262,6 @@
if(radius > 0.0f)
/* sphere light */
ls->P += sphere_light_sample(P, ls->P, radius, randu, randv);
-#ifdef __LAMP_MIS__
- else
- ls->use_mis = false;
-#endif
ls->D = normalize_len(ls->P - P, &ls->t);
ls->Ng = -ls->D;
@@ -304,13 +291,6 @@
float invarea = data2.x;
- if(invarea == 0.0f) {
-#ifdef __LAMP_MIS__
- ls->use_mis = false;
-#endif
- invarea = 1.0f;
- }
-
ls->eval_fac = 0.25f*invarea;
ls->pdf = invarea;
}
@@ -318,11 +298,6 @@
ls->eval_fac *= kernel_data.integrator.inv_pdf_lights;
ls->pdf *= lamp_light_pdf(kg, ls->Ng, -ls->D, ls->t);
}
-
- ls->shader = __float_as_int(data1.x);
- ls->object = ~0;
- ls->prim = ~0;
- ls->lamp = lamp;
}
__device bool lamp_light_eval(KernelGlobals *kg, int lamp, float3 P, float3 D, float t, LightSample *ls)
@@ -336,7 +311,6 @@
ls->object = ~0;
ls->prim = ~0;
ls->lamp = lamp;
- ls->use_mis = false; /* flag not used for eval */
if(type == LIGHT_DISTANT) {
/* distant light */
@@ -475,7 +449,7 @@
ls->object = object;
ls->prim = prim;
ls->lamp = ~0;
- ls->use_mis = true;
+ ls->shader |= SHADER_USE_MIS;
ls->t = 0.0f;
ls->type = LIGHT_AREA;
ls->eval_fac = 1.0f;
@@ -529,11 +503,10 @@
ls->object = object;
ls->prim = prim;
ls->lamp = ~0;
- ls->use_mis = true;
ls->t = 0.0f;
ls->type = LIGHT_STRAND;
ls->eval_fac = 1.0f;
- ls->shader = __float_as_int(v00.z);
+ ls->shader = __float_as_int(v00.z) | SHADER_USE_MIS;
object_transform_light_sample(kg, ls, object, time);
}
Modified: trunk/blender/intern/cycles/kernel/kernel_path.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_path.h 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/kernel/kernel_path.h 2013-01-30 15:57:15 UTC (rev 54210)
@@ -254,7 +254,7 @@
bool hit = scene_intersect(kg, &ray, visibility, &isect);
#ifdef __LAMP_MIS__
- if(kernel_data.integrator.pdf_lights > 0.0f && !(state.flag & PATH_RAY_CAMERA)) {
+ if(kernel_data.integrator.use_lamp_mis && !(state.flag & PATH_RAY_CAMERA)) {
/* ray starting from previous non-transparent bounce */
Ray light_ray;
@@ -501,7 +501,7 @@
bool hit = scene_intersect(kg, &ray, visibility, &isect);
#ifdef __LAMP_MIS__
- if(kernel_data.integrator.pdf_lights > 0.0f && !(state.flag & PATH_RAY_CAMERA)) {
+ if(kernel_data.integrator.use_lamp_mis && !(state.flag & PATH_RAY_CAMERA)) {
/* ray starting from previous non-transparent bounce */
Ray light_ray;
Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h 2013-01-30 15:57:15 UTC (rev 54210)
@@ -288,8 +288,9 @@
SHADER_SMOOTH_NORMAL = (1 << 31),
SHADER_CAST_SHADOW = (1 << 30),
SHADER_AREA_LIGHT = (1 << 29),
+ SHADER_USE_MIS = (1 << 28),
- SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT)
+ SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT|SHADER_USE_MIS)
} ShaderFlag;
/* Light Type */
@@ -680,7 +681,7 @@
int transmission_samples;
int ao_samples;
int mesh_light_samples;
- int pad1;
+ int use_lamp_mis;
} KernelIntegrator;
typedef struct KernelBVH {
Modified: trunk/blender/intern/cycles/render/light.cpp
===================================================================
--- trunk/blender/intern/cycles/render/light.cpp 2013-01-30 15:55:13 UTC (rev 54209)
+++ trunk/blender/intern/cycles/render/light.cpp 2013-01-30 15:57:15 UTC (rev 54210)
@@ -115,6 +115,8 @@
spot_smooth = 0.0f;
cast_shadow = true;
+ use_mis = false;
+
shader = 0;
samples = 1;
}
@@ -291,13 +293,19 @@
/* point lights */
float lightarea = (totarea > 0.0f)? totarea/scene->lights.size(): 1.0f;
+ bool use_lamp_mis = false;
for(int i = 0; i < scene->lights.size(); i++, offset++) {
+ Light *light = scene->lights[i];
+
distribution[offset].x = totarea;
distribution[offset].y = __int_as_float(~(int)i);
distribution[offset].z = 1.0f;
- distribution[offset].w = scene->lights[i]->size;
+ distribution[offset].w = light->size;
totarea += lightarea;
+
+ if(light->size > 0.0f && light->use_mis)
+ use_lamp_mis = true;
}
/* normalize cumulative distribution functions */
@@ -344,6 +352,8 @@
kintegrator->inv_pdf_lights = 1.0f/kintegrator->pdf_lights;
}
+ kintegrator->use_lamp_mis = use_lamp_mis;
+
/* CDF */
device->tex_alloc("__light_distribution", dscene->light_distribution);
}
@@ -355,6 +365,7 @@
kintegrator->pdf_triangles = 0.0f;
kintegrator->pdf_lights = 0.0f;
kintegrator->inv_pdf_lights = 0.0f;
+ kintegrator->use_lamp_mis = false;
}
}
@@ -484,6 +495,9 @@
float radius = light->size;
float invarea = (radius > 0.0f)? 1.0f/(M_PI_F*radius*radius): 1.0f;
+ if(light->use_mis && radius > 0.0f)
+ shader_id |= SHADER_USE_MIS;
+
light_data[i*LIGHT_SIZE + 0] = make_float4(__int_as_float(light->type), co.x, co.y, co.z);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list