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

Shadow map (3 lights with shadow can be created at the same time) #447

Merged
merged 10 commits into from
Jan 25, 2024

Conversation

bxy176179
Copy link
Contributor

@bxy176179 bxy176179 commented Dec 30, 2023

There's still some bugs in point light shadow.

Comment on lines +14 to +15
LIGHT_LENGTH = num of lights(3) * num of total vec4 in one light(7)
LIGHT_TRANSFORM_LENGTH = num of lights(3) * max num of total mat4 of light transform for different kind of light(4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comments.

Comment on lines +5 to +8
void main()
{

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't need to use fragment shader, it is OK to create a program with only vertex shader. Then pipeline should help to optimize. Did you have a try?


void AddLightViewProjMatrix(cd::Matrix4x4 lightViewProjMatrix) { m_lightViewProjMatrices.push_back(lightViewProjMatrix); }
const std::vector<cd::Matrix4x4>& GetLightViewProjMatrix() { return m_lightViewProjMatrices; }
const std::vector<cd::Matrix4x4> GetLightViewProjMatrix() const { return m_lightViewProjMatrices; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const std::vector<cd::Matrix4x4> GetLightViewProjMatrix() const { return m_lightViewProjMatrices; }
std::vector<cd::Matrix4x4> GetLightViewProjMatrix() const { return m_lightViewProjMatrices; }

It is good to use const but here is not suitable for the return value to use const. The reason is that people who call this method can decide to accept return value as const or not. So in the API side, it is better not to limit const.

@@ -13,7 +13,7 @@ class RenderContext;
namespace
{

constexpr uint16_t MAX_LIGHT_COUNT = 64;
constexpr uint16_t MAX_LIGHT_COUNT = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after merging this PR, the number of math lights will be limited to 3? I am OK with a small number because game usually uses baking to simulate many "lights". It can be a TODO item to expand lighting limits.

namespace
{
// uniform name
constexpr const char* cameraPos = "u_cameraPos";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is strange that github pr page shows the first constexpr black. Actually, it should look red as a key word..

Comment on lines 142 to 153
for(float x = -totalOffset; x <= totalOffset; x += stepOffset)
{
for(float y = -totalOffset; y <= totalOffset; y += stepOffset)
{
for(float z = -totalOffset; z <= totalOffset; z += stepOffset)
{
float closestDepth = textureIndex(lightIndex, lightToFrag + vec3(x, y, z));
closestDepth *= far_plane;
shadow += step(closestDepth, currentDepth - bias);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(float x = -totalOffset; x <= totalOffset; x += stepOffset)
{
for(float y = -totalOffset; y <= totalOffset; y += stepOffset)
{
for(float z = -totalOffset; z <= totalOffset; z += stepOffset)
{
float closestDepth = textureIndex(lightIndex, lightToFrag + vec3(x, y, z));
closestDepth *= far_plane;
shadow += step(closestDepth, currentDepth - bias);
}
}
}
for(float x = -totalOffset; x <= totalOffset; x += stepOffset)
{
for(float y = -totalOffset; y <= totalOffset; y += stepOffset)
{
for(float z = -totalOffset; z <= totalOffset; z += stepOffset)
{
float closestDepth = textureIndex(lightIndex, lightToFrag + vec3(x, y, z));
closestDepth *= far_plane;
shadow += step(closestDepth, currentDepth - bias);
}
}
}

@T-rvw T-rvw requested a review from roeas January 23, 2024 12:46
@T-rvw
Copy link
Contributor

T-rvw commented Jan 25, 2024

Create https://github.com/CatDogEngine/CatDogEngine/issues/456 to track future improvements.

@T-rvw T-rvw merged commit 8104906 into main Jan 25, 2024
2 checks passed
@T-rvw T-rvw deleted the shadow_map branch January 25, 2024 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants