Shadows WIP

- Light direction in 2nd level changed
This commit is contained in:
Brandon Mak 2023-03-03 22:01:34 +08:00
parent 61a877cee1
commit 166e13a339
8 changed files with 61 additions and 36 deletions

View File

@ -17,7 +17,7 @@
Light Component: Light Component:
Position: {x: 0, y: 0, z: 0} Position: {x: 0, y: 0, z: 0}
Type: Directional Type: Directional
Direction: {x: 15, y: 90, z: 15} Direction: {x: 15, y: -90, z: 15}
Color: {x: 1, y: 1, z: 1, w: 1} Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295 Layer: 4294967295
Strength: 1 Strength: 1
@ -2251,6 +2251,8 @@
Text Renderer Component: Text Renderer Component:
Text: My name is Brandon. Text: My name is Brandon.
Font: 174412429 Font: 174412429
Color: {x: 1, y: 1, z: 1, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
UI Component: UI Component:
Canvas ID: 199 Canvas ID: 199
@ -2291,6 +2293,8 @@
Text Renderer Component: Text Renderer Component:
Text: My name is Brandon. Text: My name is Brandon.
Font: 176667660 Font: 176667660
Color: {x: 1, y: 1, z: 1, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
UI Component: UI Component:
Canvas ID: 199 Canvas ID: 199
@ -2311,6 +2315,8 @@
Text Renderer Component: Text Renderer Component:
Text: X2 Text: X2
Font: 174412429 Font: 174412429
Color: {x: 1, y: 1, z: 1, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
UI Component: UI Component:
Canvas ID: 199 Canvas ID: 199
@ -4954,6 +4960,8 @@
Text Renderer Component: Text Renderer Component:
Text: Game Pause Text: Game Pause
Font: 176667660 Font: 176667660
Color: {x: 1, y: 1, z: 1, w: 1}
Text Size: {x: 1, y: 1, z: 1}
IsActive: false IsActive: false
UI Component: UI Component:
Canvas ID: 10 Canvas ID: 10

View File

@ -14,10 +14,10 @@
Yaw: 0 Yaw: 0
Roll: 0 Roll: 0
Width: 1200 Width: 1200
Height: 1080
Near: 0.00999999978 Near: 0.00999999978
Far: 10000 Far: 10000
Perspective: true Perspective: true
FOV: 90
IsActive: true IsActive: true
Scripts: ~ Scripts: ~
- EID: 1 - EID: 1
@ -26,9 +26,9 @@
NumberOfChildren: 1 NumberOfChildren: 1
Components: Components:
Transform Component: Transform Component:
Translate: {x: -1.86388135, y: 0.0544953719, z: 0} Translate: {x: 0, y: 0.189419448, z: 0}
Rotate: {x: -0, y: 0, z: -0} Rotate: {x: 0.00523597933, y: -2.96353412, z: -6.40293041e-10}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1.00000191, y: 1, z: 1.00000191}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
Mesh: 149697411 Mesh: 149697411
@ -55,10 +55,15 @@
IsActive: true IsActive: true
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component:
Translate: {x: 0, y: 1.82978272, z: -3.28967047}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
Light Component: Light Component:
Position: {x: 3, y: 4.5, z: 7} Position: {x: 3, y: 4.5, z: 7}
Type: Directional Type: Directional
Direction: {x: -0.298000008, y: 0.522498012, z: 0.798600018} Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1} Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295 Layer: 4294967295
Strength: 0 Strength: 0
@ -85,8 +90,8 @@
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 0.0810000002, z: 0} Translate: {x: 0, y: 0.0810000002, z: 0}
Rotate: {x: -1.57079637, y: 0, z: 0} Rotate: {x: -1.57079625, y: 0, z: -0}
Scale: {x: 50, y: 50, z: 50} Scale: {x: 50, y: 49.9999924, z: 49.9999924}
IsActive: true IsActive: true
Renderable Component: Renderable Component:
Mesh: 141771688 Mesh: 141771688

View File

@ -78,8 +78,12 @@ float CalcShadowValue (sampler2D shadowMap, vec4 worldSpaceFragPos, mat4 lightPV
float pMax = LinStep (variance / (variance + (d * d)), 0.9f, 1.0f); float pMax = LinStep (variance / (variance + (d * d)), 0.9f, 1.0f);
return min (max (p, pMax), 1.0f); return min (max (p, pMax), 1.0f);
} }
else if (fragPosLightPOV.z > 1.0f)
{
return 0.0f;
}
else else
return 1.0f; return 0.3f;
// return step (fragPosLightPOV.z, ); // return step (fragPosLightPOV.z, );
} }
@ -125,7 +129,7 @@ void main()
vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction); vec3 dLightNormalized = normalize (DirLightData.dLightData[i].direction);
// Get diffuse strength // Get diffuse strength
float diffuseStrength = max (0, dot (dLightNormalized, normalView)); float diffuseStrength = max (0, dot (-dLightNormalized, normalView));
// Calculate the fragment color // Calculate the fragment color
fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse; fragColor += DirLightData.dLightData[i].diffuseColor.rgb * diffuseStrength.rrr * pixelDiffuse;

