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
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void kernel_shader_evaluate(KernelGlobals *kg, ccl_global uint4 *input, ccl_global float4 *output, ShaderEvalType type, int i)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
ShaderData sd;
|
|
|
|
uint4 in = input[i];
|
2011-12-31 15:18:13 +00:00
|
|
|
float3 out;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-31 15:18:13 +00:00
|
|
|
if(type == SHADER_EVAL_DISPLACE) {
|
|
|
|
/* setup shader data */
|
|
|
|
int object = in.x;
|
|
|
|
int prim = in.y;
|
2013-06-07 16:06:17 +00:00
|
|
|
float u = __uint_as_float(in.z);
|
|
|
|
float v = __uint_as_float(in.w);
|
2011-12-31 15:18:13 +00:00
|
|
|
|
|
|
|
shader_setup_from_displace(kg, &sd, object, prim, u, v);
|
|
|
|
|
|
|
|
/* evaluate */
|
|
|
|
float3 P = sd.P;
|
2012-12-15 10:18:42 +00:00
|
|
|
shader_eval_displacement(kg, &sd, SHADER_CONTEXT_MAIN);
|
2011-12-31 15:18:13 +00:00
|
|
|
out = sd.P - P;
|
|
|
|
}
|
|
|
|
else { // SHADER_EVAL_BACKGROUND
|
|
|
|
/* setup ray */
|
|
|
|
Ray ray;
|
2013-06-07 16:06:17 +00:00
|
|
|
float u = __uint_as_float(in.x);
|
|
|
|
float v = __uint_as_float(in.y);
|
2011-12-31 15:18:13 +00:00
|
|
|
|
|
|
|
ray.P = make_float3(0.0f, 0.0f, 0.0f);
|
2012-02-28 16:44:54 +00:00
|
|
|
ray.D = equirectangular_to_direction(u, v);
|
2011-12-31 15:18:13 +00:00
|
|
|
ray.t = 0.0f;
|
2012-10-17 22:48:29 +00:00
|
|
|
#ifdef __CAMERA_MOTION__
|
|
|
|
ray.time = 0.5f;
|
|
|
|
#endif
|
2011-12-31 15:18:13 +00:00
|
|
|
|
|
|
|
#ifdef __RAY_DIFFERENTIALS__
|
2013-05-03 21:34:51 +00:00
|
|
|
ray.dD = differential3_zero();
|
|
|
|
ray.dP = differential3_zero();
|
2011-12-31 15:18:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup shader data */
|
2013-07-31 20:30:37 +00:00
|
|
|
shader_setup_from_background(kg, &sd, &ray, 0);
|
2011-12-31 15:18:13 +00:00
|
|
|
|
|
|
|
/* evaluate */
|
|
|
|
int flag = 0; /* we can't know which type of BSDF this is for */
|
2012-12-15 10:18:42 +00:00
|
|
|
out = shader_eval_background(kg, &sd, flag, SHADER_CONTEXT_MAIN);
|
2011-12-31 15:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write output */
|
2012-01-20 17:49:17 +00:00
|
|
|
output[i] = make_float4(out.x, out.y, out.z, 0.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|