Blender  V2.93
kernel_film.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 ccl_device float4 film_get_pass_result(KernelGlobals *kg,
20  ccl_global float *buffer,
21  float sample_scale,
22  int index,
23  bool use_display_sample_scale)
24 {
25  float4 pass_result;
26 
27  int display_pass_stride = kernel_data.film.display_pass_stride;
28  int display_pass_components = kernel_data.film.display_pass_components;
29 
30  if (display_pass_components == 4) {
31  float4 in = *(ccl_global float4 *)(buffer + display_pass_stride +
32  index * kernel_data.film.pass_stride);
33  float alpha = use_display_sample_scale ?
34  (kernel_data.film.use_display_pass_alpha ? in.w : 1.0f / sample_scale) :
35  1.0f;
36 
37  pass_result = make_float4(in.x, in.y, in.z, alpha);
38 
39  int display_divide_pass_stride = kernel_data.film.display_divide_pass_stride;
40  if (display_divide_pass_stride != -1) {
41  ccl_global float4 *divide_in = (ccl_global float4 *)(buffer + display_divide_pass_stride +
42  index * kernel_data.film.pass_stride);
43  float3 divided = safe_divide_even_color(float4_to_float3(pass_result),
44  float4_to_float3(*divide_in));
45  pass_result = make_float4(divided.x, divided.y, divided.z, pass_result.w);
46  }
47 
48  if (kernel_data.film.use_display_exposure) {
49  float exposure = kernel_data.film.exposure;
50  pass_result *= make_float4(exposure, exposure, exposure, 1.0f);
51  }
52  }
53  else if (display_pass_components == 1) {
54  ccl_global float *in = (ccl_global float *)(buffer + display_pass_stride +
55  index * kernel_data.film.pass_stride);
56  pass_result = make_float4(*in, *in, *in, 1.0f / sample_scale);
57  }
58 
59  return pass_result;
60 }
61 
62 ccl_device float4 film_map(KernelGlobals *kg, float4 rgba_in, float scale)
63 {
64  float4 result;
65 
66  /* Conversion to SRGB. */
67  result.x = color_linear_to_srgb(rgba_in.x * scale);
68  result.y = color_linear_to_srgb(rgba_in.y * scale);
69  result.z = color_linear_to_srgb(rgba_in.z * scale);
70 
71  /* Clamp since alpha might be > 1.0 due to Russian roulette. */
72  result.w = saturate(rgba_in.w * scale);
73 
74  return result;
75 }
76 
78 {
79  uchar4 result;
80 
81  /* simple float to byte conversion */
82  result.x = (uchar)(saturate(color.x) * 255.0f);
83  result.y = (uchar)(saturate(color.y) * 255.0f);
84  result.z = (uchar)(saturate(color.z) * 255.0f);
85  result.w = (uchar)(saturate(color.w) * 255.0f);
86 
87  return result;
88 }
89 
91  ccl_global uchar4 *rgba,
92  ccl_global float *buffer,
93  float sample_scale,
94  int x,
95  int y,
96  int offset,
97  int stride)
98 {
99  /* buffer offset */
100  int index = offset + x + y * stride;
101 
102  bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
103  float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
104 
105  /* map colors */
106  float4 float_result = film_map(kg, rgba_in, use_display_sample_scale ? sample_scale : 1.0f);
107  uchar4 uchar_result = film_float_to_byte(float_result);
108 
109  rgba += index;
110  *rgba = uchar_result;
111 }
112 
114  ccl_global uchar4 *rgba,
115  ccl_global float *buffer,
116  float sample_scale,
117  int x,
118  int y,
119  int offset,
120  int stride)
121 {
122  /* buffer offset */
123  int index = offset + x + y * stride;
124 
125  bool use_display_sample_scale = (kernel_data.film.display_divide_pass_stride == -1);
126  float4 rgba_in = film_get_pass_result(kg, buffer, sample_scale, index, use_display_sample_scale);
127 
128  ccl_global half *out = (ccl_global half *)rgba + index * 4;
129  float4_store_half(out, rgba_in, use_display_sample_scale ? sample_scale : 1.0f);
130 }
131 
unsigned char uchar
Definition: BLI_sys_types.h:86
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
Definition: util_half.h:41
static CCL_NAMESPACE_BEGIN const double alpha
#define kernel_data
#define ccl_device
#define ccl_global
#define CCL_NAMESPACE_END
#define make_float4(x, y, z, w)
ccl_device void kernel_film_convert_to_byte(KernelGlobals *kg, ccl_global uchar4 *rgba, ccl_global float *buffer, float sample_scale, int x, int y, int offset, int stride)
Definition: kernel_film.h:90
ccl_device uchar4 film_float_to_byte(float4 color)
Definition: kernel_film.h:77
ccl_device float4 film_map(KernelGlobals *kg, float4 rgba_in, float scale)
Definition: kernel_film.h:62
ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg, ccl_global uchar4 *rgba, ccl_global float *buffer, float sample_scale, int x, int y, int offset, int stride)
Definition: kernel_film.h:113
CCL_NAMESPACE_BEGIN ccl_device float4 film_get_pass_result(KernelGlobals *kg, ccl_global float *buffer, float sample_scale, int index, bool use_display_sample_scale)
Definition: kernel_film.h:19
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
float z
Definition: sky_float3.h:35
float y
Definition: sky_float3.h:35
float x
Definition: sky_float3.h:35
ccl_device float color_linear_to_srgb(float c)
Definition: util_color.h:77
ccl_device_inline void float4_store_half(half *h, float4 f, float scale)
Definition: util_half.h:80
ccl_device_inline float saturate(float a)
Definition: util_math.h:315
ccl_device_inline float3 safe_divide_even_color(float3 a, float3 b)
Definition: util_math.h:525
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition: util_math.h:415