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);
160 void pushLights(
const std::vector<RenderableComponentInstance*>& renderComps);
174 virtual void getDependentServices(std::vector<rtti::TypeInfo>& dependencies)
override;
188 virtual void preShutdown()
override;
195 virtual void shutdown()
override;
201 virtual void preResourcesLoaded()
override;
206 virtual void postResourcesLoaded()
override;
229 virtual void postUpdate(
double deltaTime);
232 void pushLightsInternal(
const std::vector<MaterialInstance*>& materials);
242 struct ShadowMapEntry
244 ShadowMapEntry(std::unique_ptr<DepthRenderTarget> target, std::unique_ptr<DepthRenderTexture2D> texture) :
245 mTarget(std::move(target)), mTexture(std::move(texture))
247 mTarget->mDepthTexture = mTexture.get();
250 std::unique_ptr<DepthRenderTarget> mTarget;
251 std::unique_ptr<DepthRenderTexture2D> mTexture;
259 CubeMapEntry(std::unique_ptr<CubeDepthRenderTarget> target, std::unique_ptr<DepthRenderTextureCube> texture) :
260 mTarget(std::move(target)), mTexture(std::move(
texture))
262 mTarget->mCubeDepthTexture = mTexture.get();
265 std::unique_ptr<CubeDepthRenderTarget> mTarget;
266 std::unique_ptr<DepthRenderTextureCube> mTexture;
270 RenderService* mRenderService =
nullptr;
273 std::vector<LightComponentInstance*> mLightComponents;
276 std::unordered_map<LightComponentInstance*, std::unique_ptr<ShadowMapEntry>> mLightDepthMap;
277 std::unordered_map<LightComponentInstance*, std::unique_ptr<CubeMapEntry>> mLightCubeMap;
278 std::unordered_map<LightComponentInstance*, LightFlags> mLightFlagsMap;
280 std::unique_ptr<Sampler2DArray> mSampler2DResource;
281 std::unique_ptr<SamplerCubeArray> mSamplerCubeResource;
282 std::unique_ptr<DepthRenderTexture2D> mShadowTextureDummy;
283 std::unique_ptr<nap::Scene> mLightScene =
nullptr;
285 bool mShadowMappingEnabled =
true;
286 bool mShadowResourcesCreated =
false;
289 std::unordered_map<CubeMapFromFile*, std::unique_ptr<CubeRenderTarget>> mCubeMapTargets;
291 std::unique_ptr<EmptyMesh> mNoMesh;
292 std::unique_ptr<MaterialInstanceResource> mCubeMaterialInstanceResource;
293 std::unique_ptr<MaterialInstance> mCubeMaterialInstance;
294 Material* mCubeMapMaterial =
nullptr;
296 static constexpr
const uint mRequiredVulkanVersionMajor = 1;
297 static constexpr
const uint mRequiredVulkanVersionMinor = 0;
298 static constexpr
const uint mMaxLightCount = 8;