[Bf-blender-cvs] [c3cc89ebaa9] cycles_texture_cache: Merge branch 'master' into cycles_texture_cache
Stefan Werner
noreply at git.blender.org
Wed Apr 21 09:41:12 CEST 2021
Commit: c3cc89ebaa9b77d47165dae6be0f0eeeef50db32
Author: Stefan Werner
Date: Wed Mar 10 13:34:26 2021 +0100
Branches: cycles_texture_cache
https://developer.blender.org/rBc3cc89ebaa9b77d47165dae6be0f0eeeef50db32
Merge branch 'master' into cycles_texture_cache
===================================================================
===================================================================
diff --cc intern/cycles/kernel/kernel_shader.h
index f6d39546a45,e6bd99414cc..70be5cef09e
--- a/intern/cycles/kernel/kernel_shader.h
+++ b/intern/cycles/kernel/kernel_shader.h
@@@ -404,12 -330,8 +404,12 @@@ ccl_device_inline void shader_setup_fro
}
else {
#ifdef __DPDU__
- sd->dPdu = make_float3(0.0f, 0.0f, 0.0f);
- sd->dPdv = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dPdu = zero_float3();
+ sd->dPdv = zero_float3();
+#endif
+#ifdef __DNDU__
+ sd->dNdx = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dNdy = make_float3(0.0f, 0.0f, 0.0f);
#endif
}
@@@ -515,13 -419,9 +515,13 @@@ ccl_device_inline void shader_setup_fro
#ifdef __DPDU__
/* dPdu/dPdv */
- sd->dPdu = make_float3(0.0f, 0.0f, 0.0f);
- sd->dPdv = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dPdu = zero_float3();
+ sd->dPdv = zero_float3();
#endif
+#ifdef __DNDU__
+ sd->dNdx = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dNdy = make_float3(0.0f, 0.0f, 0.0f);
+#endif
#ifdef __RAY_DIFFERENTIALS__
/* differentials */
@@@ -566,14 -466,9 +566,14 @@@ ccl_device_inline void shader_setup_fro
# ifdef __DPDU__
/* dPdu/dPdv */
- sd->dPdu = make_float3(0.0f, 0.0f, 0.0f);
- sd->dPdv = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dPdu = zero_float3();
+ sd->dPdv = zero_float3();
# endif
+# ifdef __DNDU__
+ /* dNdu/dNdv */
+ sd->dNdx = make_float3(0.0f, 0.0f, 0.0f);
+ sd->dNdy = make_float3(0.0f, 0.0f, 0.0f);
+# endif
# ifdef __RAY_DIFFERENTIALS__
/* differentials */
diff --cc intern/cycles/kernel/kernel_subsurface.h
index 1d019125d19,55bbe7f95db..c26a88b92a3
--- a/intern/cycles/kernel/kernel_subsurface.h
+++ b/intern/cycles/kernel/kernel_subsurface.h
@@@ -419,34 -495,84 +495,85 @@@ ccl_device_noinlin
/* Advance random number offset. */
state->rng_offset += PRNG_BOUNCE_NUM;
+ /* Sample color channel, use MIS with balance heuristic. */
+ float rphase = path_state_rng_1D(kg, state, PRNG_PHASE_CHANNEL);
+ float3 channel_pdf;
+ int channel = kernel_volume_sample_channel(alpha, throughput, rphase, &channel_pdf);
+ float sample_sigma_t = kernel_volume_channel_get(sigma_t, channel);
+ float randt = path_state_rng_1D(kg, state, PRNG_SCATTER_DISTANCE);
+
+ /* We need the result of the raycast to compute the full guided PDF, so just remember the
+ * relevant terms to avoid recomputing them later. */
+ float backward_fraction = 0.0f;
+ float forward_pdf_factor = 0.0f;
+ float forward_stretching = 1.0f;
+ float backward_pdf_factor = 0.0f;
+ float backward_stretching = 1.0f;
+
+ /* For the initial ray, we already know the direction, so just do classic distance sampling. */
if (bounce > 0) {
+ /* Decide whether we should use guided or classic sampling. */
+ bool guided = (path_state_rng_1D(kg, state, PRNG_LIGHT_TERMINATE) < guided_fraction);
+
+ /* Determine if we want to sample away from the incoming interface.
+ * This only happens if we found a nearby opposite interface, and the probability for it
+ * depends on how close we are to it already.
+ * This probability term comes from the recorded presentation of [3]. */
+ bool guide_backward = false;
+ if (have_opposite_interface) {
+ /* Compute distance of the random walk between the tangent plane at the starting point
+ * and the assumed opposite interface (the parallel plane that contains the point we
+ * found in our ray query for the opposite side). */
+ float x = clamp(dot(ray->P - sd->P, -sd->N), 0.0f, opposite_distance);
+ backward_fraction = 1.0f / (1.0f + expf((opposite_distance - 2 * x) / diffusion_length));
+ guide_backward = path_state_rng_1D(kg, state, PRNG_TERMINATE) < backward_fraction;
+ }
+
/* Sample scattering direction. */
- const float anisotropy = 0.0f;
float scatter_u, scatter_v;
path_state_rng_2D(kg, state, PRNG_BSDF_U, &scatter_u, &scatter_v);
- ray->D = henyey_greenstrein_sample(ray->D,
- anisotropy,
- scatter_u,
- scatter_v,
- NULL,
- make_float3(0.0f, 0.0f, 0.0f),
- make_float3(0.0f, 0.0f, 0.0f),
- NULL,
- NULL);
- }
+
- /* Sample color channel, use MIS with balance heuristic. */
- float rphase = path_state_rng_1D(kg, state, PRNG_PHASE_CHANNEL);
- float3 albedo = safe_divide_color(sigma_s, sigma_t);
- float3 channel_pdf;
- int channel = kernel_volume_sample_channel(albedo, throughput, rphase, &channel_pdf);
+ float cos_theta;
+ if (guided) {
+ cos_theta = sample_phase_dwivedi(diffusion_length, phase_log, scatter_u);
+ /* The backwards guiding distribution is just mirrored along sd->N, so swapping the
+ * sign here is enough to sample from that instead. */
+ if (guide_backward) {
+ cos_theta = -cos_theta;
+ }
+ }
+ else {
+ cos_theta = 2.0f * scatter_u - 1.0f;
+ }
+ ray->D = direction_from_cosine(sd->N, cos_theta, scatter_v);
+
+ /* Compute PDF factor caused by phase sampling (as the ratio of guided / classic).
+ * Since phase sampling is channel-independent, we can get away with applying a factor
+ * to the guided PDF, which implicitly means pulling out the classic PDF term and letting
+ * it cancel with an equivalent term in the numerator of the full estimator.
+ * For the backward PDF, we again reuse the same probability distribution with a sign swap.
+ */
+ forward_pdf_factor = 2.0f * eval_phase_dwivedi(diffusion_length, phase_log, cos_theta);
+ backward_pdf_factor = 2.0f * eval_phase_dwivedi(diffusion_length, phase_log, -cos_theta);
+
+ /* Prepare distance sampling.
+ * For the backwards case, this also needs the sign swapped since now directions against
+ * sd->N (and therefore with negative cos_theta) are preferred. */
+ forward_stretching = (1.0f - cos_theta / diffusion_length);
+ backward_stretching = (1.0f + cos_theta / diffusion_length);
+ if (guided) {
+ sample_sigma_t *= guide_backward ? backward_stretching : forward_stretching;
+ }
+ }
- /* Distance sampling. */
- float rdist = path_state_rng_1D(kg, state, PRNG_SCATTER_DISTANCE);
- float sample_sigma_t = kernel_volume_channel_get(sigma_t, channel);
- float t = -logf(1.0f - rdist) / sample_sigma_t;
+ /* Sample direction along ray. */
+ float t = -logf(1.0f - randt) / sample_sigma_t;
- ray->t = t;
+ /* On the first bounce, we use the raycast to check if the opposite side is nearby.
+ * If yes, we will later use backwards guided sampling in order to have a decent
+ * chance of connecting to it.
+ * Todo: Maybe use less than 10 times the mean free path? */
+ ray->t = (bounce == 0) ? max(t, 10.0f / (min3(sigma_t))) : t;
scene_intersect_local(kg, ray, ss_isect, sd->object, NULL, 1);
hit = (ss_isect->num_hits > 0);
diff --cc intern/cycles/render/image.cpp
index d83437c0625,29a95beaf7e..c419ed9b159
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@@ -300,8 -298,8 +300,8 @@@ bool ImageLoader::is_vdb_loader() cons
ImageManager::ImageManager(const DeviceInfo &info)
{
- need_update = true;
+ need_update_ = true;
- osl_texture_system = NULL;
+ oiio_texture_system = NULL;
animation_frame = 0;
/* Set image limits */
diff --cc intern/cycles/render/nodes.cpp
index 06288eee97b,b17f1ec0b2f..21ca05c89ae
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@@ -250,9 -250,7 +250,10 @@@ NODE_DEFINE(ImageTextureNode
SOCKET_INT_ARRAY(tiles, "Tiles", array<int>());
SOCKET_BOOLEAN(animated, "Animated", false);
- SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_UV);
- SOCKET_IN_POINT(vector_dx, "Vector_dx", make_float3(0.0f, 0.0f, 0.0f));
- SOCKET_IN_POINT(vector_dy, "Vector_dy", make_float3(0.0f, 0.0f, 0.0f));
++
+ SOCKET_IN_POINT(vector, "Vector", zero_float3(), SocketType::LINK_TEXTURE_UV);
++ SOCKET_IN_POINT(vector_dx, "Vector_dx", zero_float3());
++ SOCKET_IN_POINT(vector_dy, "Vector_dy", zero_float3());
SOCKET_OUT_COLOR(color, "Color");
SOCKET_OUT_FLOAT(alpha, "Alpha");
@@@ -530,9 -517,7 +531,9 @@@ NODE_DEFINE(EnvironmentTextureNode
SOCKET_BOOLEAN(animated, "Animated", false);
- SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_POSITION);
- SOCKET_IN_POINT(vector_dx, "Vector_dx", make_float3(0.0f, 0.0f, 0.0f));
- SOCKET_IN_POINT(vector_dy, "Vector_dy", make_float3(0.0f, 0.0f, 0.0f));
+ SOCKET_IN_POINT(vector, "Vector", zero_float3(), SocketType::LINK_POSITION);
++ SOCKET_IN_POINT(vector_dx, "Vector_dx", zero_float3());
++ SOCKET_IN_POINT(vector_dy, "Vector_dy", zero_float3());
SOCKET_OUT_COLOR(color, "Color");
SOCKET_OUT_FLOAT(alpha, "Alpha");
diff --cc intern/cycles/render/shader.cpp
index 64f2ad3f2fa,ea83073d5ce..e85fb0a540e
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@@ -34,9 -35,8 +35,10 @@@
#include "util/util_foreach.h"
#include "util/util_murmurhash.h"
#include "util/util_task.h"
+ #include "util/util_transform.h"
+#include "kernel/kernel_oiio_globals.h"
+#include <OpenImageIO/texture.h>
#ifdef WITH_OCIO
# include <OpenColorIO/OpenColorIO.h>
namespace OCIO = OCIO_NAMESPACE;
More information about the Bf-blender-cvs
mailing list