mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Added skinned mesh shadow
This commit is contained in:
@@ -180,7 +180,7 @@ float ShadowCalculation(Light light, vec3 FragPos, vec3 normal)
|
||||
float bias = max(0.005 * (1.0 - dot(normal, light.Direction)), 0.0005);
|
||||
//float pcfDepth = texture(ShadowMaps[shadowmap], vec3(projCoords.xy, currentDepth), bias);
|
||||
|
||||
if (shadowmap <= 3)
|
||||
if (shadowmap <= 4)
|
||||
{
|
||||
const float NUM_SAMPLES = 4.f;
|
||||
const float SAMPLES_START = (NUM_SAMPLES - 1.0f) / 2.0f;
|
||||
|
||||
45
Editor/resources/Shaders/shadowMap_skinned.shader
Normal file
45
Editor/resources/Shaders/shadowMap_skinned.shader
Normal file
@@ -0,0 +1,45 @@
|
||||
#shader vertex
|
||||
#version 460 core
|
||||
|
||||
layout(location = 0) in vec3 Position;
|
||||
layout(location = 1) in vec2 UVPosition;
|
||||
layout(location = 2) in vec3 Normal;
|
||||
layout(location = 3) in vec3 Tangent;
|
||||
layout(location = 4) in vec3 Bitangent;
|
||||
layout(location = 5) in ivec4 BoneIDs;
|
||||
layout(location = 6) in vec4 Weights;
|
||||
|
||||
uniform mat4 u_LightTransform;
|
||||
|
||||
const int MAX_BONES = 200;
|
||||
const int MAX_BONES_INFLUENCE = 4;
|
||||
uniform mat4 u_FinalBonesMatrice[MAX_BONES];
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 totalPosition = vec4(0.0f);
|
||||
for (int i = 0; i < MAX_BONES_INFLUENCE; i++)
|
||||
{
|
||||
if (BoneIDs[i] == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (BoneIDs[i] >= MAX_BONES)
|
||||
{
|
||||
totalPosition = vec4(Position, 1.0f);
|
||||
break;
|
||||
}
|
||||
|
||||
vec4 localPosition = u_FinalBonesMatrice[BoneIDs[i]] * vec4(Position, 1.0f);
|
||||
totalPosition += localPosition * Weights[i];
|
||||
// vec3 localNormal = mat3(u_FinalBonesMatrice[BoneIDs[i]]) * Normal;
|
||||
}
|
||||
|
||||
gl_Position = u_LightTransform * totalPosition;
|
||||
}
|
||||
|
||||
#shader fragment
|
||||
#version 460 core
|
||||
|
||||
void main() { }
|
||||
@@ -49,8 +49,12 @@ namespace Nuake
|
||||
|
||||
for (auto& m : i.second)
|
||||
{
|
||||
if (!depthOnly)
|
||||
{
|
||||
shader->SetUniform1i(entityIdUniformLocation, m.entityId + 1);
|
||||
}
|
||||
|
||||
shader->SetUniformMat4f(modelMatrixUniformLocation, m.transform);
|
||||
shader->SetUniform1i(entityIdUniformLocation, m.entityId + 1);
|
||||
m.Mesh->Draw(shader, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +262,43 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Shader* gBufferSkinnedMeshShader = ShaderManager::GetShader("resources/Shaders/shadowMap_skinned.shader");
|
||||
gBufferSkinnedMeshShader->Bind();
|
||||
const uint32_t modelMatrixUniformLocation = gBufferSkinnedMeshShader->FindUniformLocation("u_Model");
|
||||
gBufferSkinnedMeshShader->SetUniformMat4f(modelMatrixUniformLocation, Matrix4(1.0f));
|
||||
|
||||
auto skinnedView = scene.m_Registry.view<TransformComponent, SkinnedModelComponent, VisibilityComponent>();
|
||||
for (auto l : view)
|
||||
{
|
||||
auto [lightTransform, light, visibility] = view.get<TransformComponent, LightComponent, VisibilityComponent>(l);
|
||||
if (light.Type != LightType::Directional || !light.CastShadows || !visibility.Visible)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < CSM_AMOUNT; i++)
|
||||
{
|
||||
light.m_Framebuffers[i]->Bind();
|
||||
{
|
||||
gBufferSkinnedMeshShader->SetUniformMat4f("u_LightTransform", light.mViewProjections[i]);
|
||||
for (auto e : skinnedView)
|
||||
{
|
||||
auto [transform, mesh, visibility] = skinnedView.get<TransformComponent, SkinnedModelComponent, VisibilityComponent>(e);
|
||||
if (mesh.ModelResource != nullptr && visibility.Visible)
|
||||
{
|
||||
auto& rootBoneNode = mesh.ModelResource->GetSkeletonRootNode();
|
||||
SetSkeletonBoneTransformRecursive(rootBoneNode, gBufferSkinnedMeshShader);
|
||||
|
||||
for (auto& m : mesh.ModelResource->GetMeshes())
|
||||
{
|
||||
m->Draw(gBufferSkinnedMeshShader, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SceneRenderer::GBufferPass(Scene& scene)
|
||||
@@ -293,10 +330,8 @@ namespace Nuake
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Renderer::Flush(gBufferShader, false);
|
||||
|
||||
|
||||
// Quake BSPs
|
||||
auto quakeView = scene.m_Registry.view<TransformComponent, BSPBrushComponent, VisibilityComponent>();
|
||||
for (auto e : quakeView)
|
||||
@@ -311,7 +346,6 @@ namespace Nuake
|
||||
Renderer::SubmitMesh(b, transform.GetGlobalTransform(), (uint32_t)e);
|
||||
}
|
||||
}
|
||||
|
||||
Renderer::Flush(gBufferShader, false);
|
||||
|
||||
RenderCommand::Disable(RendererEnum::FACE_CULL);
|
||||
@@ -400,7 +434,6 @@ namespace Nuake
|
||||
if (meshResource && visibility.Visible)
|
||||
{
|
||||
auto& rootBoneNode = meshResource->GetSkeletonRootNode();
|
||||
|
||||
SetSkeletonBoneTransformRecursive(rootBoneNode, gBufferSkinnedMeshShader);
|
||||
|
||||
for (auto& m : mesh.ModelResource->GetMeshes())
|
||||
|
||||
Reference in New Issue
Block a user