Cycles: Implement denoising option for reducing noise in the rendered image
[blender.git] / intern / cycles / kernel / svm / svm_geometry.h
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
17 CCL_NAMESPACE_BEGIN
18
19 /* Geometry Node */
20
21 ccl_device_inline void svm_node_geometry(KernelGlobals *kg,
22                                          ShaderData *sd,
23                                          float *stack,
24                                          uint type,
25                                          uint out_offset)
26 {
27         float3 data;
28
29         switch(type) {
30                 case NODE_GEOM_P: data = sd->P; break;
31                 case NODE_GEOM_N: data = sd->N; break;
32 #ifdef __DPDU__
33                 case NODE_GEOM_T: data = primitive_tangent(kg, sd); break;
34 #endif
35                 case NODE_GEOM_I: data = sd->I; break;
36                 case NODE_GEOM_Ng: data = sd->Ng; break;
37 #ifdef __UV__
38                 case NODE_GEOM_uv: data = make_float3(sd->u, sd->v, 0.0f); break;
39 #endif
40                 default: data = make_float3(0.0f, 0.0f, 0.0f);
41         }
42
43         stack_store_float3(stack, out_offset, data);
44 }
45
46 ccl_device void svm_node_geometry_bump_dx(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
47 {
48 #ifdef __RAY_DIFFERENTIALS__
49         float3 data;
50
51         switch(type) {
52                 case NODE_GEOM_P: data = sd->P + sd->dP.dx; break;
53                 case NODE_GEOM_uv: data = make_float3(sd->u + sd->du.dx, sd->v + sd->dv.dx, 0.0f); break;
54                 default: svm_node_geometry(kg, sd, stack, type, out_offset); return;
55         }
56
57         stack_store_float3(stack, out_offset, data);
58 #else
59         svm_node_geometry(kg, sd, stack, type, out_offset);
60 #endif
61 }
62
63 ccl_device void svm_node_geometry_bump_dy(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
64 {
65 #ifdef __RAY_DIFFERENTIALS__
66         float3 data;
67
68         switch(type) {
69                 case NODE_GEOM_P: data = sd->P + sd->dP.dy; break;
70                 case NODE_GEOM_uv: data = make_float3(sd->u + sd->du.dy, sd->v + sd->dv.dy, 0.0f); break;
71                 default: svm_node_geometry(kg, sd, stack, type, out_offset); return;
72         }
73
74         stack_store_float3(stack, out_offset, data);
75 #else
76         svm_node_geometry(kg, sd, stack, type, out_offset);
77 #endif
78 }
79
80 /* Object Info */
81
82 ccl_device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset)
83 {
84         float data;
85
86         switch(type) {
87                 case NODE_INFO_OB_LOCATION: {
88                         stack_store_float3(stack, out_offset, object_location(kg, sd));
89                         return;
90                 }
91                 case NODE_INFO_OB_INDEX: data = object_pass_id(kg, sd->object); break;
92                 case NODE_INFO_MAT_INDEX: data = shader_pass_id(kg, sd); break;
93                 case NODE_INFO_OB_RANDOM: data = object_random_number(kg, sd->object); break;
94                 default: data = 0.0f; break;
95         }
96
97         stack_store_float(stack, out_offset, data);
98 }
99
100 /* Particle Info */
101
102 ccl_device void svm_node_particle_info(KernelGlobals *kg,
103                                        ShaderData *sd,
104                                        float *stack,
105                                        uint type,
106                                        uint out_offset)
107 {
108         switch(type) {
109                 case NODE_INFO_PAR_INDEX: {
110                         int particle_id = object_particle_id(kg, sd->object);
111                         stack_store_float(stack, out_offset, particle_index(kg, particle_id));
112                         break;
113                 }
114                 case NODE_INFO_PAR_AGE: {
115                         int particle_id = object_particle_id(kg, sd->object);
116                         stack_store_float(stack, out_offset, particle_age(kg, particle_id));
117                         break;
118                 }
119                 case NODE_INFO_PAR_LIFETIME: {
120                         int particle_id = object_particle_id(kg, sd->object);
121                         stack_store_float(stack, out_offset, particle_lifetime(kg, particle_id));
122                         break;
123                 }
124                 case NODE_INFO_PAR_LOCATION: {
125                         int particle_id = object_particle_id(kg, sd->object);
126                         stack_store_float3(stack, out_offset, particle_location(kg, particle_id));
127                         break;
128                 }
129 #if 0   /* XXX float4 currently not supported in SVM stack */
130                 case NODE_INFO_PAR_ROTATION: {
131                         int particle_id = object_particle_id(kg, sd->object);
132                         stack_store_float4(stack, out_offset, particle_rotation(kg, particle_id));
133                         break;
134                 }
135 #endif
136                 case NODE_INFO_PAR_SIZE: {
137                         int particle_id = object_particle_id(kg, sd->object);
138                         stack_store_float(stack, out_offset, particle_size(kg, particle_id));
139                         break;
140                 }
141                 case NODE_INFO_PAR_VELOCITY: {
142                         int particle_id = object_particle_id(kg, sd->object);
143                         stack_store_float3(stack, out_offset, particle_velocity(kg, particle_id));
144                         break;
145                 }
146                 case NODE_INFO_PAR_ANGULAR_VELOCITY: {
147                         int particle_id = object_particle_id(kg, sd->object);
148                         stack_store_float3(stack, out_offset, particle_angular_velocity(kg, particle_id));
149                         break;
150                 }
151         }
152 }
153
154 #ifdef __HAIR__
155
156 /* Hair Info */
157
158 ccl_device void svm_node_hair_info(KernelGlobals *kg,
159                                    ShaderData *sd,
160                                    float *stack,
161                                    uint type,
162                                    uint out_offset)
163 {
164         float data;
165         float3 data3;
166
167         switch(type) {
168                 case NODE_INFO_CURVE_IS_STRAND: {
169                         data = (sd->type & PRIMITIVE_ALL_CURVE) != 0;
170                         stack_store_float(stack, out_offset, data);
171                         break;
172                 }
173                 case NODE_INFO_CURVE_INTERCEPT:
174                         break; /* handled as attribute */
175                 case NODE_INFO_CURVE_THICKNESS: {
176                         data = curve_thickness(kg, sd);
177                         stack_store_float(stack, out_offset, data);
178                         break;
179                 }
180                 /*case NODE_INFO_CURVE_FADE: {
181                         data = sd->curve_transparency;
182                         stack_store_float(stack, out_offset, data);
183                         break;
184                 }*/
185                 case NODE_INFO_CURVE_TANGENT_NORMAL: {
186                         data3 = curve_tangent_normal(kg, sd);
187                         stack_store_float3(stack, out_offset, data3);
188                         break;
189                 }
190         }
191 }
192 #endif
193
194 CCL_NAMESPACE_END
195