diff options
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/blender/blender_session.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_camera.h | 8 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_color.h | 8 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_environment_texture.osl | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_image_texture.osl | 15 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_image.h | 31 | ||||
-rw-r--r-- | intern/cycles/render/attribute.cpp | 133 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/render/tile.h | 3 | ||||
-rw-r--r-- | intern/cycles/util/util_transform.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/util/util_transform.h | 1 |
11 files changed, 142 insertions, 72 deletions
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index acda90f0b83..1f1bb830771 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -549,7 +549,7 @@ void BlenderSession::get_progress(float& progress, double& total_time) session->progress.get_tile(tile, total_time, tile_time); sample = session->progress.get_sample(); - samples_per_tile = session->params.samples; + samples_per_tile = session->tile_manager.num_samples; if(samples_per_tile && tile_total) progress = ((float)sample / (float)(tile_total * samples_per_tile)); diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index 800daf40887..fe31419b11e 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -100,7 +100,6 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa Transform rastertocamera = kernel_data.cam.rastertocamera; float3 Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y, 0.0f)); - ray->P = Pcamera; ray->D = make_float3(0.0f, 0.0f, 1.0f); /* modify ray for depth of field */ @@ -116,11 +115,12 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa /* update ray for effect of lens */ float3 lensuvw = make_float3(lensuv.x, lensuv.y, 0.0f); - - ray->P += lensuvw; + ray->P = Pcamera + lensuvw; ray->D = normalize(Pfocus - lensuvw); } - + else { + ray->P = Pcamera; + } /* transform ray from camera to world */ Transform cameratoworld = kernel_data.cam.cameratoworld; diff --git a/intern/cycles/kernel/shaders/node_color.h b/intern/cycles/kernel/shaders/node_color.h index 80786e4e369..c6b5d740f6a 100644 --- a/intern/cycles/kernel/shaders/node_color.h +++ b/intern/cycles/kernel/shaders/node_color.h @@ -48,6 +48,14 @@ color color_scene_linear_to_srgb(color c) color_scene_linear_to_srgb(c[2])); } +color color_unpremultiply(color c, float alpha) +{ + if(alpha != 1.0 && alpha != 0.0) + return c/alpha; + + return c; +} + /* Color Operations */ color rgb_to_hsv(color rgb) diff --git a/intern/cycles/kernel/shaders/node_environment_texture.osl b/intern/cycles/kernel/shaders/node_environment_texture.osl index 33b30a27ee1..36b2f755c20 100644 --- a/intern/cycles/kernel/shaders/node_environment_texture.osl +++ b/intern/cycles/kernel/shaders/node_environment_texture.osl @@ -66,6 +66,9 @@ shader node_environment_texture( /* 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)) + Color = color_unpremultiply(Color, Alpha); + if (color_space == "sRGB") Color = color_srgb_to_scene_linear(Color); } diff --git a/intern/cycles/kernel/shaders/node_image_texture.osl b/intern/cycles/kernel/shaders/node_image_texture.osl index c94a3f7e76a..c7ec8726ae2 100644 --- a/intern/cycles/kernel/shaders/node_image_texture.osl +++ b/intern/cycles/kernel/shaders/node_image_texture.osl @@ -19,10 +19,13 @@ #include "stdosl.h" #include "node_color.h" -color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha) +color image_texture_lookup(string filename, string color_space, float u, float v, output float Alpha, int use_alpha) { color rgb = (color)texture(filename, u, 1.0 - v, "wrap", "periodic", "alpha", Alpha); + if (use_alpha) + rgb = color_unpremultiply(rgb, Alpha); + if (color_space == "sRGB") rgb = color_srgb_to_scene_linear(rgb); @@ -44,9 +47,11 @@ shader node_image_texture( if (use_mapping) p = transform(mapping, p); + + int use_alpha = isconnected(Alpha); if (projection == "Flat") { - Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha); + Color = image_texture_lookup(filename, color_space, p[0], p[1], Alpha, use_alpha); } else if (projection == "Box") { /* object space normal */ @@ -111,15 +116,15 @@ shader node_image_texture( float tmp_alpha; if (weight[0] > 0.0) { - Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha); + Color += weight[0] * image_texture_lookup(filename, color_space, p[1], p[2], tmp_alpha, use_alpha); 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); + Color += weight[1] * image_texture_lookup(filename, color_space, p[0], p[2], tmp_alpha, use_alpha); 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); + Color += weight[2] * image_texture_lookup(filename, color_space, p[1], p[0], tmp_alpha, use_alpha); Alpha += weight[2] * tmp_alpha; } } diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h index 0894c9c8290..b2f20366573 100644 --- a/intern/cycles/kernel/svm/svm_image.h +++ b/intern/cycles/kernel/svm/svm_image.h @@ -50,7 +50,7 @@ __device_inline float svm_image_texture_frac(float x, int *ix) return x - (float)i; } -__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb) +__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha) { /* first slots are used by float textures, which are not supported here */ if(id < TEX_NUM_FLOAT_IMAGES) @@ -88,6 +88,13 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, u r += ty*(1.0f - tx)*svm_image_texture_read(kg, offset + ix + niy*width); r += ty*tx*svm_image_texture_read(kg, offset + nix + niy*width); + if(use_alpha && r.w != 1.0f && r.w != 0.0f) { + float invw = 1.0f/r.w; + r.x *= invw; + r.y *= invw; + r.z *= invw; + } + if(srgb) { r.x = color_srgb_to_scene_linear(r.x); r.y = color_srgb_to_scene_linear(r.y); @@ -99,7 +106,7 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, u #else -__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb) +__device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, uint srgb, uint use_alpha) { float4 r; @@ -222,6 +229,13 @@ __device float4 svm_image_texture(KernelGlobals *kg, int id, float x, float y, u } #endif + if(use_alpha && r.w != 1.0f && r.w != 0.0f) { + float invw = 1.0f/r.w; + r.x *= invw; + r.y *= invw; + r.z *= invw; + } + if(srgb) { r.x = color_srgb_to_scene_linear(r.x); r.y = color_srgb_to_scene_linear(r.y); @@ -241,7 +255,8 @@ __device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *stack decode_node_uchar4(node.z, &co_offset, &out_offset, &alpha_offset, &srgb); float3 co = stack_load_float3(stack, co_offset); - float4 f = svm_image_texture(kg, id, co.x, co.y, srgb); + uint use_alpha = stack_valid(alpha_offset); + float4 f = svm_image_texture(kg, id, co.x, co.y, srgb, use_alpha); if(stack_valid(out_offset)) stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); @@ -322,13 +337,14 @@ __device void svm_node_tex_image_box(KernelGlobals *kg, ShaderData *sd, float *s uint id = node.y; float4 f = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + uint use_alpha = stack_valid(alpha_offset); if(weight.x > 0.0f) - f += weight.x*svm_image_texture(kg, id, co.y, co.z, srgb); + f += weight.x*svm_image_texture(kg, id, co.y, co.z, srgb, use_alpha); if(weight.y > 0.0f) - f += weight.y*svm_image_texture(kg, id, co.x, co.z, srgb); + f += weight.y*svm_image_texture(kg, id, co.x, co.z, srgb, use_alpha); if(weight.z > 0.0f) - f += weight.z*svm_image_texture(kg, id, co.y, co.x, srgb); + f += weight.z*svm_image_texture(kg, id, co.y, co.x, srgb, use_alpha); if(stack_valid(out_offset)) stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); @@ -355,7 +371,8 @@ __device void svm_node_tex_environment(KernelGlobals *kg, ShaderData *sd, float else uv = direction_to_mirrorball(co); - float4 f = svm_image_texture(kg, id, uv.x, uv.y, srgb); + uint use_alpha = stack_valid(alpha_offset); + float4 f = svm_image_texture(kg, id, uv.x, uv.y, srgb, use_alpha); if(stack_valid(out_offset)) stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z)); diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index b6f6ba47fe8..3137ea5327b 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -72,20 +72,33 @@ size_t Attribute::data_sizeof() const size_t Attribute::element_size(int numverts, int numtris, int numcurves, int numkeys) const { - if(element == ATTR_ELEMENT_VALUE) - return 1; - if(element == ATTR_ELEMENT_VERTEX) - return numverts; - else if(element == ATTR_ELEMENT_FACE) - return numtris; - else if(element == ATTR_ELEMENT_CORNER) - return numtris*3; - else if(element == ATTR_ELEMENT_CURVE) - return numcurves; - else if(element == ATTR_ELEMENT_CURVE_KEY) - return numkeys; + size_t size; - return 0; + switch(element) { + case ATTR_ELEMENT_VALUE: + size = 1; + break; + case ATTR_ELEMENT_VERTEX: + size = numverts; + break; + case ATTR_ELEMENT_FACE: + size = numtris; + break; + case ATTR_ELEMENT_CORNER: + size = numtris*3; + break; + case ATTR_ELEMENT_CURVE: + size = numcurves; + break; + case ATTR_ELEMENT_CURVE_KEY: + size = numkeys; + break; + default: + size = 0; + break; + } + + return size; } size_t Attribute::buffer_size(int numverts, int numtris, int numcurves, int numkeys) const @@ -214,44 +227,66 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name) name = Attribute::standard_name(std); if(triangle_mesh) { - if(std == ATTR_STD_VERTEX_NORMAL) - attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); - else if(std == ATTR_STD_FACE_NORMAL) - attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); - else if(std == ATTR_STD_UV) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER); - else if(std == ATTR_STD_UV_TANGENT) - attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER); - else if(std == ATTR_STD_UV_TANGENT_SIGN) - attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER); - else if(std == ATTR_STD_GENERATED) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); - else if(std == ATTR_STD_POSITION_UNDEFORMED) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); - else if(std == ATTR_STD_POSITION_UNDISPLACED) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); - else if(std == ATTR_STD_MOTION_PRE) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); - else if(std == ATTR_STD_MOTION_POST) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); - else - assert(0); + switch(std) { + case ATTR_STD_VERTEX_NORMAL: + attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX); + break; + case ATTR_STD_FACE_NORMAL: + attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_FACE); + break; + case ATTR_STD_UV: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER); + break; + case ATTR_STD_UV_TANGENT: + attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER); + break; + case ATTR_STD_UV_TANGENT_SIGN: + attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER); + break; + case ATTR_STD_GENERATED: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); + break; + case ATTR_STD_POSITION_UNDEFORMED: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); + break; + case ATTR_STD_POSITION_UNDISPLACED: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); + break; + case ATTR_STD_MOTION_PRE: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); + break; + case ATTR_STD_MOTION_POST: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_VERTEX); + break; + default: + assert(0); + break; + } } else if(curve_mesh) { - if(std == ATTR_STD_UV) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); - else if(std == ATTR_STD_GENERATED) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); - else if(std == ATTR_STD_MOTION_PRE) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY); - else if(std == ATTR_STD_MOTION_POST) - attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY); - else if(std == ATTR_STD_CURVE_TANGENT) - attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CURVE_KEY); - else if(std == ATTR_STD_CURVE_INTERCEPT) - attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CURVE_KEY); - else - assert(0); + switch(std) { + case ATTR_STD_UV: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); + break; + case ATTR_STD_GENERATED: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE); + break; + case ATTR_STD_MOTION_PRE: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY); + break; + case ATTR_STD_MOTION_POST: + attr = add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CURVE_KEY); + break; + case ATTR_STD_CURVE_TANGENT: + attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CURVE_KEY); + break; + case ATTR_STD_CURVE_INTERCEPT: + attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_CURVE_KEY); + break; + default: + assert(0); + break; + } } attr->std = std; diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 6ed14452c6b..075f5eb6bab 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -758,7 +758,7 @@ void Session::update_status_time(bool show_pause, bool show_done) * also display the info on CPU, when using 1 tile only */ - int sample = progress.get_sample(), num_samples = tile_manager.state.num_samples; + int sample = progress.get_sample(), num_samples = tile_manager.num_samples; if(tile > 1) { /* sample counter is global for all tiles, subtract samples @@ -771,10 +771,10 @@ void Session::update_status_time(bool show_pause, bool show_done) substatus += string_printf(", Sample %d/%d", sample, num_samples); } } - else if(params.samples == INT_MAX) + else if(tile_manager.num_samples == INT_MAX) substatus = string_printf("Path Tracing Sample %d", sample+1); else - substatus = string_printf("Path Tracing Sample %d/%d", sample+1, params.samples); + substatus = string_printf("Path Tracing Sample %d/%d", sample+1, tile_manager.num_samples); if(show_pause) status = "Paused"; @@ -846,7 +846,7 @@ void Session::tonemap() bool Session::update_progressive_refine(bool cancel) { int sample = tile_manager.state.sample + 1; - bool write = sample == params.samples || cancel; + bool write = sample == tile_manager.num_samples || cancel; double current_time = time_dt(); diff --git a/intern/cycles/render/tile.h b/intern/cycles/render/tile.h index 99cffb49c08..0e9e5a73a42 100644 --- a/intern/cycles/render/tile.h +++ b/intern/cycles/render/tile.h @@ -58,6 +58,8 @@ public: list<Tile> tiles; } state; + int num_samples; + TileManager(bool progressive, int num_samples, int2 tile_size, int start_resolution, bool preserve_tile_device, bool background, int tile_order, int num_devices = 1); ~TileManager(); @@ -82,7 +84,6 @@ protected: void set_tiles(); bool progressive; - int num_samples; int2 tile_size; int tile_order; int start_resolution; diff --git a/intern/cycles/util/util_transform.cpp b/intern/cycles/util/util_transform.cpp index ca19146e125..f5e0c8e803e 100644 --- a/intern/cycles/util/util_transform.cpp +++ b/intern/cycles/util/util_transform.cpp @@ -155,7 +155,7 @@ Transform transform_inverse(const Transform& tfm) /* Motion Transform */ -static float4 transform_to_quat(const Transform& tfm) +float4 transform_to_quat(const Transform& tfm) { double trace = tfm[0][0] + tfm[1][1] + tfm[2][2]; float4 qt; diff --git a/intern/cycles/util/util_transform.h b/intern/cycles/util/util_transform.h index 1f19f85f894..617ba43a5ed 100644 --- a/intern/cycles/util/util_transform.h +++ b/intern/cycles/util/util_transform.h @@ -454,6 +454,7 @@ __device_inline bool operator==(const MotionTransform& A, const MotionTransform& return (A.pre == B.pre && A.post == B.post); } +float4 transform_to_quat(const Transform& tfm); void transform_motion_decompose(DecompMotionTransform *decomp, const MotionTransform *motion, const Transform *mid); #endif |