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

Function ProjectCubemapToSH

SampleFramework11/v1.01/Graphics/SH.cpp:118–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117
118SH9Color ProjectCubemapToSH(ID3D11Device* device, ID3D11ShaderResourceView* cubeMap)
119{
120 TextureData<Float4> textureData;
121 GetTextureData(device, cubeMap, textureData);
122 Assert_(textureData.NumSlices == 6);
123 const uint32 width = textureData.Width;
124 const uint32 height = textureData.Height;
125
126 SH9Color result;
127 float weightSum = 0.0f;
128 for(uint32 face = 0; face < 6; ++face)
129 {
130 for(uint32 y = 0; y < height; ++y)
131 {
132 for(uint32 x = 0; x < width; ++x)
133 {
134 const uint32 idx = face * (width * height) + y * (width) + x;
135 Float3 sample = textureData.Texels[idx].To3D();
136
137 float u = (x + 0.5f) / width;
138 float v = (y + 0.5f) / height;
139
140 // Account for cubemap texel distribution
141 u = u * 2.0f - 1.0f;
142 v = v * 2.0f - 1.0f;
143 const float temp = 1.0f + u * u + v * v;
144 const float weight = 4.0f / (sqrt(temp) * temp);
145
146 Float3 dir = MapXYSToDirection(x, y, face, width, height);
147 result += ProjectOntoSH9Color(dir, sample) * weight;
148 weightSum += weight;
149 }
150 }
151 }
152
153 result *= (4.0f * 3.14159f) / weightSum;
154 return result;
155}
156
157}

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected