Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/blender_util.h11
-rw-r--r--intern/cycles/bvh/bvh_optix.cpp2
-rw-r--r--intern/cycles/device/device.h2
-rw-r--r--intern/cycles/device/device_multi.cpp12
-rw-r--r--intern/cycles/device/device_optix.cpp36
-rw-r--r--intern/cycles/kernel/closure/bsdf_microfacet.h35
-rw-r--r--intern/cycles/kernel/closure/bsdf_microfacet_multi.h12
-rw-r--r--intern/cycles/kernel/kernel_passes.h12
-rw-r--r--intern/cycles/kernel/svm/svm_types.h6
-rw-r--r--intern/opencolorio/gpu_shader_display_transform.glsl10
-rw-r--r--intern/opencolorio/ocio_capi.h6
-rw-r--r--intern/opencolorio/ocio_impl_glsl.cc4
12 files changed, 83 insertions, 65 deletions
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 3625dd45ae2..cbe61e367fa 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -159,7 +159,7 @@ static inline void curvemapping_to_array(BL::CurveMapping &cumap, array<float> &
data.resize(size);
for (int i = 0; i < size; i++) {
float t = (float)i / (float)(size - 1);
- data[i] = curve.evaluate(t);
+ data[i] = cumap.evaluate(curve, t);
}
}
@@ -197,15 +197,16 @@ static inline void curvemapping_color_to_array(BL::CurveMapping &cumap,
BL::CurveMap mapI = cumap.curves[3];
for (int i = 0; i < size; i++) {
const float t = min_x + (float)i / (float)(size - 1) * range_x;
- data[i] = make_float3(mapR.evaluate(mapI.evaluate(t)),
- mapG.evaluate(mapI.evaluate(t)),
- mapB.evaluate(mapI.evaluate(t)));
+ data[i] = make_float3(cumap.evaluate(mapR, cumap.evaluate(mapI, t)),
+ cumap.evaluate(mapG, cumap.evaluate(mapI, t)),
+ cumap.evaluate(mapB, cumap.evaluate(mapI, t)));
}
}
else {
for (int i = 0; i < size; i++) {
float t = min_x + (float)i / (float)(size - 1) * range_x;
- data[i] = make_float3(mapR.evaluate(t), mapG.evaluate(t), mapB.evaluate(t));
+ data[i] = make_float3(
+ cumap.evaluate(mapR, t), cumap.evaluate(mapG, t), cumap.evaluate(mapB, t));
}
}
}
diff --git a/intern/cycles/bvh/bvh_optix.cpp b/intern/cycles/bvh/bvh_optix.cpp
index b3a9aab3266..86d755ab06a 100644
--- a/intern/cycles/bvh/bvh_optix.cpp
+++ b/intern/cycles/bvh/bvh_optix.cpp
@@ -49,7 +49,7 @@ void BVHOptiX::copy_to_device(Progress &progress, DeviceScene *dscene)
progress.set_status("Updating Scene BVH", "Building OptiX acceleration structure");
Device *const device = dscene->bvh_nodes.device;
- if (!device->build_optix_bvh(this, dscene->bvh_nodes))
+ if (!device->build_optix_bvh(this))
progress.set_error("Failed to build OptiX acceleration structure");
}
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 672d93c2581..66fcac921d3 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -407,7 +407,7 @@ class Device {
const DeviceDrawParams &draw_params);
/* acceleration structure building */
- virtual bool build_optix_bvh(BVH *, device_memory &)
+ virtual bool build_optix_bvh(BVH *)
{
return false;
}
diff --git a/intern/cycles/device/device_multi.cpp b/intern/cycles/device/device_multi.cpp
index ac71be9dbea..b8587eb0a62 100644
--- a/intern/cycles/device/device_multi.cpp
+++ b/intern/cycles/device/device_multi.cpp
@@ -153,21 +153,13 @@ class MultiDevice : public Device {
return result;
}
- bool build_optix_bvh(BVH *bvh, device_memory &mem)
+ bool build_optix_bvh(BVH *bvh)
{
- device_ptr key = unique_key++;
-
// Broadcast acceleration structure build to all devices
foreach (SubDevice &sub, devices) {
- mem.device = sub.device;
- if (!sub.device->build_optix_bvh(bvh, mem))
+ if (!sub.device->build_optix_bvh(bvh))
return false;
- sub.ptr_map[key] = mem.device_pointer;
}
-
- mem.device = this;
- mem.device_pointer = key;
- stats.mem_alloc(mem.device_size);
return true;
}
diff --git a/intern/cycles/device/device_optix.cpp b/intern/cycles/device/device_optix.cpp
index e10bab5a0d8..ae3ab7e1fc2 100644
--- a/intern/cycles/device/device_optix.cpp
+++ b/intern/cycles/device/device_optix.cpp
@@ -174,7 +174,7 @@ class OptiXDevice : public Device {
device_vector<SbtRecord> sbt_data;
device_vector<TextureInfo> texture_info;
device_only_memory<KernelParams> launch_params;
- vector<device_only_memory<uint8_t>> blas;
+ vector<device_only_memory<uint8_t>> as_mem;
OptixTraversableHandle tlas_handle = 0;
// TODO(pmours): This is copied from device_cuda.cpp, so move to common code eventually
@@ -268,8 +268,8 @@ class OptiXDevice : public Device {
// Stop processing any more tasks
task_pool.stop();
- // Clean up all memory before destroying context
- blas.clear();
+ // Free all acceleration structures
+ as_mem.clear();
sbt_data.free();
texture_info.free();
@@ -290,8 +290,8 @@ class OptiXDevice : public Device {
optixPipelineDestroy(pipelines[i]);
// Destroy launch streams
- for (int i = 0; i < info.cpu_threads; ++i)
- cuStreamDestroy(cuda_stream[i]);
+ for (CUstream stream : cuda_stream)
+ cuStreamDestroy(stream);
// Destroy OptiX and CUDA context
optixDeviceContextDestroy(context);
@@ -881,15 +881,16 @@ class OptiXDevice : public Device {
return true;
}
- bool build_optix_bvh(BVH *bvh, device_memory &out_data) override
+ bool build_optix_bvh(BVH *bvh) override
{
assert(bvh->params.top_level);
unsigned int num_instances = 0;
unordered_map<Mesh *, vector<OptixTraversableHandle>> meshes;
+ meshes.reserve(bvh->meshes.size());
- // Clear all previous AS
- blas.clear();
+ // Free all previous acceleration structure
+ as_mem.clear();
// Build bottom level acceleration structures (BLAS)
// Note: Always keep this logic in sync with bvh_optix.cpp!
@@ -900,6 +901,7 @@ class OptiXDevice : public Device {
Mesh *const mesh = ob->mesh;
vector<OptixTraversableHandle> handles;
+ handles.reserve(2);
// Build BLAS for curve primitives
if (bvh->params.primitive_mask & PRIMITIVE_ALL_CURVE && mesh->num_curves() > 0) {
@@ -966,9 +968,9 @@ class OptiXDevice : public Device {
build_input.aabbArray.primitiveIndexOffset = mesh->prim_offset;
// Allocate memory for new BLAS and build it
- blas.emplace_back(this, "blas");
+ as_mem.emplace_back(this, "blas");
handles.emplace_back();
- if (!build_optix_bvh(build_input, num_motion_steps, blas.back(), handles.back()))
+ if (!build_optix_bvh(build_input, num_motion_steps, as_mem.back(), handles.back()))
return false;
}
@@ -1032,9 +1034,9 @@ class OptiXDevice : public Device {
build_input.triangleArray.primitiveIndexOffset = mesh->prim_offset + mesh->num_segments();
// Allocate memory for new BLAS and build it
- blas.emplace_back(this, "blas");
+ as_mem.emplace_back(this, "blas");
handles.emplace_back();
- if (!build_optix_bvh(build_input, num_motion_steps, blas.back(), handles.back()))
+ if (!build_optix_bvh(build_input, num_motion_steps, as_mem.back(), handles.back()))
return false;
}
@@ -1051,6 +1053,7 @@ class OptiXDevice : public Device {
// Skip non-traceable objects
if (!ob->is_traceable())
continue;
+
// Create separate instance for triangle/curve meshes of an object
for (OptixTraversableHandle handle : meshes[ob->mesh]) {
OptixAabb &aabb = aabbs[num_instances];
@@ -1078,8 +1081,8 @@ class OptiXDevice : public Device {
// Insert motion traversable if object has motion
if (motion_blur && ob->use_motion()) {
- blas.emplace_back(this, "motion_transform");
- device_only_memory<uint8_t> &motion_transform_gpu = blas.back();
+ as_mem.emplace_back(this, "motion_transform");
+ device_only_memory<uint8_t> &motion_transform_gpu = as_mem.back();
motion_transform_gpu.alloc_to_device(sizeof(OptixSRTMotionTransform) +
(max(ob->motion.size(), 2) - 2) *
sizeof(OptixSRTData));
@@ -1157,7 +1160,7 @@ class OptiXDevice : public Device {
instances.resize(num_instances);
instances.copy_to_device();
- // Build top-level acceleration structure
+ // Build top-level acceleration structure (TLAS)
OptixBuildInput build_input = {};
build_input.type = OPTIX_BUILD_INPUT_TYPE_INSTANCES;
build_input.instanceArray.instances = instances.device_pointer;
@@ -1165,7 +1168,8 @@ class OptiXDevice : public Device {
build_input.instanceArray.aabbs = aabbs.device_pointer;
build_input.instanceArray.numAabbs = num_instances;
- return build_optix_bvh(build_input, 0 /* TLAS has no motion itself */, out_data, tlas_handle);
+ as_mem.emplace_back(this, "tlas");
+ return build_optix_bvh(build_input, 0, as_mem.back(), tlas_handle);
}
void update_texture_info()
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h
index 2f73434706c..2884ea62a18 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet.h
@@ -37,6 +37,7 @@ CCL_NAMESPACE_BEGIN
typedef ccl_addr_space struct MicrofacetExtra {
float3 color, cspec0;
+ float3 fresnel_color;
float clearcoat;
} MicrofacetExtra;
@@ -276,6 +277,22 @@ ccl_device_forceinline float D_GTR1(float NdotH, float alpha)
return (alpha2 - 1.0f) / (M_PI_F * logf(alpha2) * t);
}
+ccl_device_forceinline void bsdf_microfacet_fresnel_color(const ShaderData *sd,
+ MicrofacetBsdf *bsdf)
+{
+ kernel_assert(CLOSURE_IS_BSDF_MICROFACET_FRESNEL(bsdf->type));
+
+ float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
+ bsdf->extra->fresnel_color = interpolate_fresnel_color(
+ sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0);
+
+ if (bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID) {
+ bsdf->extra->fresnel_color *= 0.25f * bsdf->extra->clearcoat;
+ }
+
+ bsdf->sample_weight *= average(bsdf->extra->fresnel_color);
+}
+
/* GGX microfacet with Smith shadow-masking from:
*
* Microfacet Models for Refraction through Rough Surfaces
@@ -305,15 +322,13 @@ ccl_device int bsdf_microfacet_ggx_fresnel_setup(MicrofacetBsdf *bsdf, const Sha
{
bsdf->extra->cspec0 = saturate3(bsdf->extra->cspec0);
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= F;
-
bsdf->alpha_x = saturate(bsdf->alpha_x);
bsdf->alpha_y = bsdf->alpha_x;
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
+
return SD_BSDF | SD_BSDF_HAS_EVAL;
}
@@ -321,15 +336,13 @@ ccl_device int bsdf_microfacet_ggx_clearcoat_setup(MicrofacetBsdf *bsdf, const S
{
bsdf->extra->cspec0 = saturate3(bsdf->extra->cspec0);
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= 0.25f * bsdf->extra->clearcoat * F;
-
bsdf->alpha_x = saturate(bsdf->alpha_x);
bsdf->alpha_y = bsdf->alpha_x;
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
+
return SD_BSDF | SD_BSDF_HAS_EVAL;
}
@@ -364,15 +377,13 @@ ccl_device int bsdf_microfacet_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsdf, con
{
bsdf->extra->cspec0 = saturate3(bsdf->extra->cspec0);
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= F;
-
bsdf->alpha_x = saturate(bsdf->alpha_x);
bsdf->alpha_y = saturate(bsdf->alpha_y);
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
+
return SD_BSDF | SD_BSDF_HAS_EVAL;
}
diff --git a/intern/cycles/kernel/closure/bsdf_microfacet_multi.h b/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
index 9780dd87415..a5fe989bcd1 100644
--- a/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
+++ b/intern/cycles/kernel/closure/bsdf_microfacet_multi.h
@@ -402,9 +402,7 @@ ccl_device int bsdf_microfacet_multi_ggx_aniso_fresnel_setup(MicrofacetBsdf *bsd
bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID;
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= F;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
return bsdf_microfacet_multi_ggx_common_setup(bsdf);
}
@@ -424,9 +422,7 @@ ccl_device int bsdf_microfacet_multi_ggx_fresnel_setup(MicrofacetBsdf *bsdf, con
bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID;
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= F;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
return bsdf_microfacet_multi_ggx_common_setup(bsdf);
}
@@ -582,9 +578,7 @@ ccl_device int bsdf_microfacet_multi_ggx_glass_fresnel_setup(MicrofacetBsdf *bsd
bsdf->type = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID;
- float F0 = fresnel_dielectric_cos(1.0f, bsdf->ior);
- float F = average(interpolate_fresnel_color(sd->I, bsdf->N, bsdf->ior, F0, bsdf->extra->cspec0));
- bsdf->sample_weight *= F;
+ bsdf_microfacet_fresnel_color(sd, bsdf);
return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_NEEDS_LCG;
}
diff --git a/intern/cycles/kernel/kernel_passes.h b/intern/cycles/kernel/kernel_passes.h
index c1d74dddc2a..3e423e42573 100644
--- a/intern/cycles/kernel/kernel_passes.h
+++ b/intern/cycles/kernel/kernel_passes.h
@@ -145,7 +145,17 @@ ccl_device_inline void kernel_update_denoising_features(KernelGlobals *kg,
normal += sc->N * sc->sample_weight;
sum_weight += sc->sample_weight;
if (bsdf_get_specular_roughness_squared(sc) > sqr(0.075f)) {
- albedo += sc->weight;
+ float3 closure_albedo = sc->weight;
+ /* Closures that include a Fresnel term typically have weights close to 1 even though their
+ * actual contribution is significantly lower.
+ * To account for this, we scale their weight by the average fresnel factor (the same is also
+ * done for the sample weight in the BSDF setup, so we don't need to scale that here). */
+ if (CLOSURE_IS_BSDF_MICROFACET_FRESNEL(sc->type)) {
+ MicrofacetBsdf *bsdf = (MicrofacetBsdf *)sc;
+ closure_albedo *= bsdf->extra->fresnel_color;
+ }
+
+ albedo += closure_albedo;
sum_nonspecular_weight += sc->sample_weight;
}
}
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 01710f713ac..aa4dfdca2d1 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -552,6 +552,12 @@ typedef enum ClosureType {
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && \
type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) || \
(type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID))
+#define CLOSURE_IS_BSDF_MICROFACET_FRESNEL(type) \
+ (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID || \
+ type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID || \
+ type == CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID || \
+ type == CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID || \
+ type == CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID)
#define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID)
#define CLOSURE_IS_BSSRDF(type) \
(type >= CLOSURE_BSSRDF_CUBIC_ID && type <= CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID)
diff --git a/intern/opencolorio/gpu_shader_display_transform.glsl b/intern/opencolorio/gpu_shader_display_transform.glsl
index 04e96e8ed3c..9787398e2ae 100644
--- a/intern/opencolorio/gpu_shader_display_transform.glsl
+++ b/intern/opencolorio/gpu_shader_display_transform.glsl
@@ -16,7 +16,7 @@ out vec4 fragColor;
*/
uniform sampler1D curve_mapping_texture;
uniform int curve_mapping_lut_size;
-uniform ivec4 use_curve_mapping_extend_extrapolate;
+uniform int use_curve_mapping_extend_extrapolate;
uniform vec4 curve_mapping_mintable;
uniform vec4 curve_mapping_range;
uniform vec4 curve_mapping_ext_in_x;
@@ -42,8 +42,8 @@ float read_curve_mapping(int table, int index)
float curvemap_calc_extend(int table, float x, vec2 first, vec2 last)
{
if (x <= first[0]) {
- if (use_curve_mapping_extend_extrapolate[table] == 0) {
- /* no extrapolate */
+ if (use_curve_mapping_extend_extrapolate == 0) {
+ /* horizontal extrapolation */
return first[1];
}
else {
@@ -55,8 +55,8 @@ float curvemap_calc_extend(int table, float x, vec2 first, vec2 last)
}
}
else if (x >= last[0]) {
- if (use_curve_mapping_extend_extrapolate[table] == 0) {
- /* no extrapolate */
+ if (use_curve_mapping_extend_extrapolate == 0) {
+ /* horizontal extrapolation */
return last[1];
}
else {
diff --git a/intern/opencolorio/ocio_capi.h b/intern/opencolorio/ocio_capi.h
index 9ba2d8fb8f9..5670b37f892 100644
--- a/intern/opencolorio/ocio_capi.h
+++ b/intern/opencolorio/ocio_capi.h
@@ -73,10 +73,10 @@ typedef struct OCIO_CurveMappingSettings {
int lut_size;
/* Extend extrapolation flags for all the tables.
- * if use_extend_extrapolate[T] != 0 means extrapolation for
- * table T is needed.
+ * if use_extend_extrapolate != 0 means extrapolation for
+ * curve.
*/
- int use_extend_extrapolate[4];
+ int use_extend_extrapolate;
/* Minimal X value of the curve mapping tables. */
float mintable[4];
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc
index 99d59c8d989..a80e29a2dec 100644
--- a/intern/opencolorio/ocio_impl_glsl.cc
+++ b/intern/opencolorio/ocio_impl_glsl.cc
@@ -499,8 +499,8 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r,
if (use_curve_mapping) {
immUniform1i("curve_mapping_texture", 2);
immUniform1i("curve_mapping_lut_size", curve_mapping_settings->lut_size);
- immUniform4iv("use_curve_mapping_extend_extrapolate",
- curve_mapping_settings->use_extend_extrapolate);
+ immUniform1i("use_curve_mapping_extend_extrapolate",
+ curve_mapping_settings->use_extend_extrapolate);
immUniform4fv("curve_mapping_mintable", curve_mapping_settings->mintable);
immUniform4fv("curve_mapping_range", curve_mapping_settings->range);
immUniform4fv("curve_mapping_ext_in_x", curve_mapping_settings->ext_in_x);