Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atmosphere scattering lighting #425

Merged
merged 12 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace castor3d::shader
C3D_API sdw::Vec3 combine( sdw::Vec3 const & directDiffuse
, sdw::Vec3 const & indirectDiffuse
, sdw::Vec3 const & directSpecular
, sdw::Vec3 const & directScattering
, sdw::Vec3 const & indirectSpecular
, sdw::Vec3 const & ambient
, sdw::Vec3 const & indirectAmbient
Expand All @@ -53,21 +54,22 @@ namespace castor3d::shader
C3D_API void compute( DirectionalLight const & light
, LightMaterial const & material
, Surface const & surface
, BackgroundModel & background
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void compute( PointLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void compute( SpotLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void computeMapContributions( PassFlags const & passFlags
, TextureFlagsArray const & textures
, TextureConfigurations const & textureConfigs
Expand Down Expand Up @@ -99,17 +101,17 @@ namespace castor3d::shader
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API sdw::Vec3 computeDiffuse( PointLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API sdw::Vec3 computeDiffuse( SpotLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API void computeMapDiffuseContributions( PassFlags const & passFlags
, TextureFlagsArray const & textures
, TextureConfigurations const & textureConfigs
Expand All @@ -127,16 +129,6 @@ namespace castor3d::shader
, LightMaterial & lightMat )override;
//\}

protected:
void doDeclareModel()override;
void doDeclareComputeDirectionalLight()override;
void doDeclareComputePointLight()override;
void doDeclareComputeSpotLight()override;
void doDeclareDiffuseModel()override;
void doDeclareComputeDirectionalLightDiffuse()override;
void doDeclareComputePointLightDiffuse()override;
void doDeclareComputeSpotLightDiffuse()override;

public:
CookTorranceBRDF m_cookTorrance;
sdw::Function< sdw::Void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace castor3d::shader
C3D_API sdw::Vec3 combine( sdw::Vec3 const & directDiffuse
, sdw::Vec3 const & indirectDiffuse
, sdw::Vec3 const & directSpecular
, sdw::Vec3 const & directScattering
, sdw::Vec3 const & indirectSpecular
, sdw::Vec3 const & ambient
, sdw::Vec3 const & indirectAmbient
Expand All @@ -49,21 +50,22 @@ namespace castor3d::shader
C3D_API void compute( DirectionalLight const & light
, LightMaterial const & material
, Surface const & surface
, BackgroundModel & background
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void compute( PointLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void compute( SpotLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows
, OutputComponents & output )const override;
, OutputComponents & output )override;
C3D_API void computeMapContributions( PassFlags const & passFlags
, TextureFlagsArray const & textures
, TextureConfigurations const & textureConfigs
Expand Down Expand Up @@ -95,17 +97,17 @@ namespace castor3d::shader
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API sdw::Vec3 computeDiffuse( PointLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API sdw::Vec3 computeDiffuse( SpotLight const & light
, LightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Int const & receivesShadows )const override;
, sdw::Int const & receivesShadows )override;
C3D_API void computeMapDiffuseContributions( PassFlags const & passFlags
, TextureFlagsArray const & textures
, TextureConfigurations const & textureConfigs
Expand All @@ -129,29 +131,17 @@ namespace castor3d::shader
}

protected:
void doDeclareModel()override;
void doDeclareComputeDirectionalLight()override;
void doDeclareComputePointLight()override;
void doDeclareComputeSpotLight()override;
void doDeclareDiffuseModel()override;
void doDeclareComputeDirectionalLightDiffuse()override;
void doDeclareComputePointLightDiffuse()override;
void doDeclareComputeSpotLightDiffuse()override;

private:
sdw::RetVec3 doComputeLight( Light const & light
C3D_API sdw::RetVec3 doComputeLight( Light const & light
, PhongLightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Vec3 const & lightDirection
, OutputComponents & output );
void doDeclareComputeLight();
sdw::Vec3 doComputeLightDiffuse( Light const & light
C3D_API sdw::Vec3 doComputeLightDiffuse( Light const & light
, PhongLightMaterial const & material
, Surface const & surface
, sdw::Vec3 const & worldEye
, sdw::Vec3 const & lightDirection );
void doDeclareComputeLightDiffuse();

public:
C3D_API static castor::String getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ namespace castor3d
HdrConfigUbo m_hdrConfigUbo;
SceneUbo m_sceneUbo;
crg::ImageViewId m_colourView;
BackgroundRendererUPtr m_backgroundRenderer;
crg::FramePass * m_opaquePassDesc{};
RenderTechniquePass * m_opaquePass{};
BackgroundRendererUPtr m_backgroundRenderer;
crg::FramePass * m_transparentPassDesc{};
RenderTechniquePass * m_transparentPass{};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ namespace castor3d
*\param[in] shadows Dit si les ombres sont utilisées.
*\return Le source.
*/
static ShaderPtr getPixelShaderSource( PassTypeID passType
, RenderSystem const & renderSystem
static ShaderPtr getPixelShaderSource( Scene const & scene
, SceneFlags const & sceneFlags
, LightType lightType
, ShadowType shadowType
, bool shadows );
, bool shadows
, VkExtent2D const & targetSize );
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace castor3d
eData2,
eData3,
eData4,
eData5,
};
/**
*\~english
Expand All @@ -61,6 +60,7 @@ namespace castor3d
eModelMatrix,
eSmLinear,
eSmVariance,
eCount,
};
/**
*\~english
Expand All @@ -76,6 +76,7 @@ namespace castor3d
eDepth,
eDiffuse,
eSpecular,
eScattering,
eIndirectDiffuse,
eIndirectSpecular,
CU_ScopedEnumBounds( eDepth ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ namespace castor3d
{
struct LightsPipeline
{
LightsPipeline( crg::FramePass const & pass
LightsPipeline( Scene const & scene
, crg::FramePass const & pass
, crg::GraphContext & context
, crg::RunnableGraph & graph
, RenderDevice const & device
, LightPipelineConfig const & config
, LightPassResult const & lpResult
, ShadowMapResult const & smResult
, std::vector< LightRenderPass > const & renderPasses
, std::vector< LightRenderPass > const & stencilRenderPasses );
, std::vector< LightRenderPass > const & stencilRenderPasses
, crg::ImageId const & targetColourResult );

void clear();
void addLight( Camera const & camera
Expand Down Expand Up @@ -87,6 +89,7 @@ namespace castor3d
ShadowMapResult const & m_smResult;
RenderDevice const & m_device;
std::vector< LightRenderPass > const & m_renderPasses;
Scene const & m_scene;
LightPipelineConfig m_config;
ShaderModule m_vertexShader;
ShaderModule m_pixelShader;
Expand All @@ -101,6 +104,7 @@ namespace castor3d
std::map< size_t, std::unique_ptr< LightDescriptors > > m_lightDescriptors;
std::vector< LightDescriptors const * > m_enabledLights;
Viewport m_viewport;
crg::ImageId m_targetColourResult;
};

using LightsPipelinePtr = std::unique_ptr< LightsPipeline >;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace castor3d
, LightPassResult const & lpResult
, ShadowMapResult const & smDirectionalResult
, ShadowMapResult const & smPointResult
, ShadowMapResult const & smSpotResult );
, ShadowMapResult const & smSpotResult
, crg::ImageId const & targetColourResult );

void clear();
void enableLight( Camera const & camera
Expand Down Expand Up @@ -55,6 +56,7 @@ namespace castor3d
ShadowMapResult const & m_smDirectionalResult;
ShadowMapResult const & m_smPointResult;
ShadowMapResult const & m_smSpotResult;
crg::ImageId const & m_targetColourResult;
std::vector< LightRenderPass > m_renderPasses;
std::vector< LightRenderPass > m_stencilRenderPasses;
std::map< size_t, LightsPipelinePtr > m_pipelines;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace castor3d
, ShadowMapResult const & smPointResult
, ShadowMapResult const & smSpotResult
, LightPassResult const & lpResult
, crg::ImageId const & targetColourResult
, SceneUbo const & sceneUbo
, GpInfoUbo const & gpInfoUbo );
/**
Expand Down Expand Up @@ -111,6 +112,7 @@ namespace castor3d
ShadowMapResult const & m_smPointResult;
ShadowMapResult const & m_smSpotResult;
LightPassResult const & m_lpResult;
crg::ImageId const & m_targetColourResult;
SceneUbo const & m_sceneUbo;
GpInfoUbo const & m_gpInfoUbo;
crg::FramePassGroup & m_group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace castor3d
, Texture const & subsurfaceScattering
, Texture const & lightDiffuse
, Texture const & lightSpecular
, Texture const & lightScattering
, Texture const & lightIndirectDiffuse
, Texture const & lightIndirectSpecular
, Texture const & result
Expand Down Expand Up @@ -130,6 +131,7 @@ namespace castor3d
Texture const & m_ssaoResult;
Texture const & m_subsurfaceScattering;
Texture const & m_lightSpecular;
Texture const & m_lightScattering;
Texture const & m_lightIndirectDiffuse;
Texture const & m_lightIndirectSpecular;
std::vector< ProgramPtr > m_programs;
Expand Down
7 changes: 6 additions & 1 deletion include/Core/Castor3D/Scene/Animation/AnimatedTexture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ namespace castor3d
*name Getters.
**/
/**@{*/
bool hasTexture()const
{
return m_texture != nullptr;
}

TextureUnit & getTexture()const
{
CU_Require( m_texture );
CU_Require( hasTexture() );
return *m_texture;
}

Expand Down
5 changes: 5 additions & 0 deletions include/Core/Castor3D/Scene/Background/Background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ namespace castor3d
return false;
}

virtual bool hasScattering()const
{
return false;
}

Scene const & getScene()const
{
return m_scene;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace castor3d::shader
public:
C3D_API IblBackgroundModel( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

C3D_API static BackgroundModelPtr create( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

Expand All @@ -38,9 +40,6 @@ namespace castor3d::shader
, LightMaterial const & material
, sdw::Vec3 & reflection
, sdw::Vec3 & refraction )override;
C3D_API sdw::Vec4 scatter( sdw::Vec2 const & fragPos
, sdw::Vec2 const & fragSize
, sdw::Float const & fragDepth )override;

private:
sdw::Vec3 doComputeRefractions( sdw::Vec3 const & wsIncident
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace castor3d::shader
public:
C3D_API ImgBackgroundModel( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

C3D_API static BackgroundModelPtr create( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

Expand All @@ -38,9 +40,6 @@ namespace castor3d::shader
, LightMaterial const & material
, sdw::Vec3 & reflection
, sdw::Vec3 & refraction )override;
C3D_API sdw::Vec4 scatter( sdw::Vec2 const & fragPos
, sdw::Vec2 const & fragSize
, sdw::Float const & fragDepth )override;

public:
static castor::String const Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace castor3d::shader
public:
C3D_API NoIblBackgroundModel( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

C3D_API static BackgroundModelPtr create( sdw::ShaderWriter & writer
, Utils & utils
, VkExtent2D targetSize
, uint32_t & binding
, uint32_t set );

Expand All @@ -38,9 +40,6 @@ namespace castor3d::shader
, LightMaterial const & material
, sdw::Vec3 & reflection
, sdw::Vec3 & refraction )override;
C3D_API sdw::Vec4 scatter( sdw::Vec2 const & fragPos
, sdw::Vec2 const & fragSize
, sdw::Float const & fragDepth )override;

private:
sdw::Vec3 doComputeRefractions( sdw::Vec3 const & wsIncident
Expand Down
Loading