Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/osl/osl_bssrdf.cpp
| Show All 26 Lines | |||||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
| */ | */ | ||||
| #include <OSL/genclosure.h> | #include <OSL/genclosure.h> | ||||
| #include "kernel/kernel_compat_cpu.h" | #include "kernel/device/cpu/compat.h" | ||||
| #include "kernel/osl/osl_closures.h" | #include "kernel/osl/osl_closures.h" | ||||
| // clang-format off | // clang-format off | ||||
| #include "kernel/kernel_types.h" | #include "kernel/kernel_types.h" | ||||
| #include "kernel/kernel_montecarlo.h" | #include "kernel/kernel_montecarlo.h" | ||||
| #include "kernel/closure/alloc.h" | #include "kernel/closure/alloc.h" | ||||
| #include "kernel/closure/bsdf_util.h" | #include "kernel/closure/bsdf_util.h" | ||||
| #include "kernel/closure/bsdf_diffuse.h" | #include "kernel/closure/bsdf_diffuse.h" | ||||
| #include "kernel/closure/bsdf_principled_diffuse.h" | #include "kernel/closure/bsdf_principled_diffuse.h" | ||||
| #include "kernel/closure/bssrdf.h" | #include "kernel/closure/bssrdf.h" | ||||
| // clang-format on | // clang-format on | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| using namespace OSL; | using namespace OSL; | ||||
| static ustring u_cubic("cubic"); | static ustring u_random_walk_fixed_radius("random_walk_fixed_radius"); | ||||
| static ustring u_gaussian("gaussian"); | |||||
| static ustring u_burley("burley"); | |||||
| static ustring u_principled("principled"); | |||||
| static ustring u_random_walk("random_walk"); | static ustring u_random_walk("random_walk"); | ||||
| static ustring u_principled_random_walk("principled_random_walk"); | |||||
| class CBSSRDFClosure : public CClosurePrimitive { | class CBSSRDFClosure : public CClosurePrimitive { | ||||
| public: | public: | ||||
| Bssrdf params; | Bssrdf params; | ||||
| float ior; | |||||
| ustring method; | ustring method; | ||||
| CBSSRDFClosure() | CBSSRDFClosure() | ||||
| { | { | ||||
| params.texture_blur = 0.0f; | params.roughness = FLT_MAX; | ||||
| params.sharpness = 0.0f; | params.anisotropy = 1.0f; | ||||
| params.roughness = 0.0f; | ior = 1.4f; | ||||
| } | } | ||||
| void setup(ShaderData *sd, int path_flag, float3 weight) | void setup(ShaderData *sd, int path_flag, float3 weight) | ||||
| { | { | ||||
| if (method == u_cubic) { | if (method == u_random_walk_fixed_radius) { | ||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_CUBIC_ID); | alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID); | ||||
| } | |||||
| else if (method == u_gaussian) { | |||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_GAUSSIAN_ID); | |||||
| } | |||||
| else if (method == u_burley) { | |||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_BURLEY_ID); | |||||
| } | |||||
| else if (method == u_principled) { | |||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_ID); | |||||
| } | } | ||||
| else if (method == u_random_walk) { | else if (method == u_random_walk) { | ||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_ID); | alloc(sd, path_flag, weight, CLOSURE_BSSRDF_RANDOM_WALK_ID); | ||||
| } | } | ||||
| else if (method == u_principled_random_walk) { | |||||
| alloc(sd, path_flag, weight, CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID); | |||||
| } | |||||
| } | } | ||||
| void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType type) | void alloc(ShaderData *sd, int path_flag, float3 weight, ClosureType type) | ||||
| { | { | ||||
| Bssrdf *bssrdf = bssrdf_alloc(sd, weight); | Bssrdf *bssrdf = bssrdf_alloc(sd, weight); | ||||
| if (bssrdf) { | if (bssrdf) { | ||||
| /* disable in case of diffuse ancestor, can't see it well then and | /* disable in case of diffuse ancestor, can't see it well then and | ||||
| * adds considerably noise due to probabilities of continuing path | * adds considerably noise due to probabilities of continuing path | ||||
| * getting lower and lower */ | * getting lower and lower */ | ||||
| if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) { | if (path_flag & PATH_RAY_DIFFUSE_ANCESTOR) { | ||||
| params.radius = make_float3(0.0f, 0.0f, 0.0f); | params.radius = make_float3(0.0f, 0.0f, 0.0f); | ||||
| } | } | ||||
| /* create one closure per color channel */ | /* create one closure per color channel */ | ||||
| bssrdf->radius = params.radius; | bssrdf->radius = params.radius; | ||||
| bssrdf->albedo = params.albedo; | bssrdf->albedo = params.albedo; | ||||
| bssrdf->texture_blur = params.texture_blur; | |||||
| bssrdf->sharpness = params.sharpness; | |||||
| bssrdf->N = params.N; | bssrdf->N = params.N; | ||||
| bssrdf->roughness = params.roughness; | bssrdf->roughness = params.roughness; | ||||
| sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type); | bssrdf->anisotropy = clamp(params.anisotropy, 0.0f, 0.9f); | ||||
| sd->flag |= bssrdf_setup(sd, bssrdf, (ClosureType)type, clamp(ior, 1.01f, 3.8f)); | |||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| ClosureParam *closure_bssrdf_params() | ClosureParam *closure_bssrdf_params() | ||||
| { | { | ||||
| static ClosureParam params[] = { | static ClosureParam params[] = { | ||||
| CLOSURE_STRING_PARAM(CBSSRDFClosure, method), | CLOSURE_STRING_PARAM(CBSSRDFClosure, method), | ||||
| CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.N), | CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.N), | ||||
| CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.radius), | CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.radius), | ||||
| CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.albedo), | CLOSURE_FLOAT3_PARAM(CBSSRDFClosure, params.albedo), | ||||
| CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.texture_blur, "texture_blur"), | |||||
| CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.sharpness, "sharpness"), | |||||
| CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, "roughness"), | CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.roughness, "roughness"), | ||||
| CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, ior, "ior"), | |||||
| CLOSURE_FLOAT_KEYPARAM(CBSSRDFClosure, params.anisotropy, "anisotropy"), | |||||
| CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"), | CLOSURE_STRING_KEYPARAM(CBSSRDFClosure, label, "label"), | ||||
| CLOSURE_FINISH_PARAM(CBSSRDFClosure)}; | CLOSURE_FINISH_PARAM(CBSSRDFClosure)}; | ||||
| return params; | return params; | ||||
| } | } | ||||
| CCLOSURE_PREPARE(closure_bssrdf_prepare, CBSSRDFClosure) | CCLOSURE_PREPARE(closure_bssrdf_prepare, CBSSRDFClosure) | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||