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