Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/kernel/kernel_shader.h
| Show All 21 Lines | |||||
| * Evaluate one or more closures. | * Evaluate one or more closures. | ||||
| * Release. | * Release. | ||||
| * | * | ||||
| */ | */ | ||||
| #include "closure/bsdf_util.h" | #include "closure/bsdf_util.h" | ||||
| #include "closure/bsdf.h" | #include "closure/bsdf.h" | ||||
| #include "closure/emissive.h" | #include "closure/emissive.h" | ||||
| #include "closure/merge.h" | |||||
| #include "svm/svm.h" | #include "svm/svm.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| /* ShaderData setup from incoming ray */ | /* ShaderData setup from incoming ray */ | ||||
| #ifdef __OBJECT_MOTION__ | #ifdef __OBJECT_MOTION__ | ||||
| ▲ Show 20 Lines • Show All 398 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| /* for NDC coordinates */ | /* for NDC coordinates */ | ||||
| sd->ray_P = ray->P; | sd->ray_P = ray->P; | ||||
| sd->ray_dP = ray->dP; | sd->ray_dP = ray->dP; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Merging */ | |||||
| #if defined(__BRANCHED_PATH__) || defined(__VOLUME__) | |||||
| ccl_device void shader_merge_closures(ShaderData *sd) | |||||
| { | |||||
| /* merge identical closures, better when we sample a single closure at a time */ | |||||
| for(int i = 0; i < sd->num_closure; i++) { | |||||
| ShaderClosure *sci = &sd->closure[i]; | |||||
| for(int j = i + 1; j < sd->num_closure; j++) { | |||||
| ShaderClosure *scj = &sd->closure[j]; | |||||
| #ifdef __OSL__ | |||||
| if(sci->prim || scj->prim) | |||||
| continue; | |||||
| #endif | |||||
| if(!(sci->type == scj->type && sci->data0 == scj->data0 && sci->data1 == scj->data1 && sci->data2 == scj->data2)) | |||||
| continue; | |||||
| if(CLOSURE_IS_BSDF_OR_BSSRDF(sci->type)) { | |||||
| if(sci->N != scj->N) | |||||
| continue; | |||||
| else if(CLOSURE_IS_BSDF_ANISOTROPIC(sci->type) && sci->T != scj->T) | |||||
| continue; | |||||
| } | |||||
| sci->weight += scj->weight; | |||||
| sci->sample_weight += scj->sample_weight; | |||||
| int size = sd->num_closure - (j+1); | |||||
| if(size > 0) { | |||||
| for(int k = 0; k < size; k++) { | |||||
| scj[k] = scj[k+1]; | |||||
| } | |||||
| } | |||||
| sd->num_closure--; | |||||
| kernel_assert(sd->num_closure >= 0); | |||||
| j--; | |||||
| } | |||||
| } | |||||
| } | |||||
| #endif | |||||
| /* BSDF */ | /* BSDF */ | ||||
| ccl_device_inline void _shader_bsdf_multi_eval(KernelGlobals *kg, const ShaderData *sd, const float3 omega_in, float *pdf, | ccl_device_inline void _shader_bsdf_multi_eval(KernelGlobals *kg, const ShaderData *sd, const float3 omega_in, float *pdf, | ||||
| int skip_bsdf, BsdfEval *result_eval, float sum_pdf, float sum_sample_weight) | int skip_bsdf, BsdfEval *result_eval, float sum_pdf, float sum_sample_weight) | ||||
| { | { | ||||
| /* this is the veach one-sample model with balance heuristic, some pdf | /* this is the veach one-sample model with balance heuristic, some pdf | ||||
| * factors drop out when using balance heuristic weighting */ | * factors drop out when using balance heuristic weighting */ | ||||
| for(int i = 0; i < ccl_fetch(sd, num_closure); i++) { | for(int i = 0; i < ccl_fetch(sd, num_closure); i++) { | ||||
| ▲ Show 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | |||||
| /* Surface Evaluation */ | /* Surface Evaluation */ | ||||
| ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, | ccl_device void shader_eval_surface(KernelGlobals *kg, ShaderData *sd, | ||||
| ccl_addr_space PathState *state, float randb, int path_flag, ShaderContext ctx) | ccl_addr_space PathState *state, float randb, int path_flag, ShaderContext ctx) | ||||
| { | { | ||||
| ccl_fetch(sd, num_closure) = 0; | ccl_fetch(sd, num_closure) = 0; | ||||
| ccl_fetch(sd, randb_closure) = randb; | ccl_fetch(sd, randb_closure) = randb; | ||||
| if(ctx == SHADER_CONTEXT_EMISSION) | |||||
| path_flag |= PATH_RAY_EMISSION; | |||||
| #ifdef __OSL__ | #ifdef __OSL__ | ||||
| if(kg->osl) | if(kg->osl) | ||||
| OSLShader::eval_surface(kg, sd, state, path_flag, ctx); | OSLShader::eval_surface(kg, sd, state, path_flag, ctx); | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| #ifdef __SVM__ | #ifdef __SVM__ | ||||
| svm_eval_nodes(kg, sd, state, SHADER_TYPE_SURFACE, path_flag); | svm_eval_nodes(kg, sd, state, SHADER_TYPE_SURFACE, path_flag); | ||||
| Show All 10 Lines | |||||
| /* Background Evaluation */ | /* Background Evaluation */ | ||||
| ccl_device float3 shader_eval_background(KernelGlobals *kg, ShaderData *sd, | ccl_device float3 shader_eval_background(KernelGlobals *kg, ShaderData *sd, | ||||
| ccl_addr_space PathState *state, int path_flag, ShaderContext ctx) | ccl_addr_space PathState *state, int path_flag, ShaderContext ctx) | ||||
| { | { | ||||
| ccl_fetch(sd, num_closure) = 0; | ccl_fetch(sd, num_closure) = 0; | ||||
| ccl_fetch(sd, randb_closure) = 0.0f; | ccl_fetch(sd, randb_closure) = 0.0f; | ||||
| if(ctx == SHADER_CONTEXT_EMISSION) | |||||
| path_flag |= PATH_RAY_EMISSION; | |||||
| #ifdef __OSL__ | #ifdef __OSL__ | ||||
| if(kg->osl) { | if(kg->osl) { | ||||
| return OSLShader::eval_background(kg, sd, state, path_flag, ctx); | return OSLShader::eval_background(kg, sd, state, path_flag, ctx); | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | if(kg->osl) { | ||||
| OSLShader::eval_volume(kg, sd, state, path_flag, ctx); | OSLShader::eval_volume(kg, sd, state, path_flag, ctx); | ||||
| } | } | ||||
| else | else | ||||
| # endif | # endif | ||||
| { | { | ||||
| svm_eval_nodes(kg, sd, state, SHADER_TYPE_VOLUME, path_flag); | svm_eval_nodes(kg, sd, state, SHADER_TYPE_VOLUME, path_flag); | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* merge closures to avoid exceeding number of closures limit */ | |||||
| if(i > 0) | |||||
| shader_merge_closures(sd); | |||||
| } | } | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* Displacement Evaluation */ | /* Displacement Evaluation */ | ||||
| ccl_device void shader_eval_displacement(KernelGlobals *kg, ShaderData *sd, ccl_addr_space PathState *state, ShaderContext ctx) | ccl_device void shader_eval_displacement(KernelGlobals *kg, ShaderData *sd, ccl_addr_space PathState *state, ShaderContext ctx) | ||||
| ▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines | |||||