I'm trying to add specular reflections to a Stage3D game and it is ALMOST working, but I don't think I have a good enough grasp of the maths happening at the actual reflection stage.
I have an incoming light vector and I have the face normal; I know what to do with the resulting reflected vector (normalize and then dot product with the normalized vector pointing to the player 'camera') but what are the AGAL opcodes to reflect the original light vector off the face? I can't get my head around that. Any help appreciated...
Asked
Active
Viewed 186 times
0

moosefetcher
- 1,841
- 2
- 23
- 39
1 Answers
0
Unlike GLSL with its reflect(), AGAL does not have any kind of helper for doing this. But you can still calculate reflection vector yourself - even GLSL reference page for reflect() mentions the formula used for calculation:
For a given incident vector I and surface normal N reflect returns the reflection direction calculated as I - 2.0 * dot(N, I) * N.

Varnius
- 1,527
- 1
- 12
- 14
-
Thanks for this. I also had to limit the final dot product to between 0 and 1; negative values were, for some reason, causing a second set of reflections. – moosefetcher Oct 09 '13 at 07:34