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 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Closure Nodes */
|
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
ccl_device void svm_node_glass_setup(ShaderData *sd, MicrofacetBsdf *bsdf, int type, float eta, float roughness, bool refract)
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
2012-11-06 19:59:02 +00:00
|
|
|
if(type == CLOSURE_BSDF_SHARP_GLASS_ID) {
|
2012-10-20 12:18:00 +00:00
|
|
|
if(refract) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_y = 0.0f;
|
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->ior = eta;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
}
|
2015-03-25 02:30:43 +05:00
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_y = 0.0f;
|
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->ior = 0.0f;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_reflection_setup(bsdf);
|
2015-03-25 02:30:43 +05:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
|
|
|
bsdf->ior = eta;
|
2012-10-20 12:18:00 +00:00
|
|
|
|
|
|
|
if(refract)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness;
|
|
|
|
bsdf->alpha_y = roughness;
|
|
|
|
bsdf->ior = eta;
|
2012-10-20 12:18:00 +00:00
|
|
|
|
|
|
|
if(refract)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2012-10-20 12:18:00 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-25 23:43:55 +01:00
|
|
|
ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type, int path_flag, int *offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-05-13 12:11:08 +00:00
|
|
|
uint type, param1_offset, param2_offset;
|
2011-09-12 13:13:56 +00:00
|
|
|
|
|
|
|
uint mix_weight_offset;
|
|
|
|
decode_node_uchar4(node.y, &type, ¶m1_offset, ¶m2_offset, &mix_weight_offset);
|
|
|
|
float mix_weight = (stack_valid(mix_weight_offset)? stack_load_float(stack, mix_weight_offset): 1.0f);
|
|
|
|
|
2012-10-10 15:56:43 +00:00
|
|
|
/* note we read this extra node before weight check, so offset is added */
|
|
|
|
uint4 data_node = read_node(kg, offset);
|
|
|
|
|
2017-12-25 23:43:55 +01:00
|
|
|
/* Only compute BSDF for surfaces, transparent variable is shared with volume extinction. */
|
|
|
|
if(mix_weight == 0.0f || shader_type != SHADER_TYPE_SURFACE) {
|
|
|
|
if(type == CLOSURE_BSDF_PRINCIPLED_ID) {
|
|
|
|
/* Read all principled BSDF extra data to get the right offset. */
|
|
|
|
read_node(kg, offset);
|
|
|
|
read_node(kg, offset);
|
|
|
|
read_node(kg, offset);
|
|
|
|
read_node(kg, offset);
|
|
|
|
}
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
return;
|
2017-12-25 23:43:55 +01:00
|
|
|
}
|
2012-10-10 15:56:43 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 N = stack_valid(data_node.x)? stack_load_float3(stack, data_node.x): sd->N;
|
2011-05-13 12:11:08 +00:00
|
|
|
|
2013-06-07 16:06:17 +00:00
|
|
|
float param1 = (stack_valid(param1_offset))? stack_load_float(stack, param1_offset): __uint_as_float(node.z);
|
|
|
|
float param2 = (stack_valid(param2_offset))? stack_load_float(stack, param2_offset): __uint_as_float(node.w);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
switch(type) {
|
2017-04-21 12:56:54 +02:00
|
|
|
#ifdef __PRINCIPLED__
|
2017-04-18 11:43:09 +02:00
|
|
|
case CLOSURE_BSDF_PRINCIPLED_ID: {
|
|
|
|
uint specular_offset, roughness_offset, specular_tint_offset, anisotropic_offset, sheen_offset,
|
2017-06-21 19:24:57 +02:00
|
|
|
sheen_tint_offset, clearcoat_offset, clearcoat_roughness_offset, eta_offset, transmission_offset,
|
2017-05-18 13:15:32 +02:00
|
|
|
anisotropic_rotation_offset, transmission_roughness_offset;
|
2017-04-18 11:43:09 +02:00
|
|
|
uint4 data_node2 = read_node(kg, offset);
|
|
|
|
|
|
|
|
float3 T = stack_load_float3(stack, data_node.y);
|
|
|
|
decode_node_uchar4(data_node.z, &specular_offset, &roughness_offset, &specular_tint_offset, &anisotropic_offset);
|
2017-06-21 19:24:57 +02:00
|
|
|
decode_node_uchar4(data_node.w, &sheen_offset, &sheen_tint_offset, &clearcoat_offset, &clearcoat_roughness_offset);
|
2017-05-18 13:15:32 +02:00
|
|
|
decode_node_uchar4(data_node2.x, &eta_offset, &transmission_offset, &anisotropic_rotation_offset, &transmission_roughness_offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
// get Disney principled parameters
|
|
|
|
float metallic = param1;
|
|
|
|
float subsurface = param2;
|
|
|
|
float specular = stack_load_float(stack, specular_offset);
|
|
|
|
float roughness = stack_load_float(stack, roughness_offset);
|
|
|
|
float specular_tint = stack_load_float(stack, specular_tint_offset);
|
|
|
|
float anisotropic = stack_load_float(stack, anisotropic_offset);
|
|
|
|
float sheen = stack_load_float(stack, sheen_offset);
|
|
|
|
float sheen_tint = stack_load_float(stack, sheen_tint_offset);
|
|
|
|
float clearcoat = stack_load_float(stack, clearcoat_offset);
|
2017-06-21 19:24:57 +02:00
|
|
|
float clearcoat_roughness = stack_load_float(stack, clearcoat_roughness_offset);
|
2017-05-18 13:15:32 +02:00
|
|
|
float transmission = stack_load_float(stack, transmission_offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
float anisotropic_rotation = stack_load_float(stack, anisotropic_rotation_offset);
|
2017-05-18 13:15:32 +02:00
|
|
|
float transmission_roughness = stack_load_float(stack, transmission_roughness_offset);
|
2017-04-18 11:43:09 +02:00
|
|
|
float eta = fmaxf(stack_load_float(stack, eta_offset), 1e-5f);
|
|
|
|
|
2018-02-08 16:19:04 +01:00
|
|
|
ClosureType distribution = (ClosureType) data_node2.y;
|
|
|
|
ClosureType subsurface_method = (ClosureType) data_node2.z;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
/* rotate tangent */
|
|
|
|
if(anisotropic_rotation != 0.0f)
|
|
|
|
T = rotate_around_axis(T, N, anisotropic_rotation * M_2PI_F);
|
|
|
|
|
|
|
|
/* calculate ior */
|
|
|
|
float ior = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
|
|
|
|
|
|
|
// calculate fresnel for refraction
|
|
|
|
float cosNO = dot(N, sd->I);
|
|
|
|
float fresnel = fresnel_dielectric_cos(cosNO, ior);
|
|
|
|
|
|
|
|
// calculate weights of the diffuse and specular part
|
2017-05-18 13:15:32 +02:00
|
|
|
float diffuse_weight = (1.0f - saturate(metallic)) * (1.0f - saturate(transmission));
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-05-18 13:15:32 +02:00
|
|
|
float final_transmission = saturate(transmission) * (1.0f - saturate(metallic));
|
|
|
|
float specular_weight = (1.0f - final_transmission);
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
// get the base color
|
|
|
|
uint4 data_base_color = read_node(kg, offset);
|
|
|
|
float3 base_color = stack_valid(data_base_color.x) ? stack_load_float3(stack, data_base_color.x) :
|
|
|
|
make_float3(__uint_as_float(data_base_color.y), __uint_as_float(data_base_color.z), __uint_as_float(data_base_color.w));
|
|
|
|
|
|
|
|
// get the additional clearcoat normal and subsurface scattering radius
|
|
|
|
uint4 data_cn_ssr = read_node(kg, offset);
|
|
|
|
float3 clearcoat_normal = stack_valid(data_cn_ssr.x) ? stack_load_float3(stack, data_cn_ssr.x) : sd->N;
|
|
|
|
float3 subsurface_radius = stack_valid(data_cn_ssr.y) ? stack_load_float3(stack, data_cn_ssr.y) : make_float3(1.0f, 1.0f, 1.0f);
|
|
|
|
|
|
|
|
// get the subsurface color
|
|
|
|
uint4 data_subsurface_color = read_node(kg, offset);
|
|
|
|
float3 subsurface_color = stack_valid(data_subsurface_color.x) ? stack_load_float3(stack, data_subsurface_color.x) :
|
|
|
|
make_float3(__uint_as_float(data_subsurface_color.y), __uint_as_float(data_subsurface_color.z), __uint_as_float(data_subsurface_color.w));
|
|
|
|
|
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
|
|
|
|
|
|
|
#ifdef __SUBSURFACE__
|
2017-05-31 07:29:17 +02:00
|
|
|
float3 mixed_ss_base_color = subsurface_color * subsurface + base_color * (1.0f - subsurface);
|
|
|
|
float3 subsurf_weight = weight * mixed_ss_base_color * diffuse_weight;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
|
|
|
/* disable in case of diffuse ancestor, can't see it well then and
|
|
|
|
* adds considerably noise due to probabilities of continuing path
|
|
|
|
* getting lower and lower */
|
|
|
|
if(path_flag & PATH_RAY_DIFFUSE_ANCESTOR) {
|
|
|
|
subsurface = 0.0f;
|
2017-05-24 07:34:11 +02:00
|
|
|
|
|
|
|
/* need to set the base color in this case such that the
|
|
|
|
* rays get the correctly mixed color after transmitting
|
|
|
|
* the object */
|
2017-05-31 07:29:17 +02:00
|
|
|
base_color = mixed_ss_base_color;
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* diffuse */
|
2017-07-02 18:16:39 +02:00
|
|
|
if(fabsf(average(mixed_ss_base_color)) > CLOSURE_WEIGHT_CUTOFF) {
|
2017-07-11 23:41:22 -04:00
|
|
|
if(subsurface <= CLOSURE_WEIGHT_CUTOFF && diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 diff_weight = weight * base_color * diffuse_weight;
|
|
|
|
|
|
|
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf*)bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
|
|
|
|
|
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->roughness = roughness;
|
|
|
|
|
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf);
|
|
|
|
}
|
|
|
|
}
|
2018-01-26 22:11:28 +01:00
|
|
|
else if(subsurface > CLOSURE_WEIGHT_CUTOFF) {
|
2018-01-26 14:09:55 +01:00
|
|
|
Bssrdf *bssrdf = bssrdf_alloc(sd, subsurf_weight);
|
2018-01-26 22:11:28 +01:00
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
if(bssrdf) {
|
2018-01-26 22:11:28 +01:00
|
|
|
bssrdf->radius = subsurface_radius * subsurface;
|
2018-02-12 21:08:59 +01:00
|
|
|
bssrdf->albedo = (subsurface_method == CLOSURE_BSSRDF_PRINCIPLED_ID)? subsurface_color: mixed_ss_base_color;
|
2018-01-26 22:11:28 +01:00
|
|
|
bssrdf->texture_blur = 0.0f;
|
|
|
|
bssrdf->sharpness = 0.0f;
|
2017-04-18 11:43:09 +02:00
|
|
|
bssrdf->N = N;
|
|
|
|
bssrdf->roughness = roughness;
|
|
|
|
|
|
|
|
/* setup bsdf */
|
2018-02-08 16:19:04 +01:00
|
|
|
sd->flag |= bssrdf_setup(sd, bssrdf, subsurface_method);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* diffuse */
|
|
|
|
if(diffuse_weight > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 diff_weight = weight * base_color * diffuse_weight;
|
|
|
|
|
|
|
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf*)bsdf_alloc(sd, sizeof(PrincipledDiffuseBsdf), diff_weight);
|
|
|
|
|
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->roughness = roughness;
|
|
|
|
|
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* sheen */
|
|
|
|
if(diffuse_weight > CLOSURE_WEIGHT_CUTOFF && sheen > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float m_cdlum = linear_rgb_to_gray(base_color);
|
|
|
|
float3 m_ctint = m_cdlum > 0.0f ? base_color / m_cdlum : make_float3(1.0f, 1.0f, 1.0f); // normalize lum. to isolate hue+sat
|
|
|
|
|
|
|
|
/* color of the sheen component */
|
|
|
|
float3 sheen_color = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - sheen_tint) + m_ctint * sheen_tint;
|
|
|
|
|
|
|
|
float3 sheen_weight = weight * sheen * sheen_color * diffuse_weight;
|
|
|
|
|
|
|
|
PrincipledSheenBsdf *bsdf = (PrincipledSheenBsdf*)bsdf_alloc(sd, sizeof(PrincipledSheenBsdf), sheen_weight);
|
|
|
|
|
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
|
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_principled_sheen_setup(bsdf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* specular reflection */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
|
|
|
#endif
|
|
|
|
if(specular_weight > CLOSURE_WEIGHT_CUTOFF && (specular > CLOSURE_WEIGHT_CUTOFF || metallic > CLOSURE_WEIGHT_CUTOFF)) {
|
|
|
|
float3 spec_weight = weight * specular_weight;
|
|
|
|
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), spec_weight);
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!extra) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->ior = (2.0f / (1.0f - safe_sqrtf(0.08f * specular))) - 1.0f;
|
|
|
|
bsdf->T = T;
|
|
|
|
bsdf->extra = extra;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
float aspect = safe_sqrtf(1.0f - anisotropic * 0.9f);
|
|
|
|
float r2 = roughness * roughness;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = r2 / aspect;
|
|
|
|
bsdf->alpha_y = r2 * aspect;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
float m_cdlum = 0.3f * base_color.x + 0.6f * base_color.y + 0.1f * base_color.z; // luminance approx.
|
|
|
|
float3 m_ctint = m_cdlum > 0.0f ? base_color / m_cdlum : make_float3(0.0f, 0.0f, 0.0f); // normalize lum. to isolate hue+sat
|
|
|
|
float3 tmp_col = make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint) + m_ctint * specular_tint;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->extra->cspec0 = (specular * 0.08f * tmp_col) * (1.0f - metallic) + base_color * metallic;
|
|
|
|
bsdf->extra->color = base_color;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID || roughness <= 0.075f) /* use single-scatter GGX */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_aniso_fresnel_setup(bsdf, sd);
|
|
|
|
else /* use multi-scatter GGX */
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_aniso_fresnel_setup(bsdf, sd);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* BSDF */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_reflective || kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
|
|
|
#endif
|
2017-05-18 13:15:32 +02:00
|
|
|
if(final_transmission > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 glass_weight = weight * final_transmission;
|
2017-04-18 11:43:09 +02:00
|
|
|
float3 cspec0 = base_color * specular_tint + make_float3(1.0f, 1.0f, 1.0f) * (1.0f - specular_tint);
|
|
|
|
|
|
|
|
if(roughness <= 5e-2f || distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) { /* use single-scatter GGX */
|
|
|
|
float refl_roughness = roughness;
|
|
|
|
|
|
|
|
/* reflection */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight*fresnel);
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!extra) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->extra = extra;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = refl_roughness * refl_roughness;
|
|
|
|
bsdf->alpha_y = refl_roughness * refl_roughness;
|
|
|
|
bsdf->ior = ior;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->extra->color = base_color;
|
|
|
|
bsdf->extra->cspec0 = cspec0;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_fresnel_setup(bsdf, sd);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* refraction */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), base_color*glass_weight*(1.0f - fresnel));
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
2018-02-03 13:29:44 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra = NULL;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID)
|
|
|
|
transmission_roughness = 1.0f - (1.0f - refl_roughness) * (1.0f - transmission_roughness);
|
|
|
|
else
|
|
|
|
transmission_roughness = refl_roughness;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = transmission_roughness * transmission_roughness;
|
|
|
|
bsdf->alpha_y = transmission_roughness * transmission_roughness;
|
|
|
|
bsdf->ior = ior;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* use multi-scatter GGX */
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), glass_weight);
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!extra) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->extra = extra;
|
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = roughness * roughness;
|
|
|
|
bsdf->alpha_y = roughness * roughness;
|
|
|
|
bsdf->ior = ior;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->extra->color = base_color;
|
|
|
|
bsdf->extra->cspec0 = cspec0;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_glass_fresnel_setup(bsdf, sd);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* clearcoat */
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0) {
|
|
|
|
#endif
|
|
|
|
if(clearcoat > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight);
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-18 11:43:09 +02:00
|
|
|
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!extra) {
|
|
|
|
break;
|
|
|
|
}
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = clearcoat_normal;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->ior = 1.5f;
|
|
|
|
bsdf->extra = extra;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = clearcoat_roughness * clearcoat_roughness;
|
|
|
|
bsdf->alpha_y = clearcoat_roughness * clearcoat_roughness;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->color = make_float3(0.0f, 0.0f, 0.0f);
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.04f, 0.04f, 0.04f);
|
|
|
|
bsdf->extra->clearcoat = clearcoat;
|
2017-04-18 11:43:09 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_clearcoat_setup(bsdf, sd);
|
2017-04-18 11:43:09 +02:00
|
|
|
}
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-04-21 12:56:54 +02:00
|
|
|
#endif /* __PRINCIPLED__ */
|
2011-09-12 13:13:56 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
OrenNayarBsdf *bsdf = (OrenNayarBsdf*)bsdf_alloc(sd, sizeof(OrenNayarBsdf), weight);
|
2011-11-14 17:31:47 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2012-10-20 12:18:00 +00:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
float roughness = param1;
|
|
|
|
|
|
|
|
if(roughness == 0.0f) {
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_diffuse_setup((DiffuseBsdf*)bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->roughness = roughness;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_oren_nayar_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2012-10-20 12:18:00 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
DiffuseBsdf *bsdf = (DiffuseBsdf*)bsdf_alloc(sd, sizeof(DiffuseBsdf), weight);
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_translucent_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2018-02-20 14:22:40 +01:00
|
|
|
bsdf_transparent_setup(sd, weight, path_flag);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
2014-06-08 12:46:12 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: {
|
2011-09-12 13:13:56 +00:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2014-09-05 20:39:35 +02:00
|
|
|
if(!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight);
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = param1;
|
|
|
|
bsdf->alpha_y = param1;
|
|
|
|
bsdf->ior = 0.0f;
|
|
|
|
bsdf->extra = NULL;
|
|
|
|
|
|
|
|
/* setup bsdf */
|
|
|
|
if(type == CLOSURE_BSDF_REFLECTION_ID)
|
|
|
|
sd->flag |= bsdf_reflection_setup(bsdf);
|
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_ID)
|
|
|
|
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_GGX_ID)
|
|
|
|
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) {
|
|
|
|
kernel_assert(stack_valid(data_node.z));
|
|
|
|
bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
|
|
|
if(bsdf->extra) {
|
|
|
|
bsdf->extra->color = stack_load_float3(stack, data_node.z);
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2017-11-08 21:58:17 +01:00
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_setup(bsdf);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
}
|
2017-11-08 21:58:17 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-09-16 13:14:02 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID: {
|
2011-09-12 13:13:56 +00:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2014-09-05 20:39:35 +02:00
|
|
|
if(!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
2012-11-06 19:59:02 +00:00
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight);
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = NULL;
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2014-02-03 17:06:37 +01:00
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
2017-02-16 06:24:13 -05:00
|
|
|
eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
|
2012-11-26 21:59:41 +00:00
|
|
|
|
|
|
|
/* setup bsdf */
|
2014-06-11 19:52:14 +02:00
|
|
|
if(type == CLOSURE_BSDF_REFRACTION_ID) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = 0.0f;
|
|
|
|
bsdf->alpha_y = 0.0f;
|
|
|
|
bsdf->ior = eta;
|
2014-06-11 19:52:14 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_refraction_setup(bsdf);
|
2014-06-11 19:52:14 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = param1;
|
|
|
|
bsdf->alpha_y = param1;
|
|
|
|
bsdf->ior = eta;
|
2014-06-11 19:52:14 +02:00
|
|
|
|
|
|
|
if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
2014-06-11 19:52:14 +02:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
2014-06-11 19:52:14 +02:00
|
|
|
}
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2012-11-06 19:59:02 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID: {
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2014-09-05 20:39:35 +02:00
|
|
|
if(!kernel_data.integrator.caustics_reflective &&
|
2016-02-03 15:00:55 +01:00
|
|
|
!kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
|
|
|
|
{
|
2012-11-06 19:59:02 +00:00
|
|
|
break;
|
2014-09-05 20:39:35 +02:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-03-26 23:44:30 +01:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* index of refraction */
|
2014-02-03 17:06:37 +01:00
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
2017-02-16 06:24:13 -05:00
|
|
|
eta = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* fresnel */
|
2017-02-16 06:24:13 -05:00
|
|
|
float cosNO = dot(N, sd->I);
|
2011-04-27 11:58:34 +00:00
|
|
|
float fresnel = fresnel_dielectric_cos(cosNO, eta);
|
2011-09-12 13:13:56 +00:00
|
|
|
float roughness = param1;
|
|
|
|
|
|
|
|
/* reflection */
|
2014-09-05 20:39:35 +02:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(kernel_data.integrator.caustics_reflective || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
2016-07-25 03:03:23 +02:00
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight*fresnel);
|
|
|
|
|
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = NULL;
|
|
|
|
svm_node_glass_setup(sd, bsdf, type, eta, roughness, false);
|
2014-09-05 20:39:35 +02:00
|
|
|
}
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
/* refraction */
|
2014-09-05 20:39:35 +02:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2016-07-25 03:03:23 +02:00
|
|
|
if(kernel_data.integrator.caustics_refractive || (path_flag & PATH_RAY_DIFFUSE) == 0)
|
2014-09-05 20:39:35 +02:00
|
|
|
#endif
|
2016-07-25 03:03:23 +02:00
|
|
|
{
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight*(1.0f - fresnel));
|
2014-09-05 20:39:35 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = NULL;
|
|
|
|
svm_node_glass_setup(sd, bsdf, type, eta, roughness, true);
|
2015-06-13 18:43:14 +02:00
|
|
|
}
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: {
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(!kernel_data.integrator.caustics_reflective && !kernel_data.integrator.caustics_refractive && (path_flag & PATH_RAY_DIFFUSE))
|
|
|
|
break;
|
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight);
|
2017-11-08 21:58:17 +01:00
|
|
|
if(!bsdf) {
|
|
|
|
break;
|
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
MicrofacetExtra *extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
|
|
|
if(!extra) {
|
|
|
|
break;
|
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->extra = extra;
|
|
|
|
bsdf->T = make_float3(0.0f, 0.0f, 0.0f);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
bsdf->alpha_x = param1;
|
|
|
|
bsdf->alpha_y = param1;
|
|
|
|
float eta = fmaxf(param2, 1e-5f);
|
|
|
|
bsdf->ior = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta;
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
kernel_assert(stack_valid(data_node.z));
|
|
|
|
bsdf->extra->color = stack_load_float3(stack, data_node.z);
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
|
2017-11-08 21:58:17 +01:00
|
|
|
/* setup bsdf */
|
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_glass_setup(bsdf);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-06-08 12:46:12 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID:
|
2014-06-08 12:46:12 +02:00
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID: {
|
2011-09-12 13:13:56 +00:00
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
2014-09-05 20:39:35 +02:00
|
|
|
if(!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf*)bsdf_alloc(sd, sizeof(MicrofacetBsdf), weight);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->extra = NULL;
|
|
|
|
bsdf->T = stack_load_float3(stack, data_node.y);
|
2012-11-22 16:08:18 +00:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
/* rotate tangent */
|
2013-09-03 22:39:17 +00:00
|
|
|
float rotation = stack_load_float(stack, data_node.z);
|
2012-11-04 22:31:32 +00:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
if(rotation != 0.0f)
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F);
|
2012-11-04 22:31:32 +00:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
/* compute roughness */
|
|
|
|
float roughness = param1;
|
|
|
|
float anisotropy = clamp(param2, -0.99f, 0.99f);
|
2012-11-04 22:31:32 +00:00
|
|
|
|
2012-11-26 21:59:41 +00:00
|
|
|
if(anisotropy < 0.0f) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness/(1.0f + anisotropy);
|
|
|
|
bsdf->alpha_y = roughness*(1.0f + anisotropy);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->alpha_x = roughness*(1.0f - anisotropy);
|
|
|
|
bsdf->alpha_y = roughness/(1.0f - anisotropy);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->ior = 0.0f;
|
2014-06-04 00:39:42 +02:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID) {
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_beckmann_aniso_setup(bsdf);
|
2016-07-25 03:03:23 +02:00
|
|
|
}
|
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID) {
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_ggx_aniso_setup(bsdf);
|
2016-07-25 03:03:23 +02:00
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
else if(type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID) {
|
|
|
|
kernel_assert(stack_valid(data_node.w));
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->extra = (MicrofacetExtra*)closure_alloc_extra(sd, sizeof(MicrofacetExtra));
|
|
|
|
if(bsdf->extra) {
|
|
|
|
bsdf->extra->color = stack_load_float3(stack, data_node.w);
|
2018-01-30 12:40:05 +01:00
|
|
|
bsdf->extra->cspec0 = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
bsdf->extra->clearcoat = 0.0f;
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_microfacet_multi_ggx_aniso_setup(bsdf);
|
2016-07-25 03:03:23 +02:00
|
|
|
}
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 22:56:43 +02:00
|
|
|
}
|
2014-06-08 12:16:28 +02:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_ashikhmin_shirley_aniso_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
VelvetBsdf *bsdf = (VelvetBsdf*)bsdf_alloc(sd, sizeof(VelvetBsdf), weight);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
2012-11-26 21:59:41 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->sigma = saturate(param1);
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_ashikhmin_velvet_setup(bsdf);
|
2012-11-26 21:59:41 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-25 21:10:36 +02:00
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
#ifdef __CAUSTICS_TRICKS__
|
|
|
|
if(!kernel_data.integrator.caustics_reflective && (path_flag & PATH_RAY_DIFFUSE))
|
|
|
|
break;
|
2017-05-24 17:23:54 +02:00
|
|
|
ATTR_FALLTHROUGH;
|
2016-05-25 21:10:36 +02:00
|
|
|
#endif
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2016-07-25 03:03:23 +02:00
|
|
|
ToonBsdf *bsdf = (ToonBsdf*)bsdf_alloc(sd, sizeof(ToonBsdf), weight);
|
2013-05-23 17:45:20 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
|
|
|
bsdf->N = N;
|
|
|
|
bsdf->size = param1;
|
|
|
|
bsdf->smooth = param2;
|
2013-05-23 17:45:20 +00:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if(type == CLOSURE_BSDF_DIFFUSE_TOON_ID)
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_diffuse_toon_setup(bsdf);
|
2013-05-23 17:45:20 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_glossy_toon_setup(bsdf);
|
2013-05-23 17:45:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-09-15 23:58:00 +00:00
|
|
|
#ifdef __HAIR__
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2013-09-15 23:58:00 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
if(sd->flag & SD_BACKFACING && sd->type & PRIMITIVE_ALL_CURVE) {
|
2017-11-01 21:07:15 +01:00
|
|
|
/* todo: giving a fixed weight here will cause issues when
|
|
|
|
* mixing multiple BSDFS. energy will not be conserved and
|
|
|
|
* the throughput can blow up after multiple bounces. we
|
|
|
|
* better figure out a way to skip backfaces from rays
|
|
|
|
* spawned by transmission from the front */
|
2018-02-20 14:22:40 +01:00
|
|
|
bsdf_transparent_setup(sd, make_float3(1.0f, 1.0f, 1.0f), path_flag);
|
2013-09-15 23:58:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2016-07-25 03:03:23 +02:00
|
|
|
HairBsdf *bsdf = (HairBsdf*)bsdf_alloc(sd, sizeof(HairBsdf), weight);
|
2013-09-15 23:58:00 +00:00
|
|
|
|
2016-07-25 03:03:23 +02:00
|
|
|
if(bsdf) {
|
2017-06-28 21:25:30 +02:00
|
|
|
bsdf->N = N;
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->roughness1 = param1;
|
|
|
|
bsdf->roughness2 = param2;
|
|
|
|
bsdf->offset = -stack_load_float(stack, data_node.z);
|
2014-05-05 17:14:46 +02:00
|
|
|
|
2015-10-11 19:43:30 +05:00
|
|
|
if(stack_valid(data_node.y)) {
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->T = normalize(stack_load_float3(stack, data_node.y));
|
2015-10-11 19:43:30 +05:00
|
|
|
}
|
2017-02-16 06:24:13 -05:00
|
|
|
else if(!(sd->type & PRIMITIVE_ALL_CURVE)) {
|
|
|
|
bsdf->T = normalize(sd->dPdv);
|
2016-07-25 03:03:23 +02:00
|
|
|
bsdf->offset = 0.0f;
|
2013-09-15 23:58:00 +00:00
|
|
|
}
|
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
bsdf->T = normalize(sd->dPdu);
|
2014-05-05 17:14:46 +02:00
|
|
|
|
2013-09-15 23:58:00 +00:00
|
|
|
if(type == CLOSURE_BSDF_HAIR_REFLECTION_ID) {
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_hair_reflection_setup(bsdf);
|
2013-09-15 23:58:00 +00:00
|
|
|
}
|
|
|
|
else {
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= bsdf_hair_transmission_setup(bsdf);
|
2013-09-15 23:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-01 20:26:52 +00:00
|
|
|
#ifdef __SUBSURFACE__
|
2013-08-18 14:15:57 +00:00
|
|
|
case CLOSURE_BSSRDF_CUBIC_ID:
|
2016-02-04 03:34:49 +05:00
|
|
|
case CLOSURE_BSSRDF_GAUSSIAN_ID:
|
2018-01-21 14:04:22 +01:00
|
|
|
case CLOSURE_BSSRDF_BURLEY_ID:
|
|
|
|
case CLOSURE_BSSRDF_RANDOM_WALK_ID: {
|
2017-02-16 06:24:13 -05:00
|
|
|
float3 weight = sd->svm_closure_weight * mix_weight;
|
2018-01-26 22:11:28 +01:00
|
|
|
Bssrdf *bssrdf = bssrdf_alloc(sd, weight);
|
|
|
|
|
|
|
|
if(bssrdf) {
|
|
|
|
/* disable in case of diffuse ancestor, can't see it well then and
|
|
|
|
* adds considerably noise due to probabilities of continuing path
|
|
|
|
* getting lower and lower */
|
|
|
|
if(path_flag & PATH_RAY_DIFFUSE_ANCESTOR)
|
|
|
|
param1 = 0.0f;
|
|
|
|
|
|
|
|
bssrdf->radius = stack_load_float3(stack, data_node.z)*param1;
|
|
|
|
bssrdf->albedo = sd->svm_closure_weight;
|
|
|
|
bssrdf->texture_blur = param2;
|
|
|
|
bssrdf->sharpness = stack_load_float(stack, data_node.w);
|
|
|
|
bssrdf->N = N;
|
2018-02-08 16:19:04 +01:00
|
|
|
bssrdf->roughness = 0.0f;
|
2018-01-26 22:11:28 +01:00
|
|
|
sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type);
|
2013-04-01 20:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
2011-09-12 13:13:56 +00:00
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
ccl_device void svm_node_closure_volume(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type)
|
2011-09-27 20:03:16 +00:00
|
|
|
{
|
2014-01-07 15:48:04 +01:00
|
|
|
#ifdef __VOLUME__
|
2017-12-25 23:43:55 +01:00
|
|
|
/* Only sum extinction for volumes, variable is shared with surface transparency. */
|
|
|
|
if(shader_type != SHADER_TYPE_VOLUME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
uint type, density_offset, anisotropy_offset;
|
2011-09-27 20:03:16 +00:00
|
|
|
|
|
|
|
uint mix_weight_offset;
|
2018-01-30 15:05:19 +01:00
|
|
|
decode_node_uchar4(node.y, &type, &density_offset, &anisotropy_offset, &mix_weight_offset);
|
2011-09-27 20:03:16 +00:00
|
|
|
float mix_weight = (stack_valid(mix_weight_offset)? stack_load_float(stack, mix_weight_offset): 1.0f);
|
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
if(mix_weight == 0.0f) {
|
2011-09-27 20:03:16 +00:00
|
|
|
return;
|
2018-01-30 15:05:19 +01:00
|
|
|
}
|
2011-09-27 20:03:16 +00:00
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
float density = (stack_valid(density_offset))? stack_load_float(stack, density_offset): __uint_as_float(node.z);
|
|
|
|
density = mix_weight * fmaxf(density, 0.0f);
|
2011-09-27 20:03:16 +00:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
/* Compute scattering coefficient. */
|
|
|
|
float3 weight = sd->svm_closure_weight;
|
2011-09-27 20:03:16 +00:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
if(type == CLOSURE_VOLUME_ABSORPTION_ID) {
|
|
|
|
weight = make_float3(1.0f, 1.0f, 1.0f) - weight;
|
|
|
|
}
|
2011-09-27 20:03:16 +00:00
|
|
|
|
2017-11-01 21:07:15 +01:00
|
|
|
weight *= density;
|
|
|
|
|
|
|
|
/* Add closure for volume scattering. */
|
|
|
|
if(type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID) {
|
|
|
|
HenyeyGreensteinVolume *volume = (HenyeyGreensteinVolume*)bsdf_alloc(sd, sizeof(HenyeyGreensteinVolume), weight);
|
|
|
|
|
|
|
|
if(volume) {
|
2018-01-30 15:05:19 +01:00
|
|
|
float anisotropy = (stack_valid(anisotropy_offset))? stack_load_float(stack, anisotropy_offset): __uint_as_float(node.w);
|
|
|
|
volume->g = anisotropy; /* g */
|
2017-11-01 21:07:15 +01:00
|
|
|
sd->flag |= volume_henyey_greenstein_setup(volume);
|
2011-09-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-01 21:07:15 +01:00
|
|
|
|
|
|
|
/* Sum total extinction weight. */
|
|
|
|
volume_extinction_setup(sd, weight);
|
2014-01-07 15:48:04 +01:00
|
|
|
#endif
|
2011-09-27 20:03:16 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 15:05:19 +01:00
|
|
|
ccl_device void svm_node_principled_volume(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, ShaderType shader_type, int path_flag, int *offset)
|
|
|
|
{
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
uint4 value_node = read_node(kg, offset);
|
|
|
|
uint4 attr_node = read_node(kg, offset);
|
|
|
|
|
|
|
|
/* Only sum extinction for volumes, variable is shared with surface transparency. */
|
|
|
|
if(shader_type != SHADER_TYPE_VOLUME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint density_offset, anisotropy_offset, absorption_color_offset, mix_weight_offset;
|
|
|
|
decode_node_uchar4(node.y, &density_offset, &anisotropy_offset, &absorption_color_offset, &mix_weight_offset);
|
|
|
|
float mix_weight = (stack_valid(mix_weight_offset)? stack_load_float(stack, mix_weight_offset): 1.0f);
|
|
|
|
|
|
|
|
if(mix_weight == 0.0f) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute density. */
|
|
|
|
float primitive_density = 1.0f;
|
|
|
|
float density = (stack_valid(density_offset))? stack_load_float(stack, density_offset): __uint_as_float(value_node.x);
|
|
|
|
density = mix_weight * fmaxf(density, 0.0f);
|
|
|
|
|
|
|
|
if(density > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
/* Density and color attribute lookup if available. */
|
|
|
|
const AttributeDescriptor attr_density = find_attribute(kg, sd, attr_node.x);
|
|
|
|
if(attr_density.offset != ATTR_STD_NOT_FOUND) {
|
|
|
|
primitive_density = primitive_attribute_float(kg, sd, attr_density, NULL, NULL);
|
|
|
|
density = fmaxf(density * primitive_density, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(density > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
/* Compute scattering color. */
|
|
|
|
float3 color = sd->svm_closure_weight;
|
|
|
|
|
|
|
|
const AttributeDescriptor attr_color = find_attribute(kg, sd, attr_node.y);
|
|
|
|
if(attr_color.offset != ATTR_STD_NOT_FOUND) {
|
|
|
|
color *= primitive_attribute_float3(kg, sd, attr_color, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add closure for volume scattering. */
|
|
|
|
HenyeyGreensteinVolume *volume = (HenyeyGreensteinVolume*)bsdf_alloc(sd, sizeof(HenyeyGreensteinVolume), color * density);
|
|
|
|
if(volume) {
|
|
|
|
float anisotropy = (stack_valid(anisotropy_offset))? stack_load_float(stack, anisotropy_offset): __uint_as_float(value_node.y);
|
|
|
|
volume->g = anisotropy;
|
|
|
|
sd->flag |= volume_henyey_greenstein_setup(volume);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add extinction weight. */
|
|
|
|
float3 zero = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
float3 one = make_float3(1.0f, 1.0f, 1.0f);
|
2018-02-28 04:36:55 +01:00
|
|
|
float3 absorption_color = max(sqrt(stack_load_float3(stack, absorption_color_offset)), zero);
|
2018-01-30 15:05:19 +01:00
|
|
|
float3 absorption = max(one - color, zero) * max(one - absorption_color, zero);
|
|
|
|
volume_extinction_setup(sd, (color + absorption) * density);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute emission. */
|
|
|
|
if(path_flag & PATH_RAY_SHADOW) {
|
|
|
|
/* Don't need emission for shadows. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint emission_offset, emission_color_offset, blackbody_offset, temperature_offset;
|
|
|
|
decode_node_uchar4(node.z, &emission_offset, &emission_color_offset, &blackbody_offset, &temperature_offset);
|
|
|
|
float emission = (stack_valid(emission_offset))? stack_load_float(stack, emission_offset): __uint_as_float(value_node.z);
|
|
|
|
float blackbody = (stack_valid(blackbody_offset))? stack_load_float(stack, blackbody_offset): __uint_as_float(value_node.w);
|
|
|
|
|
|
|
|
if(emission > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 emission_color = stack_load_float3(stack, emission_color_offset);
|
|
|
|
emission_setup(sd, emission * emission_color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(blackbody > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float T = stack_load_float(stack, temperature_offset);
|
|
|
|
|
|
|
|
/* Add flame temperature from attribute if available. */
|
|
|
|
const AttributeDescriptor attr_temperature = find_attribute(kg, sd, attr_node.z);
|
|
|
|
if(attr_temperature.offset != ATTR_STD_NOT_FOUND) {
|
|
|
|
float temperature = primitive_attribute_float(kg, sd, attr_temperature, NULL, NULL);
|
|
|
|
T *= fmaxf(temperature, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
T = fmaxf(T, 0.0f);
|
|
|
|
|
|
|
|
/* Stefan-Boltzmann law. */
|
|
|
|
float T4 = sqr(sqr(T));
|
|
|
|
float sigma = 5.670373e-8f * 1e-6f / M_PI_F;
|
|
|
|
float intensity = sigma * mix(1.0f, T4, blackbody);
|
|
|
|
|
|
|
|
if(intensity > CLOSURE_WEIGHT_CUTOFF) {
|
|
|
|
float3 blackbody_tint = stack_load_float3(stack, node.w);
|
|
|
|
float3 bb = blackbody_tint * intensity * svm_math_blackbody_color(T);
|
|
|
|
emission_setup(sd, bb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_emission(ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
2017-11-01 19:00:42 +01:00
|
|
|
float3 weight = sd->svm_closure_weight;
|
2011-09-12 13:13:56 +00:00
|
|
|
|
|
|
|
if(stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if(mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
weight *= mix_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
emission_setup(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_background(ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-10-19 00:13:41 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
2017-11-01 19:00:42 +01:00
|
|
|
float3 weight = sd->svm_closure_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
|
|
|
|
if(stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if(mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-11-01 19:00:42 +01:00
|
|
|
weight *= mix_weight;
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2017-11-01 19:00:42 +01:00
|
|
|
|
|
|
|
background_setup(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_holdout(ShaderData *sd, float *stack, uint4 node)
|
2011-08-28 13:55:59 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
uint mix_weight_offset = node.y;
|
|
|
|
|
|
|
|
if(stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if(mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight * mix_weight);
|
2011-10-19 00:13:41 +00:00
|
|
|
}
|
2012-11-30 18:55:04 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_HOLDOUT_ID, sd->svm_closure_weight);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= SD_HOLDOUT;
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_ambient_occlusion(ShaderData *sd, float *stack, uint4 node)
|
2012-11-06 19:59:02 +00:00
|
|
|
{
|
|
|
|
uint mix_weight_offset = node.y;
|
|
|
|
|
|
|
|
if(stack_valid(mix_weight_offset)) {
|
|
|
|
float mix_weight = stack_load_float(stack, mix_weight_offset);
|
|
|
|
|
|
|
|
if(mix_weight == 0.0f)
|
|
|
|
return;
|
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_AMBIENT_OCCLUSION_ID, sd->svm_closure_weight * mix_weight);
|
2012-11-06 19:59:02 +00:00
|
|
|
}
|
2012-11-30 18:55:04 +00:00
|
|
|
else
|
2017-02-16 06:24:13 -05:00
|
|
|
closure_alloc(sd, sizeof(ShaderClosure), CLOSURE_AMBIENT_OCCLUSION_ID, sd->svm_closure_weight);
|
2012-11-06 19:59:02 +00:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->flag |= SD_AO;
|
2012-11-06 19:59:02 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Closure Nodes */
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device_inline void svm_node_closure_store_weight(ShaderData *sd, float3 weight)
|
2011-09-12 13:13:56 +00:00
|
|
|
{
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->svm_closure_weight = weight;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_set_weight(ShaderData *sd, uint r, uint g, uint b)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-06-07 16:06:17 +00:00
|
|
|
float3 weight = make_float3(__uint_as_float(r), __uint_as_float(g), __uint_as_float(b));
|
2011-09-12 13:13:56 +00:00
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_closure_weight(ShaderData *sd, float *stack, uint weight_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
float3 weight = stack_load_float3(stack, weight_offset);
|
|
|
|
|
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_emission_weight(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
uint color_offset = node.y;
|
|
|
|
uint strength_offset = node.z;
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
float strength = stack_load_float(stack, strength_offset);
|
|
|
|
float3 weight = stack_load_float3(stack, color_offset)*strength;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
svm_node_closure_store_weight(sd, weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-21 15:53:20 +02:00
|
|
|
ccl_device void svm_node_mix_closure(ShaderData *sd, float *stack, uint4 node)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
/* fetch weight from blend input, previous mix closures,
|
2012-06-09 17:22:52 +00:00
|
|
|
* and write to stack to be used by closure nodes later */
|
2011-09-12 13:13:56 +00:00
|
|
|
uint weight_offset, in_weight_offset, weight1_offset, weight2_offset;
|
|
|
|
decode_node_uchar4(node.y, &weight_offset, &in_weight_offset, &weight1_offset, &weight2_offset);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float weight = stack_load_float(stack, weight_offset);
|
2015-04-28 00:13:03 +05:00
|
|
|
weight = saturate(weight);
|
2013-06-01 12:23:49 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
float in_weight = (stack_valid(in_weight_offset))? stack_load_float(stack, in_weight_offset): 1.0f;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
if(stack_valid(weight1_offset))
|
|
|
|
stack_store_float(stack, weight1_offset, in_weight*(1.0f - weight));
|
|
|
|
if(stack_valid(weight2_offset))
|
|
|
|
stack_store_float(stack, weight2_offset, in_weight*weight);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 15:56:43 +00:00
|
|
|
/* (Bump) normal */
|
|
|
|
|
2013-11-16 00:17:10 +01:00
|
|
|
ccl_device void svm_node_set_normal(KernelGlobals *kg, ShaderData *sd, float *stack, uint in_direction, uint out_normal)
|
2012-10-10 15:56:43 +00:00
|
|
|
{
|
|
|
|
float3 normal = stack_load_float3(stack, in_direction);
|
2017-02-16 06:24:13 -05:00
|
|
|
sd->N = normal;
|
2012-10-10 15:56:43 +00:00
|
|
|
stack_store_float3(stack, out_normal, normal);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|