actionscript-3stage3dagalspecular

Logic of reflecting light for 3D specular reflections


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...


Solution

  • 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.