8 #include <nap/service.h>
9 #include <depthrendertarget.h>
10 #include <rendertexturecube.h>
11 #include <materialinstance.h>
12 #include <renderablemesh.h>
16 #include "cuberendertarget.h"
17 #include "cubedepthrendertarget.h"
18 #include "lightcomponent.h"
19 #include "lightflags.h"
20 #include "rendertag.h"
21 #include "emptymesh.h"
22 #include "cubemapfromfile.h"
28 class RenderableComponentInstance;
36 inline constexpr
const char*
id =
"lightscene";
48 friend class PreRenderCubeMapsCommand;
50 virtual rtti::
TypeInfo getServiceType() const;
54 bool mEnableShadowMapping = true;
118 const std::vector<LightComponentInstance*>&
getLights() {
return mLightComponents; }
137 void renderShadows(
const std::vector<RenderableComponentInstance*>& renderComps,
bool updateMaterials =
true,
RenderMask renderMask = 0);
168 void pushLights(
const std::vector<RenderableComponentInstance*>& renderComps);
182 virtual void getDependentServices(std::vector<rtti::TypeInfo>& dependencies)
override;
196 virtual void preShutdown()
override;
203 virtual void shutdown()
override;
209 virtual void preResourcesLoaded()
override;
214 virtual void postResourcesLoaded()
override;
237 virtual void postUpdate(
double deltaTime);
240 void pushLightsInternal(
const std::vector<MaterialInstance*>& materials);
250 struct ShadowMapEntry
252 ShadowMapEntry(std::unique_ptr<DepthRenderTarget> target, std::unique_ptr<DepthRenderTexture2D> texture) :
253 mTarget(std::move(target)), mTexture(std::move(texture))
255 mTarget->mDepthTexture = mTexture.get();
258 std::unique_ptr<DepthRenderTarget> mTarget;
259 std::unique_ptr<DepthRenderTexture2D> mTexture;
267 CubeMapEntry(std::unique_ptr<CubeDepthRenderTarget> target, std::unique_ptr<DepthRenderTextureCube> texture) :
268 mTarget(std::move(target)), mTexture(std::move(
texture))
270 mTarget->mCubeDepthTexture = mTexture.get();
273 std::unique_ptr<CubeDepthRenderTarget> mTarget;
274 std::unique_ptr<DepthRenderTextureCube> mTexture;
278 RenderService* mRenderService =
nullptr;
281 std::vector<LightComponentInstance*> mLightComponents;
284 std::unordered_map<LightComponentInstance*, std::unique_ptr<ShadowMapEntry>> mLightDepthMap;
285 std::unordered_map<LightComponentInstance*, std::unique_ptr<CubeMapEntry>> mLightCubeMap;
286 std::unordered_map<LightComponentInstance*, LightFlags> mLightFlagsMap;
288 std::unique_ptr<Sampler2DArray> mSampler2DResource;
289 std::unique_ptr<SamplerCubeArray> mSamplerCubeResource;
290 std::unique_ptr<DepthRenderTexture2D> mShadowTextureDummy;
291 std::unique_ptr<nap::Scene> mLightScene =
nullptr;
293 bool mShadowMappingEnabled =
true;
294 bool mShadowResourcesCreated =
false;
297 std::unordered_map<CubeMapFromFile*, std::unique_ptr<CubeRenderTarget>> mCubeMapTargets;
299 std::unique_ptr<EmptyMesh> mNoMesh;
300 std::unique_ptr<MaterialInstanceResource> mCubeMaterialInstanceResource;
301 std::unique_ptr<MaterialInstance> mCubeMaterialInstance;
302 Material* mCubeMapMaterial =
nullptr;
304 static constexpr
const uint mRequiredVulkanVersionMajor = 1;
305 static constexpr
const uint mRequiredVulkanVersionMinor = 0;
306 static constexpr
const uint mMaxLightCount = 8;