**random photon directions**

A 3d vector normalized (I talk about ~5,000,000 of them per frame)

points in any direction and I need to make this all vectors a little bit random.

(depending on the material roughness of the last surface intersection)

pseudo code:

#define SMALL_RND (rnd()-rnd()) * surface_roughness

n.x += SMALL_RND : n.y += SMALL_RND : n.z += SMALL_RND

var l = n.x*n.x + n.y*n.y + n.z*n.z

Normaly the new vector can't be 0

if it was length 1.0 before and the random offset are small

how ever it's more safe here

while l=0

n.x += SMALL_RND : n.y += SMALL_RND : n.z += SMALL_RND

l = n.x*n.x + n.y*n.y + n.z*n.z

wend

The new direction vector isn't length of 1.0 any more so make it length of 1.0 again.

l=1/sqr(l) : v.x*=l : v.y*=l : v.z*=l

This looks simple and it's Ok BUT normalize = SQR() all this ~5,000,0000 vectors again and again are slow.

Is there any trick to make a normal a litle bit random but the length will be 1.0 same as before ?

The maximum range of x,y and z are -1 to +1 this reminds me on the result of

**cos**() and

**sin**() and so on ...

May be it exist a small random rotation or other

**trigonometric trick**without the need to normalized again.

Don't ask me you are the math guru here :-)

Joshy