Cycles / Math:

* Add M_2PI_F and M_4PI_F constants and use them inside the codebase.
This commit is contained in:
Thomas Dinges
2013-05-12 14:13:29 +00:00
parent 469979f9cb
commit 7636aeffe1
15 changed files with 41 additions and 29 deletions

View File

@@ -669,7 +669,7 @@ void ExportCurveTriangleGeometry(Mesh *mesh, ParticleCurveData *CData, int inter
if(CData->psys_closetip[sys] && (subv == segments) && (curvekey == CData->curve_firstkey[curve] + CData->curve_keynum[curve] - 2))
radius = shaperadius(CData->psys_shape[sys], CData->psys_rootradius[sys], 0.0f, 0.95f);
float angle = 2 * M_PI_F / (float)resolution;
float angle = M_2PI_F / (float)resolution;
for(int section = 0 ; section < resolution; section++) {
float3 ickey_loc_shf = ickey_loc + radius * (cosf(angle * section) * xbasis + sinf(angle * section) * ybasis);
mesh->verts.push_back(ickey_loc_shf);

View File

@@ -157,7 +157,7 @@ __device int bsdf_microfacet_ggx_sample(const ShaderClosure *sc, float3 Ng, floa
float tanThetaM2 = alpha2 * randu / (1 - randu);
float cosThetaM = 1 / safe_sqrtf(1 + tanThetaM2);
float sinThetaM = cosThetaM * safe_sqrtf(tanThetaM2);
float phiM = 2 * M_PI_F * randv;
float phiM = M_2PI_F * randv;
float3 m = (cosf(phiM) * sinThetaM) * X +
(sinf(phiM) * sinThetaM) * Y +
cosThetaM * Z;
@@ -386,7 +386,7 @@ __device int bsdf_microfacet_beckmann_sample(const ShaderClosure *sc, float3 Ng,
}
float sinThetaM = cosThetaM * tanThetaM;
float phiM = 2 * M_PI_F * randv;
float phiM = M_2PI_F * randv;
float3 m = (cosf(phiM) * sinThetaM) * X +
(sinf(phiM) * sinThetaM) * Y +
cosThetaM * Z;

View File

@@ -100,7 +100,7 @@ __device int bsdf_phong_ramp_sample(const ShaderClosure *sc, const float3 colors
float3 T, B;
make_orthonormals (R, &T, &B);
float phi = 2 * M_PI_F * randu;
float phi = M_2PI_F * randu;
float cosTheta = powf(randv, 1 / (m_exponent + 1));
float sinTheta2 = 1 - cosTheta * cosTheta;
float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0;

View File

@@ -75,11 +75,11 @@ __device float3 bsdf_ward_eval_reflect(const ShaderClosure *sc, const float3 I,
float doty = dot(H, Y) / m_ay;
float dotn = dot(H, N);
float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
float denom = (4 * M_PI_F * m_ax * m_ay * sqrtf(cosNO * cosNI));
float denom = (M_4PI_F * m_ax * m_ay * sqrtf(cosNO * cosNI));
float exp_val = expf(-exp_arg);
float out = cosNI * exp_val / denom;
float oh = dot(H, I);
denom = 4 * M_PI_F * m_ax * m_ay * oh * dotn * dotn * dotn;
denom = M_4PI_F * m_ax * m_ay * oh * dotn * dotn * dotn;
*pdf = exp_val / denom;
return make_float3 (out, out, out);
}
@@ -134,7 +134,7 @@ __device int bsdf_ward_sample(const ShaderClosure *sc, float3 Ng, float3 I, floa
else {
float val = 1 - 4 * (1 - randu);
float tanPhi = alphaRatio * tanf(M_PI_2_F * val);
// phi = 2 * M_PI_F - phi;
// phi = M_2PI_F - phi;
cosPhi = 1 / sqrtf(1 + tanPhi * tanPhi);
sinPhi = -tanPhi * cosPhi;
}
@@ -167,10 +167,10 @@ __device int bsdf_ward_sample(const ShaderClosure *sc, float3 Ng, float3 I, floa
// eq. 9
float exp_arg = (dotx * dotx + doty * doty) / (dotn * dotn);
float denom = 4 * M_PI_F * m_ax * m_ay * oh * dotn * dotn * dotn;
float denom = M_4PI_F * m_ax * m_ay * oh * dotn * dotn * dotn;
*pdf = expf(-exp_arg) / denom;
// compiler will reuse expressions already computed
denom = (4 * M_PI_F * m_ax * m_ay * sqrtf(cosNO * cosNI));
denom = (M_4PI_F * m_ax * m_ay * sqrtf(cosNO * cosNI));
float power = cosNI * expf(-exp_arg) / denom;
*eval = make_float3(power, power, power);
#ifdef __RAY_DIFFERENTIALS__

View File

@@ -91,7 +91,7 @@ __device int bsdf_westin_backscatter_sample(const ShaderClosure *sc, float3 Ng,
#endif
float3 T, B;
make_orthonormals (I, &T, &B);
float phi = 2 * M_PI_F * randu;
float phi = M_2PI_F * randu;
float cosTheta = powf(randv, 1 / (m_invroughness + 1));
float sinTheta2 = 1 - cosTheta * cosTheta;
float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0;

View File

@@ -145,7 +145,7 @@ __device float bssrdf_original(const BSSRDFParams *ss, float r)
Rdr = ss->zr*(1.0f + ss->sigma_tr*sr)*expf(-ss->sigma_tr*sr)/(sr*sr*sr);
Rdv = ss->zv*(1.0f + ss->sigma_tr*sv)*expf(-ss->sigma_tr*sv)/(sv*sv*sv);
return ss->alpha_*(1.0f/(4.0f*(float)M_PI))*(Rdr + Rdv);
return ss->alpha_*(1.0f/M_4PI_F)*(Rdr + Rdv);
}
CCL_NAMESPACE_END

View File

@@ -106,7 +106,7 @@ __device float3 background_light_sample(KernelGlobals *kg, float randu, float ra
if(sin_theta == 0.0f || denom == 0.0f)
*pdf = 0.0f;
else
*pdf = (cdf_u.x * cdf_v.x)/(2.0f * M_PI_F * M_PI_F * sin_theta * denom);
*pdf = (cdf_u.x * cdf_v.x)/(M_2PI_F * M_PI_F * sin_theta * denom);
*pdf *= kernel_data.integrator.pdf_lights;
@@ -140,7 +140,7 @@ __device float background_light_pdf(KernelGlobals *kg, float3 direction)
float2 cdf_u = kernel_tex_fetch(__light_background_conditional_cdf, index_v * (res + 1) + index_u);
float2 cdf_v = kernel_tex_fetch(__light_background_marginal_cdf, index_v);
float pdf = (cdf_u.x * cdf_v.x)/(2.0f * M_PI_F * M_PI_F * sin_theta * denom);
float pdf = (cdf_u.x * cdf_v.x)/(M_2PI_F * M_PI_F * sin_theta * denom);
return pdf * kernel_data.integrator.pdf_lights;
}
@@ -499,7 +499,7 @@ __device void curve_segment_light_sample(KernelGlobals *kg, int prim, int object
float gd = ((r2 - r1)/l);
/* normal currently ignores gradient */
ls->Ng = sinf(2 * M_PI_F * randv) * xc + cosf(2 * M_PI_F * randv) * yc;
ls->Ng = sinf(M_2PI_F * randv) * xc + cosf(M_2PI_F * randv) * yc;
ls->P = randu * l * tg + (gd * l + r1) * ls->Ng;
ls->object = object;
ls->prim = prim;

View File

@@ -95,7 +95,7 @@ __device_inline void sample_uniform_hemisphere(const float3 N,
{
float z = randu;
float r = sqrtf(max(0.0f, 1.0f - z*z));
float phi = 2.0f * M_PI_F * randv;
float phi = M_2PI_F * randv;
float x = r * cosf(phi);
float y = r * sinf(phi);
@@ -111,7 +111,7 @@ __device_inline void sample_uniform_cone(const float3 N, float angle,
{
float z = cosf(angle*randu);
float r = sqrtf(max(0.0f, 1.0f - z*z));
float phi = 2.0f * M_PI_F * randv;
float phi = M_2PI_F * randv;
float x = r * cosf(phi);
float y = r * sinf(phi);

View File

@@ -287,7 +287,7 @@ __device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float *st
float rotation = stack_load_float(stack, data_node.w);
if(rotation != 0.0f)
sc->T = rotate_around_axis(sc->T, sc->N, rotation * 2.0f * M_PI_F);
sc->T = rotate_around_axis(sc->T, sc->N, rotation * M_2PI_F);
/* compute roughness */
float roughness = param1;

View File

@@ -45,7 +45,7 @@ __device float svm_gradient(float3 p, NodeGradientType type)
return (x + y)/2.0f;
}
else if(type == NODE_BLEND_RADIAL) {
return atan2f(y, x) / (2.0f * M_PI_F) + 0.5f;
return atan2f(y, x) / M_2PI_F + 0.5f;
}
else {
float r = fmaxf(1.0f - sqrtf(x*x + y*y + z*z), 0.0f);

View File

@@ -86,7 +86,7 @@ static void bssrdf_lookup_table_create(const BSSRDFParams *ss, vector<float>& sa
/* adjust for area covered by each distance */
for(int i = 0; i < pdf.size(); i++) {
float x = (i*step)*max_radius;
pdf[i] *= 2*M_PI_F*x;
pdf[i] *= M_2PI_F*x;
}
/* normalize pdf, we multiply in reflectance later */

View File

@@ -44,7 +44,7 @@ Camera::Camera()
panorama_type = PANORAMA_EQUIRECTANGULAR;
fisheye_fov = M_PI_F;
fisheye_lens = 10.5f;
fov = M_PI_F/4.0f;
fov = M_PI_4_F;
sensorwidth = 0.036;
sensorheight = 0.024;

View File

@@ -111,7 +111,7 @@ Light::Light()
map_resolution = 512;
spot_angle = M_PI_F/4.0f;
spot_angle = M_PI_4_F;
spot_smooth = 0.0f;
cast_shadow = true;

View File

@@ -413,10 +413,10 @@ void SubdAccBuilder::computeInteriorStencil(SubdFaceRing *ring, GregoryAccStenci
}
else {
SubdVert *e0 = edge->from();
float costerm0 = cosf(2.0f * M_PI_F / pseudoValence(e0));
float costerm0 = cosf(M_2PI_F / pseudoValence(e0));
SubdVert *f0 = edge->to();
float costerm1 = cosf(2.0f * M_PI_F / pseudoValence(f0));
float costerm1 = cosf(M_2PI_F / pseudoValence(f0));
/* p0 +------+ q0
* | |

View File

@@ -42,23 +42,35 @@ CCL_NAMESPACE_BEGIN
/* Float Pi variations */
/* Division */
#ifndef M_PI_F
#define M_PI_F ((float)3.14159265358979323846264338327950288)
#define M_PI_F ((float)3.14159265358979323846264338327950288) /* pi */
#endif
#ifndef M_PI_2_F
#define M_PI_2_F ((float)1.57079632679489661923132169163975144)
#define M_PI_2_F ((float)1.57079632679489661923132169163975144) /* pi/2 */
#endif
#ifndef M_PI_4_F
#define M_PI_4_F ((float)0.785398163397448309615660845819875721)
#define M_PI_4_F ((float)0.785398163397448309615660845819875721) /* pi/4 */
#endif
#ifndef M_1_PI_F
#define M_1_PI_F ((float)0.318309886183790671537767526745028724)
#define M_1_PI_F ((float)0.318309886183790671537767526745028724) /* 1/pi */
#endif
#ifndef M_2_PI_F
#define M_2_PI_F ((float)0.636619772367581343075535053490057448)
#define M_2_PI_F ((float)0.636619772367581343075535053490057448) /* 2/pi */
#endif
/* Multiplication */
#ifndef M_2PI_F
#define M_2PI_F ((float)6.283185307179586476925286766559005768) /* 2*pi */
#endif
#ifndef M_4PI_F
#define M_4PI_F ((float)12.56637061435917295385057353311801153) /* 4*pi */
#endif
/* Float sqrt variations */
#ifndef M_SQRT2_F
#define M_SQRT2_F ((float)1.41421356237309504880)
#define M_SQRT2_F ((float)1.41421356237309504880) /* sqrt(2) */
#endif