33 #ifndef __BSDF_PHONG_RAMP_H__
34 #define __BSDF_PHONG_RAMP_H__
47 static_assert(
sizeof(
ShaderClosure) >=
sizeof(PhongRampBsdf),
"PhongRampBsdf is too large!");
53 float npos =
pos * (
float)(MAXCOLORS - 1);
57 if (ipos >= (MAXCOLORS - 1))
58 return colors[MAXCOLORS - 1];
59 float offset = npos - (
float)ipos;
60 return colors[ipos] * (1.0f - offset) + colors[ipos + 1] * offset;
63 ccl_device int bsdf_phong_ramp_setup(PhongRampBsdf *bsdf)
66 bsdf->exponent =
max(bsdf->exponent, 0.0f);
75 const PhongRampBsdf *bsdf = (
const PhongRampBsdf *)sc;
76 float m_exponent = bsdf->exponent;
77 float cosNI =
dot(bsdf->N, omega_in);
78 float cosNO =
dot(bsdf->N,
I);
80 if (cosNI > 0 && cosNO > 0) {
82 float3 R = (2 * cosNO) * bsdf->N -
I;
83 float cosRI =
dot(
R, omega_in);
85 float cosp =
powf(cosRI, m_exponent);
86 float common = 0.5f *
M_1_PI_F * cosp;
87 float out = cosNI * (m_exponent + 2) * common;
88 *pdf = (m_exponent + 1) * common;
89 return bsdf_phong_ramp_get_color(bsdf->colors, cosp) * out;
117 const PhongRampBsdf *bsdf = (
const PhongRampBsdf *)sc;
118 float cosNO =
dot(bsdf->N,
I);
119 float m_exponent = bsdf->exponent;
123 float3 R = (2 * cosNO) * bsdf->N -
I;
126 *domega_in_dx = (2 *
dot(bsdf->N, dIdx)) * bsdf->N - dIdx;
127 *domega_in_dy = (2 *
dot(bsdf->N, dIdy)) * bsdf->N - dIdy;
133 float cosTheta =
powf(randv, 1 / (m_exponent + 1));
134 float sinTheta2 = 1 - cosTheta * cosTheta;
135 float sinTheta = sinTheta2 > 0 ?
sqrtf(sinTheta2) : 0;
136 *omega_in = (
cosf(phi) * sinTheta) *
T + (
sinf(phi) * sinTheta) *
B + (cosTheta)*
R;
137 if (
dot(Ng, *omega_in) > 0.0f) {
139 float cosNI =
dot(bsdf->N, *omega_in);
142 float cosp =
powf(cosTheta, m_exponent);
143 float common = 0.5f *
M_1_PI_F * cosp;
144 *pdf = (m_exponent + 1) * common;
145 float out = cosNI * (m_exponent + 2) * common;
146 *eval = bsdf_phong_ramp_get_color(bsdf->colors, cosp) * out;
typedef float(TangentPoint)[2]
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
#define SHADER_CLOSURE_BASE
#define __RAY_DIFFERENTIALS__
@ CLOSURE_BSDF_PHONG_RAMP_ID
ccl_device_inline int float_to_int(float f)
ccl_device_inline void make_orthonormals(const float3 N, float3 *a, float3 *b)
ccl_device_inline float dot(const float2 &a, const float2 &b)