MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / SampleCubemap

Function SampleCubemap

SampleFramework12/v1.00/Graphics/Textures.h:122–162  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122template<typename T> static DirectX::XMVECTOR SampleCubemap(Float3 direction, const TextureData<T>& texData)
123{
124 Assert_(texData.NumSlices == 6);
125
126 float maxComponent = std::max(std::max(std::abs(direction.x), std::abs(direction.y)), std::abs(direction.z));
127 uint32 faceIdx = 0;
128 Float2 uv = Float2(direction.y, direction.z);
129 if(direction.x == maxComponent)
130 {
131 faceIdx = 0;
132 uv = Float2(-direction.z, -direction.y) / direction.x;
133 }
134 else if(-direction.x == maxComponent)
135 {
136 faceIdx = 1;
137 uv = Float2(direction.z, -direction.y) / -direction.x;
138 }
139 else if(direction.y == maxComponent)
140 {
141 faceIdx = 2;
142 uv = Float2(direction.x, direction.z) / direction.y;
143 }
144 else if(-direction.y == maxComponent)
145 {
146 faceIdx = 3;
147 uv = Float2(direction.x, -direction.z) / -direction.y;
148 }
149 else if(direction.z == maxComponent)
150 {
151 faceIdx = 4;
152 uv = Float2(direction.x, -direction.y) / direction.z;
153 }
154 else if(-direction.z == maxComponent)
155 {
156 faceIdx = 5;
157 uv = Float2(-direction.x, -direction.y) / -direction.z;
158 }
159
160 uv = uv * Float2(0.5f, 0.5f) + Float2(0.5f, 0.5f);
161 return SampleTexture2D(uv, faceIdx, texData);
162}
163
164}

Callers

nothing calls this directly

Calls 2

Float2Class · 0.85
SampleTexture2DFunction · 0.85

Tested by

no test coverage detected