stacy
New Member
Posts: 4
|
Post by stacy on Dec 11, 2022 19:47:26 GMT
Not sure where I'm going wrong with applying a perturbation to the surface normal, in order to achieve a sinusoidal pattern like in Jamis image on p.246 I'm adding the result of the sin function to the y-component of a "perturb" vector, and then adding that perturb vector to the surface normal. The result is then normalized. I think I'm missing something here. Would anyone mind sharing their implementation? This is the essence of the function function perturbNormal(Vector normal, Point point) { // NB: the point is in local object space double y = A * sin(point.y); Vector perturb{ 0.0, y, 0.0 }; return (normal + perturb).normalize(); } As you can see, it does something loosely resembling a sine pattern. It seems however that there is some kind of clipping occurring, and it also does not work on all shapes.
|
|
|
Post by Jamis on Dec 11, 2022 20:32:30 GMT
Hey stacy , it's looking pretty good! What does the "ysin" function do? It almost looks like you're taking the sin twice (once when declaring y, and again when declaring perturb, but I don't know what ysin is actually doing). Here's my (Ruby) implementation for comparison: def perturbNormal(pt, n) y = ((pt.y * 4) % 1) * 2 * Math::PI ofs = Math.sin(y) RTC::Tuple.vector(n.x, n.y + ofs * 0.25, n.z) end As you can see, it's mostly what you're doing (with some other calculations thrown in to scale the perturbation). Hopefully that helps!
|
|
stacy
New Member
Posts: 4
|
Post by stacy on Dec 11, 2022 22:53:27 GMT
Hey stacy , it's looking pretty good! What does the "ysin" function do? It almost looks like you're taking the sin twice (once when declaring y, and again when declaring perturb, but I don't know what ysin is actually doing). Here's my (Ruby) implementation for comparison: def perturbNormal(pt, n) y = ((pt.y * 4) % 1) * 2 * Math::PI ofs = Math.sin(y) RTC::Tuple.vector(n.x, n.y + ofs * 0.25, n.z) end As you can see, it's mostly what you're doing (with some other calculations thrown in to scale the perturbation). Hopefully that helps! Oh, drat. Thought I was being extra careful with minimizing the code to post That extra sin that was there is not actually in the code. I've edited the code block in my post to what is actually happening. Hmmm! Ok, it seems like our implementations are pretty close. Thanks Jamis! Is the `pt` in your method a local/object-space point or a world point I wonder? I notice that you're limiting the offset amount you add, to 0.25 maximum. That might be my problem here with the clipping, since I've let the total offset value be potentially larger than 0.25. It doesn't look like you are normalizing the vector before returning it. For some reason I thought that would be necessary.
|
|
|
Post by Jamis on Dec 12, 2022 4:27:55 GMT
The `pt` variable is in object-space; my `perturbNormal` function is called after converting the point to object space, and the result is then normalized in the object's `normal_at` method. (I've simplified the architecture a bit to show the implementation; suffice to say that *eventually*, the normal vector is normalized.)
|
|
stacy
New Member
Posts: 4
|
Post by stacy on Dec 13, 2022 13:06:44 GMT
The `pt` variable is in object-space; my `perturbNormal` function is called after converting the point to object space, and the result is then normalized in the object's `normal_at` method. (I've simplified the architecture a bit to show the implementation; suffice to say that *eventually*, the normal vector is normalized.) Thank you Jamis! It seems I was doing everything basically the same, but was probably "blowing out" the max/min you can perturb the normal before you start getting weird, clipped lighting results. So, it was pretty much working all along but I had to program in some more sane maximum levels for the perturbation (just like yours). It's nice when the solution is that simple Generative surface normal textures are working nice now. Here are a couple of images using Simplex and other types of noise on both the sphere and the reflective surface underneath it.
|
|