forked from bartvdbraak/blender
Fix T73064: Embree does not like Bevel shader
Embree's local intersection routine was not prepared for local intersections without per-object BVH. Now it should be able to handle any kind of local intersection, such as AO, bevel and SSS. Differential Revision: https://developer.blender.org/D6602
This commit is contained in:
parent
b05bca2364
commit
6257cdc376
@ -146,7 +146,21 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CCLIntersectContext::RAY_LOCAL:
|
||||||
case CCLIntersectContext::RAY_SSS: {
|
case CCLIntersectContext::RAY_SSS: {
|
||||||
|
/* Check if it's hitting the correct object. */
|
||||||
|
Intersection current_isect;
|
||||||
|
if (ctx->type == CCLIntersectContext::RAY_SSS) {
|
||||||
|
kernel_embree_convert_sss_hit(kg, ray, hit, ¤t_isect, ctx->local_object_id);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
kernel_embree_convert_hit(kg, ray, hit, ¤t_isect);
|
||||||
|
if (ctx->local_object_id != current_isect.object) {
|
||||||
|
/* This tells Embree to continue tracing. */
|
||||||
|
*args->valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* No intersection information requested, just return a hit. */
|
/* No intersection information requested, just return a hit. */
|
||||||
if (ctx->max_hits == 0) {
|
if (ctx->max_hits == 0) {
|
||||||
break;
|
break;
|
||||||
@ -160,8 +174,8 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See triangle_intersect_subsurface() for the native equivalent. */
|
/* See triangle_intersect_subsurface() for the native equivalent. */
|
||||||
for (int i = min(ctx->max_hits, ctx->ss_isect->num_hits) - 1; i >= 0; --i) {
|
for (int i = min(ctx->max_hits, ctx->local_isect->num_hits) - 1; i >= 0; --i) {
|
||||||
if (ctx->ss_isect->hits[i].t == ray->tfar) {
|
if (ctx->local_isect->hits[i].t == ray->tfar) {
|
||||||
/* This tells Embree to continue tracing. */
|
/* This tells Embree to continue tracing. */
|
||||||
*args->valid = 0;
|
*args->valid = 0;
|
||||||
break;
|
break;
|
||||||
@ -172,14 +186,14 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
|
|||||||
|
|
||||||
if (ctx->lcg_state) {
|
if (ctx->lcg_state) {
|
||||||
|
|
||||||
++ctx->ss_isect->num_hits;
|
++ctx->local_isect->num_hits;
|
||||||
if (ctx->ss_isect->num_hits <= ctx->max_hits) {
|
if (ctx->local_isect->num_hits <= ctx->max_hits) {
|
||||||
hit_idx = ctx->ss_isect->num_hits - 1;
|
hit_idx = ctx->local_isect->num_hits - 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* reservoir sampling: if we are at the maximum number of
|
/* reservoir sampling: if we are at the maximum number of
|
||||||
* hits, randomly replace element or skip it */
|
* hits, randomly replace element or skip it */
|
||||||
hit_idx = lcg_step_uint(ctx->lcg_state) % ctx->ss_isect->num_hits;
|
hit_idx = lcg_step_uint(ctx->lcg_state) % ctx->local_isect->num_hits;
|
||||||
|
|
||||||
if (hit_idx >= ctx->max_hits) {
|
if (hit_idx >= ctx->max_hits) {
|
||||||
/* This tells Embree to continue tracing. */
|
/* This tells Embree to continue tracing. */
|
||||||
@ -189,15 +203,11 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ctx->ss_isect->num_hits = 1;
|
ctx->local_isect->num_hits = 1;
|
||||||
}
|
}
|
||||||
/* record intersection */
|
/* record intersection */
|
||||||
kernel_embree_convert_local_hit(
|
ctx->local_isect->hits[hit_idx] = current_isect;
|
||||||
kg, ray, hit, &ctx->ss_isect->hits[hit_idx], ctx->sss_object_id);
|
ctx->local_isect->Ng[hit_idx] = normalize(make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z));
|
||||||
ctx->ss_isect->Ng[hit_idx].x = hit->Ng_x;
|
|
||||||
ctx->ss_isect->Ng[hit_idx].y = hit->Ng_y;
|
|
||||||
ctx->ss_isect->Ng[hit_idx].z = hit->Ng_z;
|
|
||||||
ctx->ss_isect->Ng[hit_idx] = normalize(ctx->ss_isect->Ng[hit_idx]);
|
|
||||||
/* This tells Embree to continue tracing .*/
|
/* This tells Embree to continue tracing .*/
|
||||||
*args->valid = 0;
|
*args->valid = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -329,24 +329,26 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals *kg,
|
|||||||
|
|
||||||
# ifdef __EMBREE__
|
# ifdef __EMBREE__
|
||||||
if (kernel_data.bvh.scene) {
|
if (kernel_data.bvh.scene) {
|
||||||
CCLIntersectContext ctx(kg, CCLIntersectContext::RAY_SSS);
|
const bool has_bvh = !(kernel_tex_fetch(__object_flag, local_object) &
|
||||||
|
SD_OBJECT_TRANSFORM_APPLIED);
|
||||||
|
CCLIntersectContext ctx(
|
||||||
|
kg, has_bvh ? CCLIntersectContext::RAY_SSS : CCLIntersectContext::RAY_LOCAL);
|
||||||
ctx.lcg_state = lcg_state;
|
ctx.lcg_state = lcg_state;
|
||||||
ctx.max_hits = max_hits;
|
ctx.max_hits = max_hits;
|
||||||
ctx.ss_isect = local_isect;
|
ctx.local_isect = local_isect;
|
||||||
local_isect->num_hits = 0;
|
local_isect->num_hits = 0;
|
||||||
ctx.sss_object_id = local_object;
|
ctx.local_object_id = local_object;
|
||||||
IntersectContext rtc_ctx(&ctx);
|
IntersectContext rtc_ctx(&ctx);
|
||||||
RTCRay rtc_ray;
|
RTCRay rtc_ray;
|
||||||
kernel_embree_setup_ray(*ray, rtc_ray, PATH_RAY_ALL_VISIBILITY);
|
kernel_embree_setup_ray(*ray, rtc_ray, PATH_RAY_ALL_VISIBILITY);
|
||||||
|
|
||||||
/* Get the Embree scene for this intersection. */
|
/* If this object has its own BVH, use it. */
|
||||||
RTCGeometry geom = rtcGetGeometry(kernel_data.bvh.scene, local_object * 2);
|
if (has_bvh) {
|
||||||
if (geom) {
|
RTCGeometry geom = rtcGetGeometry(kernel_data.bvh.scene, local_object * 2);
|
||||||
float3 P = ray->P;
|
if (geom) {
|
||||||
float3 dir = ray->D;
|
float3 P = ray->P;
|
||||||
float3 idir = ray->D;
|
float3 dir = ray->D;
|
||||||
const int object_flag = kernel_tex_fetch(__object_flag, local_object);
|
float3 idir = ray->D;
|
||||||
if (!(object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
|
||||||
Transform ob_itfm;
|
Transform ob_itfm;
|
||||||
rtc_ray.tfar = bvh_instance_motion_push(
|
rtc_ray.tfar = bvh_instance_motion_push(
|
||||||
kg, local_object, ray, &P, &dir, &idir, ray->t, &ob_itfm);
|
kg, local_object, ray, &P, &dir, &idir, ray->t, &ob_itfm);
|
||||||
@ -360,11 +362,15 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals *kg,
|
|||||||
rtc_ray.dir_x = dir.x;
|
rtc_ray.dir_x = dir.x;
|
||||||
rtc_ray.dir_y = dir.y;
|
rtc_ray.dir_y = dir.y;
|
||||||
rtc_ray.dir_z = dir.z;
|
rtc_ray.dir_z = dir.z;
|
||||||
|
RTCScene scene = (RTCScene)rtcGetGeometryUserData(geom);
|
||||||
|
kernel_assert(scene);
|
||||||
|
if (scene) {
|
||||||
|
rtcOccluded1(scene, &rtc_ctx.context, &rtc_ray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RTCScene scene = (RTCScene)rtcGetGeometryUserData(geom);
|
}
|
||||||
if (scene) {
|
else {
|
||||||
rtcOccluded1(scene, &rtc_ctx.context, &rtc_ray);
|
rtcOccluded1(kernel_data.bvh.scene, &rtc_ctx.context, &rtc_ray);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return local_isect->num_hits > 0;
|
return local_isect->num_hits > 0;
|
||||||
|
@ -28,9 +28,9 @@ struct CCLIntersectContext {
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
RAY_REGULAR = 0,
|
RAY_REGULAR = 0,
|
||||||
RAY_SHADOW_ALL = 1,
|
RAY_SHADOW_ALL = 1,
|
||||||
RAY_SSS = 2,
|
RAY_LOCAL = 2,
|
||||||
RAY_VOLUME_ALL = 3,
|
RAY_SSS = 3,
|
||||||
|
RAY_VOLUME_ALL = 4,
|
||||||
} RayType;
|
} RayType;
|
||||||
|
|
||||||
KernelGlobals *kg;
|
KernelGlobals *kg;
|
||||||
@ -42,8 +42,8 @@ struct CCLIntersectContext {
|
|||||||
int num_hits;
|
int num_hits;
|
||||||
|
|
||||||
/* for SSS Rays: */
|
/* for SSS Rays: */
|
||||||
LocalIntersection *ss_isect;
|
LocalIntersection *local_isect;
|
||||||
int sss_object_id;
|
int local_object_id;
|
||||||
uint *lcg_state;
|
uint *lcg_state;
|
||||||
|
|
||||||
CCLIntersectContext(KernelGlobals *kg_, RayType type_)
|
CCLIntersectContext(KernelGlobals *kg_, RayType type_)
|
||||||
@ -53,8 +53,8 @@ struct CCLIntersectContext {
|
|||||||
max_hits = 1;
|
max_hits = 1;
|
||||||
num_hits = 0;
|
num_hits = 0;
|
||||||
isect_s = NULL;
|
isect_s = NULL;
|
||||||
ss_isect = NULL;
|
local_isect = NULL;
|
||||||
sss_object_id = -1;
|
local_object_id = -1;
|
||||||
lcg_state = NULL;
|
lcg_state = NULL;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -121,11 +121,11 @@ ccl_device_inline void kernel_embree_convert_hit(KernelGlobals *kg,
|
|||||||
isect->type = kernel_tex_fetch(__prim_type, isect->prim);
|
isect->type = kernel_tex_fetch(__prim_type, isect->prim);
|
||||||
}
|
}
|
||||||
|
|
||||||
ccl_device_inline void kernel_embree_convert_local_hit(KernelGlobals *kg,
|
ccl_device_inline void kernel_embree_convert_sss_hit(KernelGlobals *kg,
|
||||||
const RTCRay *ray,
|
const RTCRay *ray,
|
||||||
const RTCHit *hit,
|
const RTCHit *hit,
|
||||||
Intersection *isect,
|
Intersection *isect,
|
||||||
int local_object_id)
|
int local_object_id)
|
||||||
{
|
{
|
||||||
isect->u = 1.0f - hit->v - hit->u;
|
isect->u = 1.0f - hit->v - hit->u;
|
||||||
isect->v = hit->u;
|
isect->v = hit->u;
|
||||||
|
Loading…
Reference in New Issue
Block a user