[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56112] trunk/blender/intern/cycles: Fix #35004: fireflies with .tif image in cycles, try to avoid extreme values when
Brecht Van Lommel
brechtvanlommel at pandora.be
Wed Apr 17 16:47:58 CEST 2013
Revision: 56112
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56112
Author: blendix
Date: 2013-04-17 14:47:58 +0000 (Wed, 17 Apr 2013)
Log Message:
-----------
Fix #35004: fireflies with .tif image in cycles, try to avoid extreme values when
openimageio can't detect premul/straight alpha correct.
Modified Paths:
--------------
trunk/blender/intern/cycles/kernel/shaders/node_environment_texture.osl
trunk/blender/intern/cycles/kernel/shaders/node_image_texture.osl
trunk/blender/intern/cycles/kernel/svm/svm_image.h
trunk/blender/intern/cycles/render/nodes.cpp
Modified: trunk/blender/intern/cycles/kernel/shaders/node_environment_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_environment_texture.osl 2013-04-17 14:47:52 UTC (rev 56111)
+++ trunk/blender/intern/cycles/kernel/shaders/node_environment_texture.osl 2013-04-17 14:47:58 UTC (rev 56112)
@@ -48,6 +48,7 @@
string filename = "",
string projection = "Equirectangular",
string color_space = "sRGB",
+ int is_float = 1,
output color Color = 0.0,
output float Alpha = 1.0)
{
@@ -66,9 +67,13 @@
/* todo: use environment for better texture filtering of equirectangular */
Color = (color)texture(filename, p[0], 1.0 - p[1], "wrap", "periodic", "alpha", Alpha);
- if (isconnected(Alpha))
+ if (isconnected(Alpha)) {
Color = color_unpremultiply(Color, Alpha);
+ if (!is_float)
+ Color = min(Color, 1.0);
+ }
+
if (color_space == "sRGB")
Color = color_srgb_to_scene_linear(Color);
}
Modified: trunk/blender/intern/cycles/kernel/shaders/node_image_texture.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/shaders/node_image_texture.osl 2013-04-17 14:47:52 UTC (rev 56111)
+++ trunk/blender/intern/cycles/kernel/shaders/node_image_texture.osl 2013-04-17 14:47:58 UTC (rev 56112)
@@ -19,12 +19,16 @@
#include "stdosl.h"
#include "node_color.h"
-color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha)
+color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha, int is_float)
{
color rgb = (color)texture(filename, u, 1.0 - v, "wrap", "periodic", "alpha", Alpha);
- if (use_alpha)
+ if (use_alpha) {
rgb = color_unpremultiply(rgb, Alpha);
+
+ if (!is_float)
+ rgb = min(rgb, 1.0);
+ }
if (color_space == "sRGB")
rgb = color_srgb_to_scene_linear(rgb);
@@ -40,6 +44,7 @@
string color_space = "sRGB",
string projection = "Flat",
float projection_blend = 0.0,
+ int is_float = 1,
output color Color = 0.0,
output float Alpha = 1.0)
{
@@ -51,7 +56,7 @@
int use_alpha = isconnected(Alpha);
if (projection == "Flat") {
- Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha);
+ Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha, is_float);
}
else if (projection == "Box") {
/* object space normal */
@@ -116,15 +121,15 @@
float tmp_alpha;
if (weight[0] > 0.0) {
- Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha, use_alpha);
+ Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha, use_alpha, is_float);
Alpha += weight[0] * tmp_alpha;
}
if (weight[1] > 0.0) {
- Color += weight[1] * image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha, use_alpha);
+ Color += weight[1] * image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha, use_alpha, is_float);
Alpha += weight[1] * tmp_alpha;
}
if (weight[2] > 0.0) {
- Color += weight[2] * image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha, use_alpha);
+ Color += weight[2] * image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha, use_alpha, is_float);
Alpha += weight[2] * tmp_alpha;
}
}
Modified: trunk/blender/intern/cycles/kernel/svm/svm_image.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_image.h 2013-04-17 14:47:52 UTC (rev 56111)
+++ trunk/blender/intern/cycles/kernel/svm/svm_image.h 2013-04-17 14:47:58 UTC (rev 56112)
@@ -93,6 +93,12 @@
r.x *= invw;
r.y *= invw;
r.z *= invw;
+
+ if(id >= TEX_NUM_FLOAT_IMAGES) {
+ r.x = min(r.x, 1.0f);
+ r.y = min(r.y, 1.0f);
+ r.z = min(r.z, 1.0f);
+ }
}
if(srgb) {
@@ -234,6 +240,12 @@
r.x *= invw;
r.y *= invw;
r.z *= invw;
+
+ if(id >= TEX_NUM_FLOAT_IMAGES) {
+ r.x = min(r.x, 1.0f);
+ r.y = min(r.y, 1.0f);
+ r.z = min(r.z, 1.0f);
+ }
}
if(srgb) {
Modified: trunk/blender/intern/cycles/render/nodes.cpp
===================================================================
--- trunk/blender/intern/cycles/render/nodes.cpp 2013-04-17 14:47:52 UTC (rev 56111)
+++ trunk/blender/intern/cycles/render/nodes.cpp 2013-04-17 14:47:58 UTC (rev 56112)
@@ -249,6 +249,7 @@
compiler.parameter("color_space", "sRGB");
compiler.parameter("projection", projection);
compiler.parameter("projection_blend", projection_blend);
+ compiler.parameter("is_float", is_float);
compiler.add(this, "node_image_texture");
}
@@ -368,6 +369,7 @@
compiler.parameter("color_space", "Linear");
else
compiler.parameter("color_space", "sRGB");
+ compiler.parameter("is_float", is_float);
compiler.add(this, "node_environment_texture");
}
More information about the Bf-blender-cvs
mailing list