Nick Bedford
Nick Bedford

Reputation: 4445

Deviate reflection by percentage

I'm working on a raytracer with diffuse reflections (with say 64 or 128 samples per reflection).

For example, a material may be 75% reflective which means the reflected rays need to deviate from "perfect" reflection by 25%.

I've been trying to sort this out by calculating the reflected ray's right and up vectors and using percentages to multiply all three to combine into a deviated vector.

right = cross(intersectionNormal, ray)
up = cross(right, ray)
ray' = (ray * w) + (up * u) + (right * v)

I can't seem to get the math right. I've tried generating multipliers for each component based on spherical coordinates (random inclination at a random angle around the perfect reflection) but my math isn't working properly. The results never look like a semi-diffuse reflection. They look wrong. I'm using Random.NextDouble() to get random spherical coordinates within the material's reflectivity range.

Given a reflectivity between 1.0 (perfect) and 0.0 (diffuse), an intersection normal and a perfect reflection ray, how would I deviate this by the reflectivity percentage?

Upvotes: 1

Views: 123

Answers (1)

Waldheinz
Waldheinz

Reputation: 10487

From what you're trying to achieve it seems to me that "right" and "up" should not depend on the incoming ray's direction but just form an orthonormal basis with the normal. So you would choose up = cross(right, intersectionNormal).

But instead of rolling you own, I'd suggest to just go with one of the standard reflection models like Blinn / Phong, where the exponent does pretty much what you want your reflectivity parameter to do.

Upvotes: 0

Related Questions