2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2019-09-05 10:47:20 +00:00
|
|
|
ccl_device float4 film_get_pass_result(KernelGlobals *kg,
|
|
|
|
ccl_global float *buffer,
|
|
|
|
float sample_scale,
|
|
|
|
int index,
|
|
|
|
bool use_display_sample_scale)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-09-05 10:47:20 +00:00
|
|
|
float4 pass_result;
|
|
|
|
|
|
|
|
int display_pass_stride = kernel_data.film.display_pass_stride;
|
|
|
|
int display_pass_components = kernel_data.film.display_pass_components;
|
|
|
|
|
|
|
|
if (display_pass_components == 4) {
|
2020-05-22 17:02:49 +00:00
|
|
|
float4 in = *(ccl_global float4 *)(buffer + display_pass_stride +
|
|
|
|
index * kernel_data.film.pass_stride);
|
2019-09-05 10:47:20 +00:00
|
|
|
float alpha = use_display_sample_scale ?
|
2020-05-22 17:02:49 +00:00
|
|
|
(kernel_data.film.use_display_pass_alpha ? in.w : 1.0f / sample_scale) :
|
2019-09-05 10:47:20 +00:00
|
|
|
1.0f;
|
|
|
|
|
2020-05-22 17:02:49 +00:00
|
|
|
pass_result = make_float4(in.x, in.y, in.z, alpha);
|
2019-09-05 10:47:20 +00:00
|
|
|
|
|
|
|
int display_divide_pass_stride = kernel_data.film.display_divide_pass_stride;
|
|
|
|
if (display_divide_pass_stride != -1) {
|
|
|
|
ccl_global float4 *divide_in = (ccl_global float4 *)(buffer + display_divide_pass_stride +
|
|
|
|
index * kernel_data.film.pass_stride);
|
2020-02-25 18:51:20 +00:00
|
|
|
float3 divided = safe_divide_even_color(float4_to_float3(pass_result),
|
|
|
|
float4_to_float3(*divide_in));
|
|
|
|
pass_result = make_float4(divided.x, divided.y, divided.z, pass_result.w);
|
2019-09-05 10:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel_data.film.use_display_exposure) {
|
|
|
|
float exposure = kernel_data.film.exposure;
|
2020-08-26 17:05:20 +00:00
|
|
|
pass_result *= make_float4(exposure, exposure, exposure, 1.0f);
|
2019-09-05 10:47:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (display_pass_components == 1) {
|
|
|
|
ccl_global float *in = (ccl_global float *)(buffer + display_pass_stride +
|
|
|
|
index * kernel_data.film.pass_stride);
|
|
|
|
pass_result = make_float4(*in, *in, *in, 1.0f / sample_scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pass_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ccl_device float4 film_map(KernelGlobals *kg, float4 rgba_in, float scale)
|
|
|
|
{
|
|
|
|
float4 result;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-02-05 05:23:34 +00:00
|
|
|
/* Conversion to SRGB. */
|
2020-01-10 13:56:39 +00:00
|
|
|
result.x = color_linear_to_srgb(rgba_in.x * scale);
|
|
|
|
result.y = color_linear_to_srgb(rgba_in.y * scale);
|
|
|
|
result.z = color_linear_to_srgb(rgba_in.z * scale);
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2021-02-05 05:23:34 +00:00
|
|
|
/* Clamp since alpha might be > 1.0 due to Russian roulette. */
|
2020-01-10 13:56:39 +00:00
|
|
|
result.w = saturate(rgba_in.w * scale);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device uchar4 film_float_to_byte(float4 color)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
uchar4 result;
|
|
|
|
|
|
|
|
/* simple float to byte conversion */
|
2015-04-27 19:13:03 +00:00
|
|
|
result.x = (uchar)(saturate(color.x) * 255.0f);
|
|
|
|
result.y = (uchar)(saturate(color.y) * 255.0f);
|
|
|
|
result.z = (uchar)(saturate(color.z) * 255.0f);
|
|
|
|
result.w = (uchar)(saturate(color.w) * 255.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void kernel_film_convert_to_byte(KernelGlobals *kg,
|
|
|
|
ccl_global uchar4 *rgba,
|
|
|
|
ccl_global float *buffer,
|
2013-08-30 23:49:38 +00:00
|
|
|
float sample_scale,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int offset,
|
|
|
|
int stride)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* buffer offset */
|
2011-12-20 12:25:37 +00:00
|
|
|
int index = offset + x + y * stride;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-09-05 10:47:20 +00:00
|
|
|
bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
|
|
|
|
float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* map colors */
|
2020-01-10 13:56:39 +00:00
|
|
|
float4 float_result = film_map(kg, rgba_in, use_display_sample_scale ? sample_scale : 1.0f);
|
|
|
|
uchar4 uchar_result = film_float_to_byte(float_result);
|
|
|
|
|
|
|
|
rgba += index;
|
|
|
|
*rgba = uchar_result;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg,
|
|
|
|
ccl_global uchar4 *rgba,
|
|
|
|
ccl_global float *buffer,
|
2013-08-30 23:49:38 +00:00
|
|
|
float sample_scale,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int offset,
|
|
|
|
int stride)
|
|
|
|
{
|
|
|
|
/* buffer offset */
|
|
|
|
int index = offset + x + y * stride;
|
2020-01-10 13:56:39 +00:00
|
|
|
|
2019-09-05 10:47:20 +00:00
|
|
|
bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
|
|
|
|
float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
|
2013-08-30 23:49:38 +00:00
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_global half *out = (ccl_global half *)rgba + index * 4;
|
2020-01-10 13:56:39 +00:00
|
|
|
float4_store_half(out, rgba_in, use_display_sample_scale ? sample_scale : 1.0f);
|
2013-08-30 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|