View File

@ -128,7 +128,7 @@ namespace SHADE
SHFreetypeInstance::Init(); SHFreetypeInstance::Init();
//SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false); SHAssetManager::CompileAsset("../../Assets/Shaders/DeferredComposite_CS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/ShadowMap_FS.glsl", false);
//SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false); //SHAssetManager::CompileAsset("../../Assets/Shaders/SSAO_CS.glsl", false);
@ -671,19 +671,19 @@ namespace SHADE
static bool shadowAdded = false; static bool shadowAdded = false;
//if (shadowAdded == false && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B)) if (shadowAdded == false && SHInputManager::GetKey(SHInputManager::SH_KEYCODE::B))
{
shadowAdded = true;
auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
//if (lightComps.size() > 2)
//{ //{
// shadowAdded = true; // lightComps[2].SetEnableShadow(true);
// auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
// //if (lightComps.size() > 2)
// //{
// // lightComps[2].SetEnableShadow(true);
// //}
// for (auto& comp : lightComps)
// {
// comp.SetEnableShadow(true);
// }
//} //}
for (auto& comp : lightComps)
{
comp.SetEnableShadow(true);
}
}
renderGraph->Begin(frameIndex); renderGraph->Begin(frameIndex);
auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex); auto cmdBuffer = renderGraph->GetCommandBuffer(frameIndex);

View File

@ -398,7 +398,10 @@ namespace SHADE
{ {
SHTransformComponent* transform = SHComponentManager::GetComponent<SHTransformComponent>(lightComp->GetEID()); SHTransformComponent* transform = SHComponentManager::GetComponent<SHTransformComponent>(lightComp->GetEID());
if (transform)
return SHMatrix::Transpose(SHMatrix::LookAtLH(transform->GetWorldPosition(), SHVec3::Normalise(lightComp->GetLightData().direction), SHVec3(0.0f, -1.0f, 0.0f))); return SHMatrix::Transpose(SHMatrix::LookAtLH(transform->GetWorldPosition(), SHVec3::Normalise(lightComp->GetLightData().direction), SHVec3(0.0f, -1.0f, 0.0f)));
else
return{};
} }
//return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f))); //return SHMatrix::Transpose(SHMatrix::LookAtLH(/*lightComp->GetLightData().position*/SHVec3(1.27862f, 4.78952f, 4.12811f), SHVec3(-0.280564f, -0.66262f, -0.69422f), SHVec3(0.0f, -1.0f, 0.0f)));
case SH_LIGHT_TYPE::POINT: case SH_LIGHT_TYPE::POINT:

View File

@ -73,8 +73,8 @@ namespace SHADE
public: public:
using DynamicOffsetArray = std::array<std::vector<uint32_t>, static_cast<uint32_t>(SHGraphicsConstants::NUM_FRAME_BUFFERS)>; using DynamicOffsetArray = std::array<std::vector<uint32_t>, static_cast<uint32_t>(SHGraphicsConstants::NUM_FRAME_BUFFERS)>;
static constexpr uint32_t MAX_SHADOWS = 200; static constexpr uint32_t MAX_SHADOWS = 200;
static constexpr uint32_t SHADOW_MAP_WIDTH = 1024; static constexpr uint32_t SHADOW_MAP_WIDTH = 2048;
static constexpr uint32_t SHADOW_MAP_HEIGHT = 1024; static constexpr uint32_t SHADOW_MAP_HEIGHT = 2048;
private: private:
class PerTypeData class PerTypeData

View File

@ -78,6 +78,7 @@ namespace SHADE
, viewport {rhs.viewport} , viewport {rhs.viewport}
, renderer {rhs.renderer} , renderer {rhs.renderer}
, companionSubpass {rhs.companionSubpass} , companionSubpass {rhs.companionSubpass}
, dummyPipelineLayout{rhs.dummyPipelineLayout}
{ {
} }
@ -115,6 +116,7 @@ namespace SHADE
renderer = rhs.renderer; renderer = rhs.renderer;
viewport = rhs.viewport; viewport = rhs.viewport;
companionSubpass = rhs.companionSubpass; companionSubpass = rhs.companionSubpass;
dummyPipelineLayout = rhs.dummyPipelineLayout;
return *this; return *this;
@ -456,6 +458,8 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
void SHSubpass::GenerateDummyPipielineLayout(void) noexcept void SHSubpass::GenerateDummyPipielineLayout(void) noexcept
{
if (!dummyPipelineLayout)
{ {
auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING); auto const& batchingSystemData = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING);
std::vector newLayouts = batchingSystemData.descSetLayouts; std::vector newLayouts = batchingSystemData.descSetLayouts;
@ -469,6 +473,7 @@ namespace SHADE
SHPipelineLayoutParamsDummy{ newLayouts } SHPipelineLayoutParamsDummy{ newLayouts }
); );
} }
}
/***************************************************************************/ /***************************************************************************/
/*! /*!