Cycles: Cleanup: Add general-purpose conversion between sin and cos
This commit is contained in:
parent
b1c8889396
commit
ce25e3e581
|
@ -41,11 +41,6 @@ static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledHairBSDF),
|
|||
static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledHairExtra),
|
||||
"PrincipledHairExtra is too large!");
|
||||
|
||||
ccl_device_inline float cos_from_sin(const float s)
|
||||
{
|
||||
return safe_sqrtf(1.0f - s * s);
|
||||
}
|
||||
|
||||
/* Gives the change in direction in the normal plane for the given angles and p-th-order
|
||||
* scattering. */
|
||||
ccl_device_inline float delta_phi(int p, float gamma_o, float gamma_t)
|
||||
|
|
|
@ -200,7 +200,7 @@ ccl_device_forceinline float3 microfacet_sample_stretched(KernelGlobals kg,
|
|||
|
||||
if (wi_.z < 0.99999f) {
|
||||
costheta_ = wi_.z;
|
||||
sintheta_ = safe_sqrtf(1.0f - costheta_ * costheta_);
|
||||
sintheta_ = sin_from_cos(costheta_);
|
||||
|
||||
float invlen = 1.0f / sintheta_;
|
||||
cosphi_ = wi_.x * invlen;
|
||||
|
|
|
@ -43,7 +43,7 @@ ccl_device_forceinline float2 mf_sampleP22_11(const float cosI,
|
|||
return make_float2(r * cosf(phi), r * sinf(phi));
|
||||
}
|
||||
|
||||
const float sinI = safe_sqrtf(1.0f - cosI * cosI);
|
||||
const float sinI = sin_from_cos(cosI);
|
||||
const float tanI = sinI / cosI;
|
||||
const float projA = 0.5f * (cosI + 1.0f);
|
||||
if (projA < 0.0001f)
|
||||
|
|
|
@ -88,7 +88,7 @@ henyey_greenstrein_sample(float3 D, float g, float randu, float randv, ccl_priva
|
|||
}
|
||||
}
|
||||
|
||||
float sin_theta = safe_sqrtf(1.0f - cos_theta * cos_theta);
|
||||
float sin_theta = sin_from_cos(cos_theta);
|
||||
float phi = M_2PI_F * randv;
|
||||
float3 dir = make_float3(sin_theta * cosf(phi), sin_theta * sinf(phi), cos_theta);
|
||||
|
||||
|
|
|
@ -720,7 +720,7 @@ ccl_device_inline void curve_shader_setup(KernelGlobals kg,
|
|||
const float3 tangent = normalize(dPdu);
|
||||
const float3 bitangent = normalize(cross(tangent, -D));
|
||||
const float sine = sd->v;
|
||||
const float cosine = safe_sqrtf(1.0f - sine * sine);
|
||||
const float cosine = cos_from_sin(sine);
|
||||
|
||||
sd->N = normalize(sine * bitangent - cosine * normalize(cross(tangent, bitangent)));
|
||||
# if 0
|
||||
|
|
|
@ -704,9 +704,9 @@ ccl_device_forceinline bool mnee_compute_transfer_matrix(ccl_private const Shade
|
|||
float ilo = -eta * ilh;
|
||||
|
||||
float cos_theta = dot(wo, m.n);
|
||||
float sin_theta = safe_sqrtf(1.f - sqr(cos_theta));
|
||||
float sin_theta = sin_from_cos(cos_theta);
|
||||
float cos_phi = dot(wo, s);
|
||||
float sin_phi = safe_sqrtf(1.f - sqr(cos_phi));
|
||||
float sin_phi = sin_from_cos(cos_phi);
|
||||
|
||||
/* Wo = (cos_phi * sin_theta) * s + (sin_phi * sin_theta) * t + cos_theta * n. */
|
||||
float3 dH_dtheta = ilo * (cos_theta * (cos_phi * s + sin_phi * t) - sin_theta * m.n);
|
||||
|
|
|
@ -136,7 +136,7 @@ ccl_device_forceinline float diffusion_length_dwivedi(float alpha)
|
|||
|
||||
ccl_device_forceinline float3 direction_from_cosine(float3 D, float cos_theta, float randv)
|
||||
{
|
||||
float sin_theta = safe_sqrtf(1.0f - cos_theta * cos_theta);
|
||||
float sin_theta = sin_from_cos(cos_theta);
|
||||
float phi = M_2PI_F * randv;
|
||||
float3 dir = make_float3(sin_theta * cosf(phi), sin_theta * sinf(phi), cos_theta);
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ ccl_device float area_light_spread_attenuation(const float3 D,
|
|||
/* The factor M_PI_F comes from integrating the radiance over the hemisphere */
|
||||
return (cos_a > 0.9999997f) ? M_PI_F : 0.0f;
|
||||
}
|
||||
const float sin_a = safe_sqrtf(1.0f - sqr(cos_a));
|
||||
const float sin_a = sin_from_cos(cos_a);
|
||||
const float tan_a = sin_a / cos_a;
|
||||
return max((tan_half_spread - tan_a) * normalize_spread, 0.0f);
|
||||
}
|
||||
|
|
|
@ -47,11 +47,6 @@ ccl_device float light_tree_cos_bounding_box_angle(const BoundingBox bbox,
|
|||
return cos_theta_u;
|
||||
}
|
||||
|
||||
ccl_device_forceinline float sin_from_cos(const float c)
|
||||
{
|
||||
return safe_sqrtf(1.0f - sqr(c));
|
||||
}
|
||||
|
||||
/* Compute vector v as in Fig .8. P_v is the corresponding point along the ray. */
|
||||
ccl_device float3 compute_v(
|
||||
const float3 centroid, const float3 P, const float3 D, const float3 bcone_axis, const float t)
|
||||
|
|
|
@ -218,7 +218,7 @@ ccl_device_forceinline bool triangle_light_sample(KernelGlobals kg,
|
|||
/* Finally, select a random point along the edge of the new triangle
|
||||
* That point on the spherical triangle is the sampled ray direction */
|
||||
const float z = 1.0f - randv * (1.0f - dot(C_, B));
|
||||
ls->D = z * B + safe_sqrtf(1.0f - z * z) * safe_normalize(C_ - dot(C_, B) * B);
|
||||
ls->D = z * B + sin_from_cos(z) * safe_normalize(C_ - dot(C_, B) * B);
|
||||
|
||||
/* calculate intersection with the planar triangle */
|
||||
if (!ray_triangle_intersect(
|
||||
|
|
|
@ -67,17 +67,18 @@ ccl_device_inline void sample_uniform_cone(const float3 N,
|
|||
ccl_private float3 *wo,
|
||||
ccl_private float *pdf)
|
||||
{
|
||||
float zMin = cosf(angle);
|
||||
float z = zMin - zMin * randu + randu;
|
||||
float r = safe_sqrtf(1.0f - sqr(z));
|
||||
float phi = M_2PI_F * randv;
|
||||
float x = r * cosf(phi);
|
||||
float y = r * sinf(phi);
|
||||
const float cosThetaMin = cosf(angle);
|
||||
const float cosTheta = mix(cosThetaMin, 1.0f, randu);
|
||||
const float sinTheta = sin_from_cos(cosTheta);
|
||||
const float phi = M_2PI_F * randv;
|
||||
const float x = sinTheta * cosf(phi);
|
||||
const float y = sinTheta * sinf(phi);
|
||||
const float z = cosTheta;
|
||||
|
||||
float3 T, B;
|
||||
make_orthonormals(N, &T, &B);
|
||||
*wo = x * T + y * B + z * N;
|
||||
*pdf = M_1_2PI_F / (1.0f - zMin);
|
||||
*pdf = M_1_2PI_F / (1.0f - cosThetaMin);
|
||||
}
|
||||
|
||||
ccl_device_inline float pdf_uniform_cone(const float3 N, float3 D, float angle)
|
||||
|
|
|
@ -750,6 +750,16 @@ ccl_device_inline float sqr(float a)
|
|||
return a * a;
|
||||
}
|
||||
|
||||
ccl_device_inline float sin_from_cos(const float c)
|
||||
{
|
||||
return safe_sqrtf(1.0f - sqr(c));
|
||||
}
|
||||
|
||||
ccl_device_inline float cos_from_sin(const float s)
|
||||
{
|
||||
return safe_sqrtf(1.0f - sqr(s));
|
||||
}
|
||||
|
||||
ccl_device_inline float pow20(float a)
|
||||
{
|
||||
return sqr(sqr(sqr(sqr(a)) * a));
|
||||
|
|
Loading…
Reference in New Issue