Blender V2.61 - r43446
|
00001 /* 00002 * Copyright 2011, Blender Foundation. 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 */ 00018 00019 CCL_NAMESPACE_BEGIN 00020 00021 __device float4 film_map(KernelGlobals *kg, float4 irradiance, int sample) 00022 { 00023 float scale = 1.0f/(float)(sample+1); 00024 float exposure = kernel_data.film.exposure; 00025 float4 result = irradiance*scale; 00026 00027 /* conversion to srgb */ 00028 result.x = color_scene_linear_to_srgb(result.x*exposure); 00029 result.y = color_scene_linear_to_srgb(result.y*exposure); 00030 result.z = color_scene_linear_to_srgb(result.z*exposure); 00031 00032 /* clamp since alpha might be > 1.0 due to russian roulette */ 00033 result.w = clamp(result.w, 0.0f, 1.0f); 00034 00035 return result; 00036 } 00037 00038 __device uchar4 film_float_to_byte(float4 color) 00039 { 00040 uchar4 result; 00041 00042 /* simple float to byte conversion */ 00043 result.x = (uchar)clamp(color.x*255.0f, 0.0f, 255.0f); 00044 result.y = (uchar)clamp(color.y*255.0f, 0.0f, 255.0f); 00045 result.z = (uchar)clamp(color.z*255.0f, 0.0f, 255.0f); 00046 result.w = (uchar)clamp(color.w*255.0f, 0.0f, 255.0f); 00047 00048 return result; 00049 } 00050 00051 __device void kernel_film_tonemap(KernelGlobals *kg, __global uchar4 *rgba, __global float4 *buffer, int sample, int resolution, int x, int y, int offset, int stride) 00052 { 00053 int index = offset + x + y*stride; 00054 float4 irradiance = buffer[index]; 00055 00056 float4 float_result = film_map(kg, irradiance, sample); 00057 uchar4 byte_result = film_float_to_byte(float_result); 00058 00059 rgba[index] = byte_result; 00060 } 00061 00062 CCL_NAMESPACE_END 00063