How does one create a glossy material like Phong shading with importance sampling? #1025
miguelggcc
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hello! I hope I properly understood your question. My experience with ray tracing is relatively recent. So I hope someone could validate my answer: When generating a scatter ray, if you're randomly choosing between diffuse and specular, you must be using some weights for each, say Wd and Ws, such that Wd + Ws = 1. For instance:
If so, the scattering PDF should be a weighted sum of the two PDFs, no matter which function generated the ray:
I hope this helps. Cheers! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
EDIT; I MEAN PHONG REFLECTION MODEL, NOT SHADING
For what I understand, there's three main functions on the program when it comes to importance sampling:
With no multiple importance sampling 1. and 3. should return the same value.
Doing some look around, I found that the PDF for the specular part of a Phong material would be PDF = (n+1)/(2*PI) * (cos α)^m, and based on that I can calculate the direction sampling for a reflected ray proportional to (cos α) ^m, like on this Lafortune paper(https://www.cs.princeton.edu/courses/archive/fall03/cs526/papers/lafortune94.pdf).
The way I thought of doing it is choosing randomly between specular and diffuse scattering based on the Phong diffuse/specular parameters. If it is diffuse, I just do pdf = cos (theta)/pi and I sample with the random_cosine_direction() function. If it is specular, I still set srec.is_specular to false because I want to use the PDF functions. The problem arises once I've set if it's specular or diffuse and I call scattering_pdf with rec.mat_ptr->scattering_pdf(r, rec, scattered), how can it know if its diffuse or specular to calculate the specific PDF with the current structure just based on the incoming/outcoming ray? Am I missing something that makes everything much easier? Am I in the right path?
Beta Was this translation helpful? Give feedback.
All reactions