   Daylight model: values go infinite
  Hi all, I've implemented a few months ago this Daylight model (I've mostly copied/pasted code from their reference implementation and adapted it to my code).Recently I noticed that often I get infinite values from the algorithm, and precisely from this function:float Perez(float A, float B, float C, float D, float E, float theta, float gamma) const{float t1 = A * exp(B / cos(theta));float t2 = C * exp(D * gamma);float t3 = cos(gamma);t3 = E * (t3 * t3);return (1.0f + t1) * (1.0f + t2 + t3);}If I don't misunderstand the paper, theta is [0.0, PI/2[ . As theta approaches PI/2, B/cos(theta) increases and sometimes goes to infinity.Theoretically, those theta values should be rare events in my raytracer (I uniformly sample the hemisphere) but I often get values close to PI/2 (this is another problem though).Now my question: how is the algorithm supposed to prevent infinite values? I gave a look to the original code but was not able to find something useful except from a check that theta is < PI/2.Any idea?   
  The problem I could see is if cos(theta) approaches 0 (theta almost PI/2). In this case B/cos(t) will go up to an infinite value followed by exp(B/cos(t)). Best to cap your values when using low precision (float instead of double) calculations. Try something likefloat f1 = A * exp( B/ max(cos(theta,EPSILON)));with EPSILON with a low value like 0.00001f. Play around with EPSILON to get a satisfying result.   ;  Thank you, yes, there is where I've found the problem, but I was looking more for a solution inside the model than a trick because I suppose that anyone using that model will face this issue.Howerver I tried with a 0.01 epsilo (smaller values do not prevent infinites) and results are good enough.Thank you!   