@@ -8,69 +8,69 @@ namespace nbl
88namespace hlsl
99{
1010// TODO: use glm instead for c++
11- template<typename T >
12- inline matrix <T , 4 , 4 > buildProjectionMatrixPerspectiveFovRH (float fieldOfViewRadians, float aspectRatio, float zNear, float zFar)
11+ template<typename FloatingPoint >
12+ inline matrix <FloatingPoint , 4 , 4 > buildProjectionMatrixPerspectiveFovRH (FloatingPoint fieldOfViewRadians, FloatingPoint aspectRatio, FloatingPoint zNear, FloatingPoint zFar)
1313{
14- const float h = core::reciprocal<float >( tanf (fieldOfViewRadians * 0.5f ));
14+ const FloatingPoint h = core::reciprocal<FloatingPoint>( tan (fieldOfViewRadians * 0.5f ));
1515 _NBL_DEBUG_BREAK_IF (aspectRatio == 0.f ); //division by zero
1616 const float w = h / aspectRatio;
1717
1818 _NBL_DEBUG_BREAK_IF (zNear == zFar); //division by zero
1919
20- matrix <T , 4 , 4 > m;
21- m[0 ] = vector <T , 4 >(w, 0.f , 0.f , 0.f );
22- m[1 ] = vector <T , 4 >(0.f , -h, 0.f , 0.f );
23- m[2 ] = vector <T , 4 >(0.f , 0.f , -zFar / (zFar - zNear), -zNear * zFar / (zFar - zNear));
24- m[3 ] = vector <T , 4 >(0.f , 0.f , -1.f , 0.f );
20+ matrix <FloatingPoint , 4 , 4 > m;
21+ m[0 ] = vector <FloatingPoint , 4 >(w, 0.f , 0.f , 0.f );
22+ m[1 ] = vector <FloatingPoint , 4 >(0.f , -h, 0.f , 0.f );
23+ m[2 ] = vector <FloatingPoint , 4 >(0.f , 0.f , -zFar / (zFar - zNear), -zNear * zFar / (zFar - zNear));
24+ m[3 ] = vector <FloatingPoint , 4 >(0.f , 0.f , -1.f , 0.f );
2525
2626 return m;
2727}
28- template<typename T >
29- inline matrix <T , 4 , 4 > buildProjectionMatrixPerspectiveFovLH (float fieldOfViewRadians, float aspectRatio, float zNear, float zFar)
28+ template<typename FloatingPoint >
29+ inline matrix <FloatingPoint , 4 , 4 > buildProjectionMatrixPerspectiveFovLH (FloatingPoint fieldOfViewRadians, FloatingPoint aspectRatio, FloatingPoint zNear, FloatingPoint zFar)
3030{
31- const float h = core::reciprocal<float >( tanf (fieldOfViewRadians * 0.5f ));
31+ const FloatingPoint h = core::reciprocal<FloatingPoint>( tan (fieldOfViewRadians * 0.5f ));
3232 _NBL_DEBUG_BREAK_IF (aspectRatio == 0.f ); //division by zero
3333 const float w = h / aspectRatio;
3434
3535 _NBL_DEBUG_BREAK_IF (zNear == zFar); //division by zero
3636
37- matrix <T , 4 , 4 > m;
38- m[0 ] = vector <T , 4 >(w, 0.f , 0.f , 0.f );
39- m[1 ] = vector <T , 4 >(0.f , -h, 0.f , 0.f );
40- m[2 ] = vector <T , 4 >(0.f , 0.f , zFar / (zFar - zNear), -zNear * zFar / (zFar - zNear));
41- m[3 ] = vector <T , 4 >(0.f , 0.f , 1.f , 0.f );
37+ matrix <FloatingPoint , 4 , 4 > m;
38+ m[0 ] = vector <FloatingPoint , 4 >(w, 0.f , 0.f , 0.f );
39+ m[1 ] = vector <FloatingPoint , 4 >(0.f , -h, 0.f , 0.f );
40+ m[2 ] = vector <FloatingPoint , 4 >(0.f , 0.f , zFar / (zFar - zNear), -zNear * zFar / (zFar - zNear));
41+ m[3 ] = vector <FloatingPoint , 4 >(0.f , 0.f , 1.f , 0.f );
4242
4343 return m;
4444}
4545
46- template<typename T >
47- inline matrix <T , 4 , 4 > buildProjectionMatrixOrthoRH (float widthOfViewVolume, float heightOfViewVolume, float zNear, float zFar)
46+ template<typename FloatingPoint >
47+ inline matrix <FloatingPoint , 4 , 4 > buildProjectionMatrixOrthoRH (FloatingPoint widthOfViewVolume, FloatingPoint heightOfViewVolume, FloatingPoint zNear, FloatingPoint zFar)
4848{
4949 _NBL_DEBUG_BREAK_IF (widthOfViewVolume == 0.f ); //division by zero
5050 _NBL_DEBUG_BREAK_IF (heightOfViewVolume == 0.f ); //division by zero
5151 _NBL_DEBUG_BREAK_IF (zNear == zFar); //division by zero
5252
53- matrix <T , 4 , 4 > m;
54- m[0 ] = vector <T , 4 >(2.f / widthOfViewVolume, 0.f , 0.f , 0.f );
55- m[1 ] = vector <T , 4 >(0.f , -2.f / heightOfViewVolume, 0.f , 0.f );
56- m[2 ] = vector <T , 4 >(0.f , 0.f , -1.f / (zFar - zNear), -zNear / (zFar - zNear));
57- m[3 ] = vector <T , 4 >(0.f , 0.f , 0.f , 1.f );
53+ matrix <FloatingPoint , 4 , 4 > m;
54+ m[0 ] = vector <FloatingPoint , 4 >(2.f / widthOfViewVolume, 0.f , 0.f , 0.f );
55+ m[1 ] = vector <FloatingPoint , 4 >(0.f , -2.f / heightOfViewVolume, 0.f , 0.f );
56+ m[2 ] = vector <FloatingPoint , 4 >(0.f , 0.f , -1.f / (zFar - zNear), -zNear / (zFar - zNear));
57+ m[3 ] = vector <FloatingPoint , 4 >(0.f , 0.f , 0.f , 1.f );
5858
5959 return m;
6060}
6161
62- template<typename T >
63- inline matrix <T , 4 , 4 > buildProjectionMatrixOrthoLH (float widthOfViewVolume, float heightOfViewVolume, float zNear, float zFar)
62+ template<typename FloatingPoint >
63+ inline matrix <FloatingPoint , 4 , 4 > buildProjectionMatrixOrthoLH (FloatingPoint widthOfViewVolume, FloatingPoint heightOfViewVolume, FloatingPoint zNear, FloatingPoint zFar)
6464{
6565 _NBL_DEBUG_BREAK_IF (widthOfViewVolume == 0.f ); //division by zero
6666 _NBL_DEBUG_BREAK_IF (heightOfViewVolume == 0.f ); //division by zero
6767 _NBL_DEBUG_BREAK_IF (zNear == zFar); //division by zero
6868
69- matrix <T , 4 , 4 > m;
70- m[0 ] = vector <T , 4 >(2.f / widthOfViewVolume, 0.f , 0.f , 0.f );
71- m[1 ] = vector <T , 4 >(0.f , -2.f / heightOfViewVolume, 0.f , 0.f );
72- m[2 ] = vector <T , 4 >(0.f , 0.f , 1.f / (zFar - zNear), -zNear / (zFar - zNear));
73- m[3 ] = vector <T , 4 >(0.f , 0.f , 0.f , 1.f );
69+ matrix <FloatingPoint , 4 , 4 > m;
70+ m[0 ] = vector <FloatingPoint , 4 >(2.f / widthOfViewVolume, 0.f , 0.f , 0.f );
71+ m[1 ] = vector <FloatingPoint , 4 >(0.f , -2.f / heightOfViewVolume, 0.f , 0.f );
72+ m[2 ] = vector <FloatingPoint , 4 >(0.f , 0.f , 1.f / (zFar - zNear), -zNear / (zFar - zNear));
73+ m[3 ] = vector <FloatingPoint , 4 >(0.f , 0.f , 0.f , 1.f );
7474
7575 return m;
7676}
0 commit comments