MCPcopy Create free account
hub / github.com/TheRealMJP/BakingLab / ProjectCubemapToSH

Function ProjectCubemapToSH

SampleFramework11/v1.02/Graphics/SH.cpp:251–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251SH9Color ProjectCubemapToSH(ID3D11Device* device, ID3D11ShaderResourceView* cubeMap)
252{
253 TextureData<Float4> textureData;
254 GetTextureData(device, cubeMap, textureData);
255 Assert_(textureData.NumSlices == 6);
256 const uint32 width = textureData.Width;
257 const uint32 height = textureData.Height;
258
259 SH9Color result;
260 float weightSum = 0.0f;
261 for(uint32 face = 0; face < 6; ++face)
262 {
263 for(uint32 y = 0; y < height; ++y)
264 {
265 for(uint32 x = 0; x < width; ++x)
266 {
267 const uint32 idx = face * (width * height) + y * (width) + x;
268 Float3 sample = textureData.Texels[idx].To3D();
269
270 float u = (x + 0.5f) / width;
271 float v = (y + 0.5f) / height;
272
273 // Account for cubemap texel distribution
274 u = u * 2.0f - 1.0f;
275 v = v * 2.0f - 1.0f;
276 const float temp = 1.0f + u * u + v * v;
277 const float weight = 4.0f / (sqrt(temp) * temp);
278
279 Float3 dir = MapXYSToDirection(x, y, face, width, height);
280 result += ProjectOntoSH9Color(dir, sample) * weight;
281 weightSum += weight;
282 }
283 }
284 }
285
286 result *= (4.0f * 3.14159f) / weightSum;
287 return result;
288}
289
290}

Callers

nothing calls this directly

Calls 5

GetTextureDataFunction · 0.85
sqrtFunction · 0.85
MapXYSToDirectionFunction · 0.85
ProjectOntoSH9ColorFunction · 0.85
To3DMethod · 0.80

Tested by

no test coverage detected