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:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2014-02-06 18:18:34 +0400
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2014-02-06 18:24:15 +0400
commita41648c1dc58fcfdb149bf6839ae237d1dadc704 (patch)
tree25fed9ed0a9d5e3f2dcfe60074e7ae3be19914ba /intern/cycles/kernel
parent5cbddd4ca47b4b2b45ae7284129db5b83d1a948c (diff)
Cycles: add pass alpha threshold value to render layers.
Z, Index, normal, UV and vector passes are only affected by surfaces with alpha transparency equal to or higher than this threshold. With value 0.0 the first surface hit will always write to these passes, regardless of transparency. With higher values surfaces that are mostly transparent can be skipped until an opaque surface is encountered.
Diffstat (limited to 'intern/cycles/kernel')
-rw-r--r--intern/cycles/kernel/closure/bsdf_transparent.h2
-rw-r--r--intern/cycles/kernel/kernel_passes.h60
-rw-r--r--intern/cycles/kernel/kernel_path.h4
-rw-r--r--intern/cycles/kernel/kernel_types.h22
4 files changed, 49 insertions, 39 deletions
diff --git a/intern/cycles/kernel/closure/bsdf_transparent.h b/intern/cycles/kernel/closure/bsdf_transparent.h
index e62aecf3da6..73601d20c3a 100644
--- a/intern/cycles/kernel/closure/bsdf_transparent.h
+++ b/intern/cycles/kernel/closure/bsdf_transparent.h
@@ -38,7 +38,7 @@ CCL_NAMESPACE_BEGIN
ccl_device int bsdf_transparent_setup(ShaderClosure *sc)
{
sc->type = CLOSURE_BSDF_TRANSPARENT_ID;
- return SD_BSDF;
+ return SD_BSDF|SD_TRANSPARENT;
}
ccl_device void bsdf_transparent_blur(ShaderClosure *sc, float roughness)
diff --git a/intern/cycles/kernel/kernel_passes.h b/intern/cycles/kernel/kernel_passes.h
index 512db9ec392..9cdcb8c5229 100644
--- a/intern/cycles/kernel/kernel_passes.h
+++ b/intern/cycles/kernel/kernel_passes.h
@@ -35,9 +35,11 @@ ccl_device_inline void kernel_write_pass_float4(ccl_global float *buffer, int sa
}
ccl_device_inline void kernel_write_data_passes(KernelGlobals *kg, ccl_global float *buffer, PathRadiance *L,
- ShaderData *sd, int sample, int path_flag, float3 throughput)
+ ShaderData *sd, int sample, PathState *state, float3 throughput)
{
#ifdef __PASSES__
+ int path_flag = state->flag;
+
if(!(path_flag & PATH_RAY_CAMERA))
return;
@@ -46,35 +48,41 @@ ccl_device_inline void kernel_write_data_passes(KernelGlobals *kg, ccl_global fl
if(!(flag & PASS_ALL))
return;
- /* todo: add alpha threshold */
- if(!(path_flag & PATH_RAY_TRANSPARENT)) {
- if(sample == 0) {
- if(flag & PASS_DEPTH) {
- float depth = camera_distance(kg, sd->P);
- kernel_write_pass_float(buffer + kernel_data.film.pass_depth, sample, depth);
+ if(!(path_flag & PATH_RAY_SINGLE_PASS_DONE)) {
+ if(!(sd->flag & SD_TRANSPARENT) ||
+ kernel_data.film.pass_alpha_threshold == 0.0f ||
+ average(shader_bsdf_alpha(kg, sd)) >= kernel_data.film.pass_alpha_threshold) {
+
+ if(sample == 0) {
+ if(flag & PASS_DEPTH) {
+ float depth = camera_distance(kg, sd->P);
+ kernel_write_pass_float(buffer + kernel_data.film.pass_depth, sample, depth);
+ }
+ if(flag & PASS_OBJECT_ID) {
+ float id = object_pass_id(kg, sd->object);
+ kernel_write_pass_float(buffer + kernel_data.film.pass_object_id, sample, id);
+ }
+ if(flag & PASS_MATERIAL_ID) {
+ float id = shader_pass_id(kg, sd);
+ kernel_write_pass_float(buffer + kernel_data.film.pass_material_id, sample, id);
+ }
}
- if(flag & PASS_OBJECT_ID) {
- float id = object_pass_id(kg, sd->object);
- kernel_write_pass_float(buffer + kernel_data.film.pass_object_id, sample, id);
+
+ if(flag & PASS_NORMAL) {
+ float3 normal = sd->N;
+ kernel_write_pass_float3(buffer + kernel_data.film.pass_normal, sample, normal);
}
- if(flag & PASS_MATERIAL_ID) {
- float id = shader_pass_id(kg, sd);
- kernel_write_pass_float(buffer + kernel_data.film.pass_material_id, sample, id);
+ if(flag & PASS_UV) {
+ float3 uv = primitive_uv(kg, sd);
+ kernel_write_pass_float3(buffer + kernel_data.film.pass_uv, sample, uv);
+ }
+ if(flag & PASS_MOTION) {
+ float4 speed = primitive_motion_vector(kg, sd);
+ kernel_write_pass_float4(buffer + kernel_data.film.pass_motion, sample, speed);
+ kernel_write_pass_float(buffer + kernel_data.film.pass_motion_weight, sample, 1.0f);
}
- }
- if(flag & PASS_NORMAL) {
- float3 normal = sd->N;
- kernel_write_pass_float3(buffer + kernel_data.film.pass_normal, sample, normal);
- }
- if(flag & PASS_UV) {
- float3 uv = primitive_uv(kg, sd);
- kernel_write_pass_float3(buffer + kernel_data.film.pass_uv, sample, uv);
- }
- if(flag & PASS_MOTION) {
- float4 speed = primitive_motion_vector(kg, sd);
- kernel_write_pass_float4(buffer + kernel_data.film.pass_motion, sample, speed);
- kernel_write_pass_float(buffer + kernel_data.film.pass_motion_weight, sample, 1.0f);
+ state->flag |= PATH_RAY_SINGLE_PASS_DONE;
}
}
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index 8460af85d4c..aabac2e8e5e 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -652,7 +652,7 @@ ccl_device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample,
#endif
/* holdout mask objects do not write data passes */
- kernel_write_data_passes(kg, buffer, &L, &sd, sample, state.flag, throughput);
+ kernel_write_data_passes(kg, buffer, &L, &sd, sample, &state, throughput);
/* blurring of bsdf after bounces, for rays that have a small likelihood
* of following this particular path (diffuse, rough glossy) */
@@ -1185,7 +1185,7 @@ ccl_device float4 kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, in
#endif
/* holdout mask objects do not write data passes */
- kernel_write_data_passes(kg, buffer, &L, &sd, sample, state.flag, throughput);
+ kernel_write_data_passes(kg, buffer, &L, &sd, sample, &state, throughput);
#ifdef __EMISSION__
/* emission */
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index cdde0fe0291..06bf6b7c5dd 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -234,6 +234,7 @@ enum PathRayFlag {
PATH_RAY_DIFFUSE_ANCESTOR = 2048,
PATH_RAY_GLOSSY_ANCESTOR = 4096,
PATH_RAY_BSSRDF_ANCESTOR = 8192,
+ PATH_RAY_SINGLE_PASS_DONE = 8192,
/* this gives collisions with localview bits
* see: blender_util.h, grr - Campbell */
@@ -519,23 +520,24 @@ enum ShaderDataFlag {
SD_ABSORPTION = 128, /* have volume absorption closure? */
SD_SCATTER = 256, /* have volume phase closure? */
SD_AO = 512, /* have ao closure? */
+ SD_TRANSPARENT = 1024, /* have transparent closure? */
SD_CLOSURE_FLAGS = (SD_EMISSION|SD_BSDF|SD_BSDF_HAS_EVAL|SD_BSDF_GLOSSY|SD_BSSRDF|SD_HOLDOUT|SD_ABSORPTION|SD_SCATTER|SD_AO),
/* shader flags */
- SD_USE_MIS = 1024, /* direct light sample */
- SD_HAS_TRANSPARENT_SHADOW = 2048, /* has transparent shadow */
- SD_HAS_VOLUME = 4096, /* has volume shader */
- SD_HAS_ONLY_VOLUME = 8192, /* has only volume shader, no surface */
- SD_HETEROGENEOUS_VOLUME = 16384, /* has heterogeneous volume */
- SD_HAS_BSSRDF_BUMP = 32768, /* bssrdf normal uses bump */
+ SD_USE_MIS = 2048, /* direct light sample */
+ SD_HAS_TRANSPARENT_SHADOW = 4096, /* has transparent shadow */
+ SD_HAS_VOLUME = 8192, /* has volume shader */
+ SD_HAS_ONLY_VOLUME = 16384, /* has only volume shader, no surface */
+ SD_HETEROGENEOUS_VOLUME = 32768, /* has heterogeneous volume */
+ SD_HAS_BSSRDF_BUMP = 65536, /* bssrdf normal uses bump */
SD_SHADER_FLAGS = (SD_USE_MIS|SD_HAS_TRANSPARENT_SHADOW|SD_HAS_VOLUME|SD_HAS_ONLY_VOLUME|SD_HETEROGENEOUS_VOLUME|SD_HAS_BSSRDF_BUMP),
/* object flags */
- SD_HOLDOUT_MASK = 65536, /* holdout for camera rays */
- SD_OBJECT_MOTION = 131072, /* has object motion blur */
- SD_TRANSFORM_APPLIED = 262144, /* vertices have transform applied */
+ SD_HOLDOUT_MASK = 131072, /* holdout for camera rays */
+ SD_OBJECT_MOTION = 262144, /* has object motion blur */
+ SD_TRANSFORM_APPLIED = 524288, /* vertices have transform applied */
SD_OBJECT_FLAGS = (SD_HOLDOUT_MASK|SD_OBJECT_MOTION|SD_TRANSFORM_APPLIED)
};
@@ -758,7 +760,7 @@ typedef struct KernelFilm {
int pass_emission;
int pass_background;
int pass_ao;
- int pass_pad1;
+ float pass_alpha_threshold;
int pass_shadow;
float pass_shadow_scale;