mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Implement shadow mapping pipeline for terrain and models
This commit is contained in:
parent
dede5a99d4
commit
f17b15395d
6 changed files with 306 additions and 1 deletions
|
|
@ -174,6 +174,18 @@ private:
|
|||
void resizePostProcess(int w, int h);
|
||||
void shutdownPostProcess();
|
||||
|
||||
// Shadow mapping
|
||||
static constexpr int SHADOW_MAP_SIZE = 2048;
|
||||
uint32_t shadowFBO = 0;
|
||||
uint32_t shadowDepthTex = 0;
|
||||
uint32_t shadowShaderProgram = 0;
|
||||
glm::mat4 lightSpaceMatrix = glm::mat4(1.0f);
|
||||
|
||||
void initShadowMap();
|
||||
void renderShadowPass();
|
||||
uint32_t compileShadowShader();
|
||||
glm::mat4 computeLightSpaceMatrix();
|
||||
|
||||
pipeline::AssetManager* cachedAssetManager = nullptr;
|
||||
uint32_t currentZoneId = 0;
|
||||
std::string currentZoneName;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@ public:
|
|||
|
||||
GLuint getProgram() const { return program; }
|
||||
|
||||
// Adopt an externally-created program (no ownership of individual shaders)
|
||||
void setProgram(GLuint prog) { program = prog; }
|
||||
// Release ownership without deleting (caller retains the GL program)
|
||||
void releaseProgram() { program = 0; vertexShader = 0; fragmentShader = 0; }
|
||||
|
||||
private:
|
||||
bool compile(const std::string& vertexSource, const std::string& fragmentSource);
|
||||
GLint getUniformLocation(const std::string& name) const;
|
||||
|
|
|
|||
|
|
@ -125,6 +125,19 @@ public:
|
|||
void setFogEnabled(bool enabled) { fogEnabled = enabled; }
|
||||
bool isFogEnabled() const { return fogEnabled; }
|
||||
|
||||
/**
|
||||
* Render terrain geometry into shadow depth map
|
||||
*/
|
||||
void renderShadow(GLuint shaderProgram);
|
||||
|
||||
/**
|
||||
* Set shadow map for receiving shadows
|
||||
*/
|
||||
void setShadowMap(GLuint depthTex, const glm::mat4& lightSpaceMat) {
|
||||
shadowDepthTex = depthTex; lightSpaceMatrix = lightSpaceMat; shadowEnabled = true;
|
||||
}
|
||||
void clearShadowMap() { shadowEnabled = false; }
|
||||
|
||||
/**
|
||||
* Get statistics
|
||||
*/
|
||||
|
|
@ -187,6 +200,11 @@ private:
|
|||
|
||||
// Default white texture (fallback)
|
||||
GLuint whiteTexture = 0;
|
||||
|
||||
// Shadow mapping (receiving)
|
||||
GLuint shadowDepthTex = 0;
|
||||
glm::mat4 lightSpaceMatrix = glm::mat4(1.0f);
|
||||
bool shadowEnabled = false;
|
||||
};
|
||||
|
||||
} // namespace rendering
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue