File indexing completed on 2026-05-15 07:41:58
0001 #pragma once
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #if defined(__CUDACC__) || defined(__CUDABE__)
0021 #define QWLS_METHOD __device__
0022 #else
0023 #define QWLS_METHOD
0024 #endif
0025
0026 struct qwls
0027 {
0028 cudaTextureObject_t wls_tex;
0029 unsigned hd_factor;
0030 int *material_map;
0031 float *time_constants;
0032 unsigned num_wls;
0033 unsigned tex_height;
0034
0035 #if defined(__CUDACC__) || defined(__CUDABE__) || defined(MOCK_CURAND) || defined(MOCK_CUDA)
0036
0037 QWLS_METHOD bool has_wls(unsigned mat_idx) const;
0038 QWLS_METHOD float wavelength(unsigned mat_idx, const float &u0) const;
0039 QWLS_METHOD float wavelength_at_row(unsigned base_row, const float &u0) const;
0040 QWLS_METHOD float time_constant(unsigned mat_idx) const;
0041
0042 #endif
0043 };
0044
0045 #if defined(__CUDACC__) || defined(__CUDABE__) || defined(MOCK_CURAND) || defined(MOCK_CUDA)
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 inline QWLS_METHOD bool qwls::has_wls(unsigned mat_idx) const
0057 {
0058 return material_map[mat_idx] >= 0;
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 inline QWLS_METHOD float qwls::time_constant(unsigned mat_idx) const
0071 {
0072 int base_row = material_map[mat_idx];
0073 if (base_row < 0)
0074 return 0.f;
0075 unsigned wls_idx = base_row / 3;
0076 return time_constants[wls_idx];
0077 }
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 inline QWLS_METHOD float qwls::wavelength(unsigned mat_idx, const float &u0) const
0092 {
0093 int base_row = material_map[mat_idx];
0094 if (base_row < 0)
0095 return 0.f;
0096 return wavelength_at_row(unsigned(base_row), u0);
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 inline QWLS_METHOD float qwls::wavelength_at_row(unsigned base_row, const float &u0) const
0115 {
0116 float y0 = (float(base_row) + 0.5f) / float(tex_height);
0117 float y1 = (float(base_row + 1) + 0.5f) / float(tex_height);
0118 float y2 = (float(base_row + 2) + 0.5f) / float(tex_height);
0119
0120 float wl;
0121
0122 if (hd_factor == 0)
0123 {
0124 wl = tex2D<float>(wls_tex, u0, y0);
0125 }
0126 else if (hd_factor == 10)
0127 {
0128 if (u0 < 0.1f)
0129 wl = tex2D<float>(wls_tex, u0 * 10.f, y1);
0130 else if (u0 > 0.9f)
0131 wl = tex2D<float>(wls_tex, (u0 - 0.9f) * 10.f, y2);
0132 else
0133 wl = tex2D<float>(wls_tex, u0, y0);
0134 }
0135 else
0136 {
0137 if (u0 < 0.05f)
0138 wl = tex2D<float>(wls_tex, u0 * 20.f, y1);
0139 else if (u0 > 0.95f)
0140 wl = tex2D<float>(wls_tex, (u0 - 0.95f) * 20.f, y2);
0141 else
0142 wl = tex2D<float>(wls_tex, u0, y0);
0143 }
0144
0145 return wl;
0146 }
0147
0148 #endif