16typedef struct PhongRampBsdf {
23static_assert(
sizeof(
ShaderClosure) >=
sizeof(PhongRampBsdf),
"PhongRampBsdf is too large!");
29 float npos =
pos * (
float)(MAXCOLORS - 1);
33 if (ipos >= (MAXCOLORS - 1))
34 return colors[MAXCOLORS - 1];
35 float offset = npos - (
float)ipos;
36 return colors[ipos] * (1.0f - offset) + colors[ipos + 1] * offset;
42 bsdf->exponent =
max(bsdf->exponent, 0.0f);
52 float m_exponent = bsdf->exponent;
53 float cosNI =
dot(bsdf->N, wi);
54 float cosNO =
dot(bsdf->N, wo);
56 if (cosNI > 0 && cosNO > 0) {
58 float3 R = (2 * cosNI) * bsdf->N - wi;
59 float cosRO =
dot(
R, wo);
61 float cosp =
powf(cosRO, m_exponent);
62 float common = 0.5f * M_1_PI_F * cosp;
63 float out = cosNO * (m_exponent + 2) * common;
64 *pdf = (m_exponent + 1) * common;
65 return rgb_to_spectrum(bsdf_phong_ramp_get_color(bsdf->colors, cosp) * out);
74 return sqrt(1.0f / ((exponent + 2.0f) / 2.0f));
87 float cosNI =
dot(bsdf->N, wi);
88 float m_exponent = bsdf->exponent;
89 const float m_roughness = phong_ramp_exponent_to_roughness(m_exponent);
90 *sampled_roughness =
make_float2(m_roughness, m_roughness);
94 float3 R = (2 * cosNI) * bsdf->N - wi;
98 float cosTheta =
powf(rand.
y, 1 / (m_exponent + 1));
99 float sinTheta2 = 1 - cosTheta * cosTheta;
100 float sinTheta = sinTheta2 > 0 ?
sqrtf(sinTheta2) : 0;
101 *wo = (
cosf(phi) * sinTheta) * T + (
sinf(phi) * sinTheta) *
B + (cosTheta)*
R;
102 if (
dot(Ng, *wo) > 0.0f) {
104 float cosNO =
dot(bsdf->N, *wo);
107 float cosp =
powf(cosTheta, m_exponent);
108 float common = 0.5f * M_1_PI_F * cosp;
109 *pdf = (m_exponent + 1) * common;
110 float out = cosNO * (m_exponent + 2) * common;
111 *eval =
rgb_to_spectrum(bsdf_phong_ramp_get_color(bsdf->colors, cosp) * out);
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
#define ccl_device_inline
#define CCL_NAMESPACE_END
draw_view in_light_buf[] float
@ CLOSURE_BSDF_PHONG_RAMP_ID
#define SHADER_CLOSURE_BASE
ccl_device_inline Spectrum rgb_to_spectrum(float3 rgb)
SPECTRUM_DATA_TYPE Spectrum
ccl_device_inline int float_to_int(float f)
ccl_device_inline void make_orthonormals(const float3 N, ccl_private float3 *a, ccl_private float3 *b)