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

Method RenderSky

SampleFramework11/v1.01/Graphics/Skybox.cpp:305–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305void Skybox::RenderSky(ID3D11DeviceContext* context,
306 Float3 sunDirection,
307 Float3 groundAlbedo,
308 Float3 sunColor,
309 float sunSize,
310 float turbidity,
311 const Float4x4& view,
312 const Float4x4& projection,
313 Float3 scale)
314{
315 PIXEvent pixEvent(L"Skybox Render Sky");
316
317 // Update the cache, if necessary
318 skyCache.Init(sunDirection, groundAlbedo, turbidity);
319
320 if(skyCache.CubeMap == nullptr)
321 {
322 const uint64 CubeMapRes = 128;
323 std::vector<Float4> texels;
324 texels.resize(CubeMapRes * CubeMapRes * 6);
325
326 for(uint64 s = 0; s < 6; ++s)
327 {
328 for(uint64 y = 0; y < CubeMapRes; ++y)
329 {
330 for(uint64 x = 0; x < CubeMapRes; ++x)
331 {
332 Float3 dir = MapXYSToDirection(x, y, s, CubeMapRes, CubeMapRes);
333 Float3 radiance = SampleSky(skyCache, dir);
334
335 uint64 idx = (s * CubeMapRes * CubeMapRes) + (y * CubeMapRes) + x;
336 texels[idx] = Float4(radiance, 1.0f);
337 }
338 }
339 }
340
341 D3D11_TEXTURE2D_DESC desc;
342 desc.Width = uint32(CubeMapRes);
343 desc.Height = uint32(CubeMapRes);
344 desc.ArraySize = 6;
345 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
346 desc.CPUAccessFlags = 0;
347 desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
348 desc.MipLevels = 1;
349 desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
350 desc.SampleDesc.Count = 1;
351 desc.SampleDesc.Quality = 0;
352 desc.Usage = D3D11_USAGE_IMMUTABLE;
353
354 D3D11_SUBRESOURCE_DATA resData[6];
355 for(uint64 i = 0; i < 6; ++i)
356 {
357 resData[i].pSysMem = &texels[i * CubeMapRes * CubeMapRes];
358 resData[i].SysMemPitch = sizeof(texels[0]) * CubeMapRes;
359 resData[i].SysMemSlicePitch = 0;
360 }
361
362 ID3D11DevicePtr device;

Callers

nothing calls this directly

Calls 5

MapXYSToDirectionFunction · 0.85
DXCallFunction · 0.85
DegToRadFunction · 0.85
Float4Class · 0.70
InitMethod · 0.45

Tested by

no test coverage detected