44 if (!_graphicsDevice || !_shadowCamera || !_shadowCamera->node()) {
49 if (!programLibrary) {
53 auto shadowShader = programLibrary->getShadowShader(
false);
54 auto shadowShaderDynBatch = programLibrary->getShadowShader(
true);
59 _graphicsDevice->setShader(shadowShader);
64 static auto shadowBlendState = std::make_shared<BlendState>();
65 static auto shadowDepthState = std::make_shared<DepthState>();
66 _graphicsDevice->setBlendState(shadowBlendState);
67 _graphicsDevice->setDepthState(shadowDepthState);
72 const float bias = _light->shadowBias() * -1000.0f;
73 _graphicsDevice->setDepthBias(bias, bias, 0.0f);
76 const Matrix4 viewProjection = _shadowCamera->projectionMatrix() * _shadowCamera->node()->worldTransform().
inverse();
82 for (
auto* meshInstance : renderComponent->meshInstances()) {
83 if (!meshInstance->visible()) {
90 auto vertexBuffer = meshInstance->mesh()->getVertexBuffer();
91 meshInstance->setVisibleThisFrame(
true);
92 _graphicsDevice->setVertexBuffer(vertexBuffer, 0);
94 if (meshInstance->isDynamicBatch()) {
95 if (shadowShaderDynBatch) {
96 _graphicsDevice->setShader(shadowShaderDynBatch);
98 auto* sbi = meshInstance->skinBatchInstance();
100 _graphicsDevice->setDynamicBatchPalette(sbi->paletteData(), sbi->paletteSizeBytes());
103 _graphicsDevice->draw(meshInstance->mesh()->getPrimitive(), meshInstance->mesh()->getIndexBuffer(), 1, -1,
true,
true);
104 _graphicsDevice->setShader(shadowShader);
106 const auto modelMatrix = (meshInstance->node() ? meshInstance->node()->worldTransform() :
Matrix4::identity());
107 _graphicsDevice->setTransformUniforms(viewProjection, modelMatrix);
108 _graphicsDevice->draw(meshInstance->mesh()->getPrimitive(), meshInstance->mesh()->getIndexBuffer(), 1, -1,
true,
true);
113 (void)_shadowRenderer;