| 159 | struct Phong : public BSDF, PhongParams { |
| 160 | Phong(const PhongParams& params) : BSDF(), PhongParams(params) {} |
| 161 | virtual float eval (const OSL::ShaderGlobals& sg, const OSL::Vec3& wi, float& pdf) const { |
| 162 | float cosNI = N.dot(wi); |
| 163 | float cosNO = -N.dot(sg.I); |
| 164 | if (cosNI > 0 && cosNO > 0) { |
| 165 | // reflect the view vector |
| 166 | Vec3 R = (2 * cosNO) * N + sg.I; |
| 167 | float cosRI = R.dot(wi); |
| 168 | if (cosRI > 0) { |
| 169 | pdf = (exponent + 1) * float(M_1_PI / 2) * OIIO::fast_safe_pow(cosRI, exponent); |
| 170 | return cosNI * (exponent + 2) / (exponent + 1); |
| 171 | } |
| 172 | } |
| 173 | return pdf = 0; |
| 174 | } |
| 175 | virtual float sample(const OSL::ShaderGlobals& sg, float rx, float ry, float rz, OSL::Dual2<OSL::Vec3>& wi, float& pdf) const { |
| 176 | float cosNO = -N.dot(sg.I); |
| 177 | if (cosNO > 0) { |
nothing calls this directly
no test coverage detected