Fermat
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
optix_payload.h
1 /*
2  * Fermat
3  *
4  * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #ifndef OPTIX_COMPILATION
32 #define OPTIX_COMPILATION
33 #endif
34 
35 #ifndef WIN32
36 #define WIN32
37 #endif
38 
39 #include <vector_types.h>
40 
41 #include <vertex.h>
42 #include <ray.h>
43 
46 struct Payload
47 {
48  uint4 packed;
49 
50  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
51  Payload() {}
52 
53  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
54  Payload(const float _t, const int32 _tri_id, const float _u, const float _v, const uint8 _mask)
55  {
56  set_t( _t );
57  set_triangle_id( _tri_id );
58  set_uv( _u, _v );
59  set_mask( _mask );
60  }
61 
62  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
63  void set_t(const float _t) { packed.x = __float_as_uint(_t); }
64 
65  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
66  float t() const { return __uint_as_float(packed.x); }
67 
68  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
69  void set_triangle_id(const int32 _tri_id) { packed.y = uint32(_tri_id); }
70 
71  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
72  int32 triangle_id() const { return int32(packed.y); }
73 
74  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
75  void set_uv(const float _u, const float _v) { packed.z = cugar::binary_cast<uint32>( __floats2half2_rn(_u,_v) ); }
76 
77  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
78  float2 uv() const { return __half22float2( cugar::binary_cast<__half2>( packed.z ) ); }
79 
80  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
81  float t(const float _t) { return __uint_as_float(packed.x); }
82 
83  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
84  void set_mask(const uint8 _mask) { packed.w = uint32(_mask); }
85 
86  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
87  uint32 mask() const { return uint32(packed.w); }
88 
89  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
90  operator Hit() const
91  {
92  return make_hit( t(), triangle_id(), uv().x, uv().y );
93  }
94 
95  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
96  operator bool() const { return t() >= 0.0f; }
97 };
98 
102 {
103  uint2 packed;
104 
105  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
106  ShadowPayload() {}
107 
108  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
109  ShadowPayload(const uint32 _mask, const bool _hit)
110  {
111  set_mask( _mask );
112  set_hit( _hit );
113  }
114 
115  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
116  uint32 mask() const { return uint32(packed.x); }
117 
118  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
119  void set_mask(const uint8 _mask) { packed.x = _mask; }
120 
121  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
122  void set_hit(const bool _hit) { packed.y = _hit ? 1u : 0u; }
123 
124  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
125  operator bool() const { return packed.y ? true : false; }
126 };
Definition: optix_payload.h:46
Definition: optix_payload.h:101
Definition: ray.h:68
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288