[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45242] trunk/blender/intern/cycles: Cycles: shadow pass support.
Brecht Van Lommel
brechtvanlommel at pandora.be
Wed Mar 28 12:39:34 CEST 2012
Revision: 45242
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45242
Author: blendix
Date: 2012-03-28 10:39:21 +0000 (Wed, 28 Mar 2012)
Log Message:
-----------
Cycles: shadow pass support. Note that this only takes into account lamps,
emitting objects or world lighting do not contribute to the shadow pass.
Consider this more as a pass useful for some compositing tricks, unlike
other lighting passes this pass can't be used to exactly reconstruct the
combined pass.
Modified Paths:
--------------
trunk/blender/intern/cycles/blender/addon/ui.py
trunk/blender/intern/cycles/blender/blender_session.cpp
trunk/blender/intern/cycles/kernel/kernel_accumulate.h
trunk/blender/intern/cycles/kernel/kernel_emission.h
trunk/blender/intern/cycles/kernel/kernel_passes.h
trunk/blender/intern/cycles/kernel/kernel_path.h
trunk/blender/intern/cycles/kernel/kernel_types.h
trunk/blender/intern/cycles/render/buffers.cpp
trunk/blender/intern/cycles/render/film.cpp
Modified: trunk/blender/intern/cycles/blender/addon/ui.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/ui.py 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/blender/addon/ui.py 2012-03-28 10:39:21 UTC (rev 45242)
@@ -197,6 +197,7 @@
col.prop(rl, "use_pass_emit")
col.prop(rl, "use_pass_environment")
col.prop(rl, "use_pass_ambient_occlusion")
+ col.prop(rl, "use_pass_shadow")
col = split.column()
col.label()
Modified: trunk/blender/intern/cycles/blender/blender_session.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_session.cpp 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/blender/blender_session.cpp 2012-03-28 10:39:21 UTC (rev 45242)
@@ -160,9 +160,10 @@
return PASS_BACKGROUND;
case BL::RenderPass::type_AO:
return PASS_AO;
+ case BL::RenderPass::type_SHADOW:
+ return PASS_SHADOW;
case BL::RenderPass::type_DIFFUSE:
- case BL::RenderPass::type_SHADOW:
case BL::RenderPass::type_COLOR:
case BL::RenderPass::type_REFRACTION:
case BL::RenderPass::type_SPECULAR:
Modified: trunk/blender/intern/cycles/kernel/kernel_accumulate.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_accumulate.h 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/kernel/kernel_accumulate.h 2012-03-28 10:39:21 UTC (rev 45242)
@@ -136,6 +136,7 @@
L->emission = make_float3(0.0f, 0.0f, 0.0f);
L->background = make_float3(0.0f, 0.0f, 0.0f);
L->ao = make_float3(0.0f, 0.0f, 0.0f);
+ L->shadow = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
}
else
L->emission = make_float3(0.0f, 0.0f, 0.0f);
@@ -215,26 +216,35 @@
#endif
}
-__device_inline void path_radiance_accum_light(PathRadiance *L, float3 throughput, BsdfEval *bsdf_eval, int bounce)
+__device_inline void path_radiance_accum_light(PathRadiance *L, float3 throughput, BsdfEval *bsdf_eval, float3 shadow, int bounce, bool is_lamp)
{
#ifdef __PASSES__
if(L->use_light_pass) {
if(bounce == 0) {
/* directly visible lighting */
- L->direct_diffuse += throughput*bsdf_eval->diffuse;
- L->direct_glossy += throughput*bsdf_eval->glossy;
- L->direct_transmission += throughput*bsdf_eval->transmission;
+ L->direct_diffuse += throughput*bsdf_eval->diffuse*shadow;
+ L->direct_glossy += throughput*bsdf_eval->glossy*shadow;
+ L->direct_transmission += throughput*bsdf_eval->transmission*shadow;
+
+ if(is_lamp) {
+ float3 sum = throughput*(bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission);
+
+ L->shadow.x += shadow.x;
+ L->shadow.y += shadow.y;
+ L->shadow.z += shadow.z;
+ L->shadow.w += average(sum);
+ }
}
else {
/* indirectly visible lighting after BSDF bounce */
float3 sum = bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission;
- L->indirect += throughput*sum;
+ L->indirect += throughput*sum*shadow;
}
}
else
- L->emission += throughput*bsdf_eval->diffuse;
+ L->emission += throughput*bsdf_eval->diffuse*shadow;
#else
- *L += throughput*(*bsdf_eval);
+ *L += throughput*(*bsdf_eval)*shadow;
#endif
}
Modified: trunk/blender/intern/cycles/kernel/kernel_emission.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_emission.h 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/kernel/kernel_emission.h 2012-03-28 10:39:21 UTC (rev 45242)
@@ -60,7 +60,8 @@
}
__device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
- float randt, float rando, float randu, float randv, Ray *ray, BsdfEval *eval)
+ float randt, float rando, float randu, float randv, Ray *ray, BsdfEval *eval,
+ bool *is_lamp)
{
LightSample ls;
@@ -135,6 +136,8 @@
ray->t = 0.0f;
}
+ *is_lamp = (ls.prim == ~0);
+
return true;
}
Modified: trunk/blender/intern/cycles/kernel/kernel_passes.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_passes.h 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/kernel/kernel_passes.h 2012-03-28 10:39:21 UTC (rev 45242)
@@ -132,6 +132,8 @@
kernel_write_pass_float3(buffer + kernel_data.film.pass_glossy_color, sample, L->color_glossy);
if(flag & PASS_TRANSMISSION_COLOR)
kernel_write_pass_float3(buffer + kernel_data.film.pass_transmission_color, sample, L->color_transmission);
+ if(flag & PASS_SHADOW)
+ kernel_write_pass_float4(buffer + kernel_data.film.pass_shadow, sample, L->shadow);
#endif
}
Modified: trunk/blender/intern/cycles/kernel/kernel_path.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_path.h 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/kernel/kernel_path.h 2012-03-28 10:39:21 UTC (rev 45242)
@@ -327,6 +327,7 @@
Ray light_ray;
BsdfEval L_light;
+ bool is_lamp;
#ifdef __MULTI_LIGHT__
/* index -1 means randomly sample from distribution */
@@ -336,14 +337,13 @@
#else
const int i = -1;
#endif
- if(direct_emission(kg, &sd, i, light_t, light_o, light_u, light_v, &light_ray, &L_light)) {
+ if(direct_emission(kg, &sd, i, light_t, light_o, light_u, light_v, &light_ray, &L_light, &is_lamp)) {
/* trace shadow ray */
float3 shadow;
if(!shadow_blocked(kg, &state, &light_ray, &shadow)) {
/* accumulate */
- bsdf_eval_mul(&L_light, shadow);
- path_radiance_accum_light(&L, throughput, &L_light, state.bounce);
+ path_radiance_accum_light(&L, throughput, &L_light, shadow, state.bounce, is_lamp);
}
}
#ifdef __MULTI_LIGHT__
Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h 2012-03-28 10:39:21 UTC (rev 45242)
@@ -175,7 +175,8 @@
PASS_TRANSMISSION_DIRECT = 32768,
PASS_EMISSION = 65536,
PASS_BACKGROUND = 131072,
- PASS_AO = 262144
+ PASS_AO = 262144,
+ PASS_SHADOW = 524288
} PassType;
#define PASS_ALL (~0)
@@ -206,6 +207,8 @@
float3 indirect_diffuse;
float3 indirect_glossy;
float3 indirect_transmission;
+
+ float4 shadow;
} PathRadiance;
typedef struct BsdfEval {
@@ -464,7 +467,7 @@
int pass_emission;
int pass_background;
int pass_ao;
- int pass_pad2;
+ int pass_shadow;
} KernelFilm;
typedef struct KernelBackground {
Modified: trunk/blender/intern/cycles/render/buffers.cpp
===================================================================
--- trunk/blender/intern/cycles/render/buffers.cpp 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/render/buffers.cpp 2012-03-28 10:39:21 UTC (rev 45242)
@@ -186,15 +186,28 @@
assert(pass.components == components);
/* RGBA */
- for(int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
- float4 f = make_float4(in[0], in[1], in[2], in[3]);
+ if(type == PASS_SHADOW) {
+ for(int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
+ float4 f = make_float4(in[0], in[1], in[2], in[3]);
+ float invw = (f.w > 0.0f)? 1.0f/f.w: 1.0f;
- pixels[0] = f.x*scale_exposure;
- pixels[1] = f.y*scale_exposure;
- pixels[2] = f.z*scale_exposure;
+ pixels[0] = f.x*invw;
+ pixels[1] = f.y*invw;
+ pixels[2] = f.z*invw;
+ pixels[3] = 1.0f;
+ }
+ }
+ else {
+ for(int i = 0; i < size; i++, in += pass_stride, pixels += 4) {
+ float4 f = make_float4(in[0], in[1], in[2], in[3]);
- /* clamp since alpha might be > 1.0 due to russian roulette */
- pixels[3] = clamp(f.w*scale, 0.0f, 1.0f);
+ pixels[0] = f.x*scale_exposure;
+ pixels[1] = f.y*scale_exposure;
+ pixels[2] = f.z*scale_exposure;
+
+ /* clamp since alpha might be > 1.0 due to russian roulette */
+ pixels[3] = clamp(f.w*scale, 0.0f, 1.0f);
+ }
}
}
Modified: trunk/blender/intern/cycles/render/film.cpp
===================================================================
--- trunk/blender/intern/cycles/render/film.cpp 2012-03-28 09:10:19 UTC (rev 45241)
+++ trunk/blender/intern/cycles/render/film.cpp 2012-03-28 10:39:21 UTC (rev 45242)
@@ -116,6 +116,10 @@
pass.components = 4;
pass.exposure = true;
break;
+ case PASS_SHADOW:
+ pass.components = 4;
+ pass.exposure = false;
+ break;
}
passes.push_back(pass);
@@ -232,6 +236,9 @@
case PASS_AO:
kfilm->pass_ao = kfilm->pass_stride;
kfilm->use_light_pass = 1;
+ case PASS_SHADOW:
+ kfilm->pass_shadow = kfilm->pass_stride;
+ kfilm->use_light_pass = 1;
case PASS_NONE:
break;
}
More information about the Bf-blender-cvs
mailing list