These functions are part of my library: CommonLib. The angles are such that our image is exactly the same distance behind the mirror as. We see the light coming from a direction determined by the law of reflection. When we see ourselves in a mirror, it appears that our image is actually behind the mirror. Out = eta * incidentVec - (eta * N_dot_I + sqrtf(k)) * normal The angle of reflection equals the angle of incidence. VEC3 &out, const VEC3 &incidentVec, const VEC3 &normal, float eta)įloat N_dot_I = Dot(normal, incidentVec) įloat k = 1.f - eta * eta * (1.f - N_dot_I * N_dot_I) So here is the code converted to C++.Įta is the refraction index (e.g. If you know the walls normal vector and have an incoming direction for the object, then what you want is the reflection of a vector across a plane. It took me some time to find the implementation, but finally I've found it in the GLSL Specification (thanks KriS!). Out = incidentVec - 2.f * Dot(incidentVec, normal) * normal įor reflect function, the formula is given in th HLSL documentation, but for refract function it is not. where n1 is the refractive index of material 1, n2 is the refractive index of material 2, 1 is the angle of incidence and 2. void Reflect(VEC3 &out, const VEC3 &incidentVec, const VEC3 &normal) Although there are no angles in the formula - all the necessary work is done by dot product. Reflection works according the simple rule that "angle of incidence equals angle of reflection". Some of more complex ones are reflect and refract, which calculate vector reflection and refraction in relation to the normal of a surface. But high level shader languages, designed to do geometrical computations, have many more interesting intrinsic functions. As you can see, the angle of reflection is entirely independent of the indices of refraction of the two materials. The angle m was chosen to be m 20°, and the characteristic length b was b 20 m. Math library for game developers always contains structures like vector, matrix and functions like vector normalization or matrix inversion. The Law of Reflection is fairly straightforward: i r i r 1. Nadal je udostępniam, ale prawdopodobnie nie odzwierciedlają one mojej aktualnej wiedzy ani przekonań.Įvery game developer must have some knowledge about maths and especially geometry. Uwaga! Informacje na tej stronie mają ponad 6 lat.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |