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

Method RenderAreaLightShadowMap

BakingLab/MeshRenderer.cpp:926–974  ·  view source on GitHub ↗

Renders an omni-directional shadow map for the spherical area light

Source from the content-addressed store, hash-verified

924
925// Renders an omni-directional shadow map for the spherical area light
926void MeshRenderer::RenderAreaLightShadowMap(ID3D11DeviceContext* context, const Camera& camera)
927{
928 PIXEvent event(L"Area Light Shadow Map Rendering");
929
930 const uint32 sMapSize = areaLightShadowMap.Width;
931 const Float3 areaLightPos = Float3(AppSettings::AreaLightX, AppSettings::AreaLightY, AppSettings::AreaLightZ);
932 const float nearClip = AppSettings::AreaLightSize;
933
934 for(uint64 face = 0; face < 6; ++face)
935 {
936 PIXEvent faceEvent(L"Area Light Shadow Map Face " + ToString(face));
937
938 // Set the viewport
939 SetViewport(context, sMapSize, sMapSize);
940
941 // Set the shadow map as the depth target
942 ID3D11DepthStencilView* dsv = areaLightShadowMap.ArraySlices[face];
943 ID3D11RenderTargetView* nullRenderTargets[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT] = { NULL };
944 context->OMSetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, nullRenderTargets, dsv);
945 context->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 0.0f, 0);
946
947 PerspectiveCamera shadowCamera(1.0f, Pi_2, nearClip, nearClip + 1.0f);
948
949 // Set up a infinite reverse projection
950 Float4x4 projection;
951 projection._33 = 0.0f;
952 projection._43 = nearClip;
953 projection._34 = 1.0f;
954 projection._44 = 0.0f;
955 shadowCamera.SetProjection(projection);
956
957 static const Float3 LookAtDirs[6] =
958 {
959 Float3(1.0f, 0.0f, 0.0f), Float3(-1.0f, 0.0f, 0.0f),
960 Float3(0.0f, 1.0f, 0.0f), Float3(0.0f, -1.0f, 0.0f),
961 Float3(0.0f, 0.0f, 1.0f), Float3(0.0f, 0.0f, -1.0f)
962 };
963
964 static const Float3 UpDirs[6] = {
965 Float3(0.0f, 1.0f, 0.0f), Float3(0.0f, 1.0f, 0.0f),
966 Float3(0.0f, 0.0f, -1.0f), Float3(0.0f, 0.0f, 1.0f),
967 Float3(0.0f, 1.0f, 0.0f), Float3(0.0f, 1.0f, 0.0f),
968 };
969
970 shadowCamera.SetLookAt(areaLightPos, areaLightPos + LookAtDirs[face], UpDirs[face]);
971
972 RenderDepth(context, shadowCamera, false, true);
973 }
974}
975
976// Renders the area light
977void MeshRenderer::RenderAreaLight(ID3D11DeviceContext* context, const Camera& camera)

Callers 1

RenderMainPassMethod · 0.80

Calls 5

Float3Class · 0.85
ToStringFunction · 0.85
SetViewportFunction · 0.85
SetProjectionMethod · 0.80
SetLookAtMethod · 0.80

Tested by

no test coverage detected