Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/closure/bsdf.h
| /* | /* | ||||
| * Copyright 2011-2013 Blender Foundation | * Copyright 2011-2013 Blender Foundation | ||||
| * | * | ||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| * You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
| * | * | ||||
| * http://www.apache.org/licenses/LICENSE-2.0 | * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | * | ||||
| * Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #pragma once | |||||
| // clang-format off | // clang-format off | ||||
| #include "kernel/closure/bsdf_ashikhmin_velvet.h" | #include "kernel/closure/bsdf_ashikhmin_velvet.h" | ||||
| #include "kernel/closure/bsdf_diffuse.h" | #include "kernel/closure/bsdf_diffuse.h" | ||||
| #include "kernel/closure/bsdf_oren_nayar.h" | #include "kernel/closure/bsdf_oren_nayar.h" | ||||
| #include "kernel/closure/bsdf_phong_ramp.h" | #include "kernel/closure/bsdf_phong_ramp.h" | ||||
| #include "kernel/closure/bsdf_diffuse_ramp.h" | #include "kernel/closure/bsdf_diffuse_ramp.h" | ||||
| #include "kernel/closure/bsdf_microfacet.h" | #include "kernel/closure/bsdf_microfacet.h" | ||||
| #include "kernel/closure/bsdf_microfacet_multi.h" | #include "kernel/closure/bsdf_microfacet_multi.h" | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| cos_in = min(cos_in, 1.0f); | cos_in = min(cos_in, 1.0f); | ||||
| const float angle = fast_acosf(cos_in); | const float angle = fast_acosf(cos_in); | ||||
| const float val = max(cosf(angle * frequency_multiplier), 0.0f) / cos_in; | const float val = max(cosf(angle * frequency_multiplier), 0.0f) / cos_in; | ||||
| return val; | return val; | ||||
| } | } | ||||
| ccl_device_inline int bsdf_sample(KernelGlobals *kg, | ccl_device_inline int bsdf_sample(const KernelGlobals *kg, | ||||
| ShaderData *sd, | ShaderData *sd, | ||||
| const ShaderClosure *sc, | const ShaderClosure *sc, | ||||
| float randu, | float randu, | ||||
| float randv, | float randv, | ||||
| float3 *eval, | float3 *eval, | ||||
| float3 *omega_in, | float3 *omega_in, | ||||
| differential3 *domega_in, | differential3 *domega_in, | ||||
| float *pdf) | float *pdf) | ||||
| ▲ Show 20 Lines • Show All 303 Lines • ▼ Show 20 Lines | case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID: | ||||
| eval, | eval, | ||||
| omega_in, | omega_in, | ||||
| &domega_in->dx, | &domega_in->dx, | ||||
| &domega_in->dy, | &domega_in->dy, | ||||
| pdf); | pdf); | ||||
| break; | break; | ||||
| # endif /* __PRINCIPLED__ */ | # endif /* __PRINCIPLED__ */ | ||||
| #endif | #endif | ||||
| #ifdef __VOLUME__ | |||||
| case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID: | |||||
| label = volume_henyey_greenstein_sample(sc, | |||||
| sd->I, | |||||
| sd->dI.dx, | |||||
| sd->dI.dy, | |||||
| randu, | |||||
| randv, | |||||
| eval, | |||||
| omega_in, | |||||
| &domega_in->dx, | |||||
| &domega_in->dy, | |||||
| pdf); | |||||
| break; | |||||
| #endif | |||||
| default: | default: | ||||
| label = LABEL_NONE; | label = LABEL_NONE; | ||||
| break; | break; | ||||
| } | } | ||||
| /* Test if BSDF sample should be treated as transparent for background. */ | /* Test if BSDF sample should be treated as transparent for background. */ | ||||
| if (label & LABEL_TRANSMIT) { | if (label & LABEL_TRANSMIT) { | ||||
| float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold; | float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold; | ||||
| Show All 22 Lines | |||||
| } | } | ||||
| #ifndef __KERNEL_CUDA__ | #ifndef __KERNEL_CUDA__ | ||||
| ccl_device | ccl_device | ||||
| #else | #else | ||||
| ccl_device_inline | ccl_device_inline | ||||
| #endif | #endif | ||||
| float3 | float3 | ||||
| bsdf_eval(KernelGlobals *kg, | bsdf_eval(const KernelGlobals *kg, | ||||
| ShaderData *sd, | ShaderData *sd, | ||||
| const ShaderClosure *sc, | const ShaderClosure *sc, | ||||
| const float3 omega_in, | const float3 omega_in, | ||||
| const bool is_transmission, | |||||
| float *pdf) | float *pdf) | ||||
| { | { | ||||
| float3 eval; | float3 eval = zero_float3(); | ||||
| if (dot(sd->N, omega_in) >= 0.0f) { | if (!is_transmission) { | ||||
| switch (sc->type) { | switch (sc->type) { | ||||
| case CLOSURE_BSDF_DIFFUSE_ID: | case CLOSURE_BSDF_DIFFUSE_ID: | ||||
| case CLOSURE_BSDF_BSSRDF_ID: | case CLOSURE_BSDF_BSSRDF_ID: | ||||
| eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf); | eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf); | ||||
| break; | break; | ||||
| #ifdef __SVM__ | #ifdef __SVM__ | ||||
| case CLOSURE_BSDF_OREN_NAYAR_ID: | case CLOSURE_BSDF_OREN_NAYAR_ID: | ||||
| eval = bsdf_oren_nayar_eval_reflect(sc, sd->I, omega_in, pdf); | eval = bsdf_oren_nayar_eval_reflect(sc, sd->I, omega_in, pdf); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | # ifdef __PRINCIPLED__ | ||||
| case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID: | case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID: | ||||
| eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf); | eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf); | ||||
| break; | break; | ||||
| case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID: | case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID: | ||||
| eval = bsdf_principled_sheen_eval_reflect(sc, sd->I, omega_in, pdf); | eval = bsdf_principled_sheen_eval_reflect(sc, sd->I, omega_in, pdf); | ||||
| break; | break; | ||||
| # endif /* __PRINCIPLED__ */ | # endif /* __PRINCIPLED__ */ | ||||
| #endif | #endif | ||||
| #ifdef __VOLUME__ | |||||
| case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID: | |||||
| eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf); | |||||
| break; | |||||
| #endif | |||||
| default: | default: | ||||
| eval = make_float3(0.0f, 0.0f, 0.0f); | |||||
| break; | break; | ||||
| } | } | ||||
| if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) { | if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) { | ||||
| if (!isequal_float3(sc->N, sd->N)) { | if (!isequal_float3(sc->N, sd->N)) { | ||||
| eval *= bump_shadowing_term(sd->N, sc->N, omega_in); | eval *= bump_shadowing_term(sd->N, sc->N, omega_in); | ||||
| } | } | ||||
| } | } | ||||
| /* Shadow terminator offset. */ | /* Shadow terminator offset. */ | ||||
| ▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | # ifdef __PRINCIPLED__ | ||||
| case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID: | case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID: | ||||
| eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf); | eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf); | ||||
| break; | break; | ||||
| case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID: | case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID: | ||||
| eval = bsdf_principled_sheen_eval_transmit(sc, sd->I, omega_in, pdf); | eval = bsdf_principled_sheen_eval_transmit(sc, sd->I, omega_in, pdf); | ||||
| break; | break; | ||||
| # endif /* __PRINCIPLED__ */ | # endif /* __PRINCIPLED__ */ | ||||
| #endif | #endif | ||||
| #ifdef __VOLUME__ | |||||
| case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID: | |||||
| eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf); | |||||
| break; | |||||
| #endif | |||||
| default: | default: | ||||
| eval = make_float3(0.0f, 0.0f, 0.0f); | |||||
| break; | break; | ||||
| } | } | ||||
| if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) { | if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) { | ||||
| if (!isequal_float3(sc->N, sd->N)) { | if (!isequal_float3(sc->N, sd->N)) { | ||||
| eval *= bump_shadowing_term(-sd->N, sc->N, omega_in); | eval *= bump_shadowing_term(-sd->N, sc->N, omega_in); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return eval; | return eval; | ||||
| } | } | ||||
| ccl_device void bsdf_blur(KernelGlobals *kg, ShaderClosure *sc, float roughness) | ccl_device void bsdf_blur(const KernelGlobals *kg, ShaderClosure *sc, float roughness) | ||||
| { | { | ||||
| /* ToDo: do we want to blur volume closures? */ | /* ToDo: do we want to blur volume closures? */ | ||||
| #ifdef __SVM__ | #ifdef __SVM__ | ||||
| switch (sc->type) { | switch (sc->type) { | ||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: | case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: | ||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID: | case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID: | ||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: | case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: | ||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID: | case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID: | ||||
| Show All 16 Lines | case CLOSURE_BSDF_HAIR_PRINCIPLED_ID: | ||||
| bsdf_principled_hair_blur(sc, roughness); | bsdf_principled_hair_blur(sc, roughness); | ||||
| break; | break; | ||||
| default: | default: | ||||
| break; | break; | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| ccl_device bool bsdf_merge(ShaderClosure *a, ShaderClosure *b) | |||||
| { | |||||
| #ifdef __SVM__ | |||||
| switch (a->type) { | |||||
| case CLOSURE_BSDF_TRANSPARENT_ID: | |||||
| return true; | |||||
| case CLOSURE_BSDF_DIFFUSE_ID: | |||||
| case CLOSURE_BSDF_BSSRDF_ID: | |||||
| case CLOSURE_BSDF_TRANSLUCENT_ID: | |||||
| return bsdf_diffuse_merge(a, b); | |||||
| case CLOSURE_BSDF_OREN_NAYAR_ID: | |||||
| return bsdf_oren_nayar_merge(a, b); | |||||
| case CLOSURE_BSDF_REFLECTION_ID: | |||||
| case CLOSURE_BSDF_REFRACTION_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_GGX_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_BECKMANN_ID: | |||||
| case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID: | |||||
| case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID: | |||||
| return bsdf_microfacet_merge(a, b); | |||||
| case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID: | |||||
| return bsdf_ashikhmin_velvet_merge(a, b); | |||||
| case CLOSURE_BSDF_DIFFUSE_TOON_ID: | |||||
| case CLOSURE_BSDF_GLOSSY_TOON_ID: | |||||
| return bsdf_toon_merge(a, b); | |||||
| case CLOSURE_BSDF_HAIR_REFLECTION_ID: | |||||
| case CLOSURE_BSDF_HAIR_TRANSMISSION_ID: | |||||
| return bsdf_hair_merge(a, b); | |||||
| # ifdef __PRINCIPLED__ | |||||
| case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID: | |||||
| case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID: | |||||
| return bsdf_principled_diffuse_merge(a, b); | |||||
| # endif | |||||
| # ifdef __VOLUME__ | |||||
| case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID: | |||||
| return volume_henyey_greenstein_merge(a, b); | |||||
| # endif | |||||
| default: | |||||
| return false; | |||||
| } | |||||
| #else | |||||
| return false; | |||||
| #endif | |||||
| } | |||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||