-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comments.
void main() | ||
{ | ||
|
||
} |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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..
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); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | |
} | |
} | |
} |
Create https://github.com/CatDogEngine/CatDogEngine/issues/456 to track future improvements. |
There's still some bugs in point light shadow.