1 /**********************************************************************
2 Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ********************************************************************/
22 
23 module radeonrays.math.ray;
24 
25 import radeonrays.math.float3;
26 import radeonrays.math.int2;
27 
28 extern(C++,"RadeonRays")
29 {
30 	struct ray
31 	{
32 		this(float3 oo, 
33 			float3 dd = float3(0,0,0), 
34 			float maxt = float.max, 
35 			float time = 0.0f)
36 		{
37 			o = oo;
38 			d = dd;
39 			SetMaxT(maxt);
40 			SetTime(time);
41 			SetMask(0xFFFFFFFF);
42 			SetActive(true);
43 			SetDoBackfaceCulling(false);
44 		}
45 		
46 		float3 operator ()(float t) const
47 		{
48 			return o + t * d;
49 		}
50 		
51 		void SetTime(float time)
52 		{
53 			d.w = time;
54 		}
55 		
56 		float GetTime() const
57 		{
58 			return d.w;
59 		}
60 		
61 		void SetMaxT(float maxt)
62 		{
63 			o.w = maxt;
64 		}
65 		
66 		float GetMaxT() const
67 		{
68 			return o.w;
69 		}
70 		
71 		void SetMask(int mask)
72 		{
73 			extra.x = mask;
74 		}
75 		
76 		int GetMask() const
77 		{
78 			return extra.x;
79 		}
80 		
81 		void SetActive(bool active)
82 		{
83 			extra.y = active ? 1 : 0;
84 		}
85 		
86 		bool IsActive() const
87 		{
88 			return extra.y > 0;
89 		}
90 		
91 		void SetDoBackfaceCulling(bool _bDoBackfaceCulling)
92 		{
93 			doBackfaceCulling = _bDoBackfaceCulling ? 1 : 0;
94 		}
95 
96 		bool GetDoBackfaceCulling() const
97 		{
98 			return doBackfaceCulling > 0;
99 		}
100 		
101 		float4 o = float4(0,0,0,float.max);
102 		float4 d = float4(0,0,0,0);
103 		int2 extra = int2(0xFFFFFFFF,1);
104 		int doBackfaceCulling;
105 		int padding;
106 	};
107 }