You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The model is basically a BRDF summarizable by this image here:
in practice there is a usual part of cosine reflection plus another part that takes into account the asymmetrical part of the scattering taking into account the angle between an ideal metallic-like reflectance and the actual reflected ray (alpha in the figures).
I' ve tried to implement it by adding some arguments to the usual functions in the project:
classPhongPDF : publicPDF {
private:
ONB uvw;
double _kd;
double _ks;
int _n;
public:PhongPDF(const Vec3& w, double kd, double ks, int n) : uvw(w), _kd(kd), _ks(ks), _n(n) {}
doublevalue(
const Vec3& direction_out,
const Vec3& direction_in,
const Vec3& direction_view) constoverride;
Vec3 generate() constoverride;
}; // class PhongPDFdoublePhongPDF::value(
const Vec3& direction_out,
const Vec3& direction_in,
const Vec3& direction_view) const {
auto cos_theta = dot(unit_vector(direction_out), uvw.w());
auto reflection = std::fmax(0, cos_theta/pi);
auto R = reflect(direction_in, uvw.w());
auto specular = std::pow(dot(-R, -direction_view), _n);
return _ks*specular + _kd*reflection;
}
Vec3 PhongPDF::generate() const {
auto r = random_double();
if (r < _kd) {
return uvw.transform(random_cosine_direction());
} elseif (_kd <= r && r < _kd + _ks) {
return uvw.transform(random_phong_direction(_n));
} else {
returnVec3();
}
}
inline Vec3 random_phong_direction(int n) {
auto r1 = random_double();
auto r2 = random_double();
auto phi = 2*pi*r2;
auto r1_1 = std::pow(r1, 2./(1+n));
auto r1_2 = std::pow(r1, 1./(1+n));
auto x = std::cos(phi)*std::sqrt(1-r1_1);
auto y = std::sin(phi)*std::sqrt(1-r1_1);
auto z = r1_2;
returnVec3(x,y,z);
}
I' m obviously doing something wrong since the image i'm getting lokks like
while it should look like a red ball with a light on top, like here for a glass sphere:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, i wanted to implement Phong model for plastic-like material to have an half matte/half glossy look.
I' m basing the phong model from these resources here:
The model is basically a BRDF summarizable by this image here:
in practice there is a usual part of cosine reflection plus another part that takes into account the asymmetrical part of the scattering taking into account the angle between an ideal metallic-like reflectance and the actual reflected ray (alpha in the figures).
I' ve tried to implement it by adding some arguments to the usual functions in the project:
with the due changes in the camera part
I' m obviously doing something wrong since the image i'm getting lokks like
while it should look like a red ball with a light on top, like here for a glass sphere:
If interested the fully executable project is in the phong branch of my repo
Beta Was this translation helpful? Give feedback.
All reactions