MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / RenderShadowMap

Method RenderShadowMap

TombEngine/Renderer/RendererDraw.cpp:129–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127 }
128
129 void Renderer::RenderShadowMap(RendererItem* item, RenderView& renderView)
130 {
131 // Doesn't cast shadow.
132 if (_moveableObjects[item->ObjectID].value().ShadowType == ShadowMode::None)
133 return;
134
135 // Only render for player if such setting is active.
136 if (g_Configuration.ShadowType == ShadowMode::Player && _moveableObjects[item->ObjectID].value().ShadowType != ShadowMode::Player)
137 return;
138
139 // No shadow light found.
140 if (_shadowLight == nullptr)
141 return;
142
143 // Shadow light found but type is incorrect.
144 if (_shadowLight->Type != LightType::Point && _shadowLight->Type != LightType::Spot)
145 return;
146
147 // Reset GPU state.
148 SetBlendMode(BlendMode::Opaque);
149 SetCullMode(CullMode::CounterClockwise);
150
151 auto shadowLightPos = (_shadowLight->Hash == 0) ?
152 _shadowLight->Position :
153 Vector3::Lerp(_shadowLight->PrevPosition, _shadowLight->Position, GetInterpolationFactor());
154
155 for (int step = 0; step < 6; step++)
156 {
157 // Bind render target.
158 _context->OMSetRenderTargets(1, _shadowMap.RenderTargetView[step].GetAddressOf(),
159 _shadowMap.DepthStencilView[step].Get());
160
161 _context->RSSetViewports(1, &_shadowMapViewport);
162 ResetScissor();
163
164 if (shadowLightPos == item->Position)
165 return;
166
167 unsigned int stride = sizeof(Vertex);
168 unsigned int offset = 0;
169
170 // Set shaders.
171 _shaders.Bind(Shader::ShadowMap);
172
173 _context->IASetVertexBuffers(0, 1, _moveablesVertexBuffer.Buffer.GetAddressOf(), &stride, &offset);
174 _context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
175 _context->IASetInputLayout(_inputLayout.Get());
176 _context->IASetIndexBuffer(_moveablesIndexBuffer.Buffer.Get(), DXGI_FORMAT_R32_UINT, 0);
177
178 // Set texture.
179 BindTexture(TextureRegister::ColorMap, &std::get<0>(_moveablesTextures[0]), SamplerStateRegister::AnisotropicClamp);
180 BindTexture(TextureRegister::NormalMap, &std::get<1>(_moveablesTextures[0]), SamplerStateRegister::AnisotropicClamp);
181
182 // Set camera matrices.
183 auto view = Matrix::CreateLookAt(shadowLightPos, shadowLightPos +
184 RenderTargetCube::forwardVectors[step] * BLOCK(10),
185 RenderTargetCube::upVectors[step]);
186

Callers

nothing calls this directly

Calls 8

LerpFunction · 0.85
TENLogFunction · 0.85
GetAddressOfMethod · 0.80
BindMethod · 0.80
valueMethod · 0.45
GetMethod · 0.45
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected