diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-09-20 04:39:27 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-09-20 04:39:27 +0400 |
commit | 6cd32435a2cd8c87a21a9f76c7fa1b91654082a2 (patch) | |
tree | 56615427c57bb4d709545af10a275258e40e049e /source/blender/render/intern | |
parent | 56476248b67351edbfeb21234c2fdf4add480cac (diff) |
Fix #32598: clamp blender internal alpha channel to 0..1, and RGB to 0..inf,
to avoid compositing issues. The values can go out of bounds due to sharp
pixel filters.
In Cycles the alpha channel is already clamped, and there are no pixel filters
that could cause negative RGB values.
Diffstat (limited to 'source/blender/render/intern')
-rw-r--r-- | source/blender/render/intern/source/pipeline.c | 16 | ||||
-rw-r--r-- | source/blender/render/intern/source/rendercore.c | 27 |
2 files changed, 41 insertions, 2 deletions
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index e9ff74bd1ac..4a1674b8bca 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -1387,7 +1387,7 @@ static void render_composit_stats(void *UNUSED(arg), char *str) static void do_merge_fullsample(Render *re, bNodeTree *ntree) { float *rectf, filt[3][3]; - int sample; + int x, y, sample; /* interaction callbacks */ if (ntree) { @@ -1408,7 +1408,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) for (sample = 0; sample < re->r.osa; sample++) { Render *re1; RenderResult rres; - int x, y, mask; + int mask; /* enable full sample print */ R.i.curfsa = sample + 1; @@ -1471,6 +1471,18 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree) if (re->test_break(re->tbh)) break; } + + /* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */ + for (y = 0; y < re->recty; y++) { + float *rf = rectf + 4 * y * re->rectx; + + for (x = 0; x < re->rectx; x++, rf += 4) { + rf[0] = MAX2(rf[0], 0.0f); + rf[1] = MAX2(rf[1], 0.0f); + rf[2] = MAX2(rf[2], 0.0f); + CLAMP(rf[3], 0.0f, 1.0f); + } + } /* clear interaction callbacks */ if (ntree) { diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c index 2161449c2d1..0d894073cee 100644 --- a/source/blender/render/intern/source/rendercore.c +++ b/source/blender/render/intern/source/rendercore.c @@ -990,6 +990,30 @@ static void convert_to_key_alpha(RenderPart *pa, RenderLayer *rl) } } +/* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */ +static void clamp_alpha_rgb_range(RenderPart *pa, RenderLayer *rl) +{ + RenderLayer *rlpp[RE_MAX_OSA]; + int y, sample, totsample; + + totsample= get_sample_layers(pa, rl, rlpp); + + /* not for full sample, there we clamp after compositing */ + if (totsample > 1) + return; + + for (sample= 0; sample<totsample; sample++) { + float *rectf= rlpp[sample]->rectf; + + for (y= pa->rectx*pa->recty; y>0; y--, rectf+=4) { + rectf[0] = MAX2(rectf[0], 0.0f); + rectf[1] = MAX2(rectf[1], 0.0f); + rectf[2] = MAX2(rectf[2], 0.0f); + CLAMP(rectf[3], 0.0f, 1.0f); + } + } +} + /* adds only alpha values */ static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz) { @@ -1270,6 +1294,9 @@ void zbufshadeDA_tile(RenderPart *pa) if (rl->passflag & SCE_PASS_VECTOR) reset_sky_speed(pa, rl); + + /* clamp alpha to 0..1 range, can go outside due to filter */ + clamp_alpha_rgb_range(pa, rl); /* de-premul alpha */ if (R.r.alphamode & R_ALPHAKEY) |