Merge branch 'master' into blender2.8
This commit is contained in:
commit
b8ab2a84d3
|
@ -184,6 +184,35 @@ ccl_device float2 regular_polygon_sample(float corners, float rotation, float u,
|
|||
return make_float2(cr*p.x - sr*p.y, sr*p.x + cr*p.y);
|
||||
}
|
||||
|
||||
ccl_device float3 ensure_valid_reflection(float3 Ng, float3 I, float3 N)
|
||||
{
|
||||
float3 R = 2*dot(N, I)*N - I;
|
||||
if(dot(Ng, R) >= 0.05f) {
|
||||
return N;
|
||||
}
|
||||
|
||||
/* Form coordinate system with Ng as the Z axis and N inside the X-Z-plane.
|
||||
* The X axis is found by normalizing the component of N that's orthogonal to Ng.
|
||||
* The Y axis isn't actually needed.
|
||||
*/
|
||||
float3 X = normalize(N - dot(N, Ng)*Ng);
|
||||
|
||||
/* Calculate N.z and N.x in the local coordinate system. */
|
||||
float Iz = dot(I, Ng);
|
||||
float Ix2 = sqr(dot(I, X)), Iz2 = sqr(Iz);
|
||||
float Ix2Iz2 = Ix2 + Iz2;
|
||||
|
||||
float a = sqrtf(Ix2*(Ix2Iz2 - sqr(0.05f)));
|
||||
float b = Iz*0.05f + Ix2Iz2;
|
||||
float c = (a + b > 0.0f)? (a + b) : (-a + b);
|
||||
|
||||
float Nz = sqrtf(0.5f * c * (1.0f / Ix2Iz2));
|
||||
float Nx = sqrtf(1.0f - sqr(Nz));
|
||||
|
||||
/* Transform back into global coordinates. */
|
||||
return Nx*X + Nz*Ng;
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
#endif /* __KERNEL_MONTECARLO_CL__ */
|
||||
|
|
|
@ -64,5 +64,7 @@ surface node_bump(
|
|||
if (use_object_space) {
|
||||
NormalOut = normalize(transform("object", "world", NormalOut));
|
||||
}
|
||||
|
||||
NormalOut = ensure_valid_reflection(Ng, I, NormalOut);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,5 +88,7 @@ shader node_normal_map(
|
|||
|
||||
if (Strength != 1.0)
|
||||
Normal = normalize(NormalIn + (Normal - NormalIn) * max(Strength, 0.0));
|
||||
|
||||
Normal = ensure_valid_reflection(Ng, I, Normal);
|
||||
}
|
||||
|
||||
|
|
|
@ -282,6 +282,36 @@ point rotate (point p, float angle, point a, point b)
|
|||
return transform (M, p-a) + a;
|
||||
}
|
||||
|
||||
normal ensure_valid_reflection(normal Ng, vector I, normal N)
|
||||
{
|
||||
float sqr(float x) { return x*x; }
|
||||
|
||||
vector R = 2*dot(N, I)*N - I;
|
||||
if (dot(Ng, R) >= 0.05) {
|
||||
return N;
|
||||
}
|
||||
|
||||
/* Form coordinate system with Ng as the Z axis and N inside the X-Z-plane.
|
||||
* The X axis is found by normalizing the component of N that's orthogonal to Ng.
|
||||
* The Y axis isn't actually needed.
|
||||
*/
|
||||
vector X = normalize(N - dot(N, Ng)*Ng);
|
||||
|
||||
/* Calculate N.z and N.x in the local coordinate system. */
|
||||
float Ix = dot(I, X), Iz = dot(I, Ng);
|
||||
float Ix2 = sqr(dot(I, X)), Iz2 = sqr(dot(I, Ng));
|
||||
float Ix2Iz2 = Ix2 + Iz2;
|
||||
|
||||
float a = sqrt(Ix2*(Ix2Iz2 - sqr(0.05)));
|
||||
float b = Iz*0.05 + Ix2Iz2;
|
||||
float c = (a + b > 0.0)? (a + b) : (-a + b);
|
||||
|
||||
float Nz = sqrt(0.5 * c * (1.0 / Ix2Iz2));
|
||||
float Nx = sqrt(1.0 - sqr(Nz));
|
||||
|
||||
/* Transform back into global coordinates. */
|
||||
return Nx*X + Nz*Ng;
|
||||
}
|
||||
|
||||
|
||||
// Color functions
|
||||
|
|
|
@ -75,6 +75,8 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac
|
|||
object_normal_transform(kg, sd, &normal_out);
|
||||
}
|
||||
|
||||
normal_out = ensure_valid_reflection(sd->Ng, sd->I, normal_out);
|
||||
|
||||
stack_store_float3(stack, node.w, normal_out);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -345,6 +345,8 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
|
|||
N = safe_normalize(sd->N + (N - sd->N)*strength);
|
||||
}
|
||||
|
||||
N = ensure_valid_reflection(sd->Ng, sd->I, N);
|
||||
|
||||
if(is_zero(N)) {
|
||||
N = sd->N;
|
||||
}
|
||||
|
|
|
@ -774,7 +774,12 @@ int BLI_kdtree_calc_duplicates_fast(
|
|||
if (ELEM(duplicates[index], -1, index)) {
|
||||
p.search = index;
|
||||
copy_v3_v3(p.search_co, tree->nodes[node_index].co);
|
||||
int found_prev = found;
|
||||
deduplicate_recursive(&p, tree->root);
|
||||
if (found != found_prev) {
|
||||
/* Prevent chains of doubles. */
|
||||
duplicates[index] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
MEM_freeN(order);
|
||||
|
@ -786,7 +791,12 @@ int BLI_kdtree_calc_duplicates_fast(
|
|||
if (ELEM(duplicates[index], -1, index)) {
|
||||
p.search = index;
|
||||
copy_v3_v3(p.search_co, tree->nodes[node_index].co);
|
||||
int found_prev = found;
|
||||
deduplicate_recursive(&p, tree->root);
|
||||
if (found != found_prev) {
|
||||
/* Prevent chains of doubles. */
|
||||
duplicates[index] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue