mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 19:19:39 -06:00
support multiple shadowers (up to 10)
This commit is contained in:
@@ -100,7 +100,8 @@ vec3 getLevelWeights(float distToVertexOnEllipsoid) {
|
||||
);
|
||||
}
|
||||
|
||||
out vec4 position_lightspace;
|
||||
const int n_depthmaps = 10;
|
||||
out vec4 positions_lightspace[n_depthmaps];
|
||||
|
||||
void main() {
|
||||
PositionNormalPair pair = globalInterpolation(in_uv);
|
||||
|
||||
@@ -67,9 +67,10 @@ uniform float chunkMinHeight;
|
||||
uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
const int n_depthmaps = 10;
|
||||
uniform dmat4 inv_vp;
|
||||
uniform dmat4 light_vp;
|
||||
out vec4 position_lightspace;
|
||||
uniform dmat4 light_vps[n_depthmaps];
|
||||
out vec4 positions_lightspace[n_depthmaps];
|
||||
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
@@ -131,5 +132,7 @@ void main() {
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(p, 1.0));
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
|
||||
position_lightspace = vec4(light_vp * (inv_vp * dvec4(p, 1.0)));
|
||||
for (int idx = 0; idx < n_depthmaps; ++idx) {
|
||||
positions_lightspace[idx] = vec4(light_vps[idx] * (inv_vp * dvec4(p, 1.0)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,8 +154,9 @@ in vec3 positionWorldSpace;
|
||||
|
||||
uniform float opacity;
|
||||
|
||||
in vec4 position_lightspace;
|
||||
uniform sampler2D light_depth_map;
|
||||
const int n_depthmaps = 10;
|
||||
in vec4 positions_lightspace[n_depthmaps];
|
||||
uniform sampler2D light_depth_maps[n_depthmaps];
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
@@ -294,12 +295,18 @@ Fragment getFragment() {
|
||||
frag.color.xyz *= shadow < 0.99 ? clamp(shadow + 0.3, 0.0, 1.0) : shadow;
|
||||
#endif
|
||||
|
||||
vec3 coords = position_lightspace.xyz / position_lightspace.w;
|
||||
coords = coords * 0.5 + 0.5;
|
||||
float sampled_depth = texture(light_depth_map, coords.xy).r;
|
||||
float current_depth = coords.z;
|
||||
bool shadowed = false;
|
||||
for (int idx = 0; idx < n_depthmaps; ++idx) {
|
||||
vec3 coords = positions_lightspace[idx].xyz / positions_lightspace[idx].w;
|
||||
coords = coords * 0.5 + 0.5;
|
||||
float sampled_depth = texture(light_depth_maps[idx], coords.xy).r;
|
||||
float current_depth = coords.z;
|
||||
if (current_depth > sampled_depth) {
|
||||
shadowed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (current_depth > sampled_depth) {
|
||||
if (shadowed) {
|
||||
frag.color.xyz *= 0.1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1643,16 +1643,22 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
|
||||
program.setUniform("shadowMapTexture", shadowMapUnit);
|
||||
}
|
||||
|
||||
if (depthMapData.size() > 0) {
|
||||
_localRenderer.program->setUniform("light_vp", depthMapData[0].viewProjecion);
|
||||
_localRenderer.program->setUniform("inv_vp", glm::inverse(data.camera.combinedViewMatrix()));
|
||||
|
||||
ghoul::opengl::TextureUnit depthmapUnit;
|
||||
depthmapUnit.activate();
|
||||
std::vector<glm::dmat4> light_vps;
|
||||
std::vector<GLint> depthmaps;
|
||||
for (const RenderableModel::DepthMapData& data : depthMapData) {
|
||||
light_vps.push_back(data.viewProjecion);
|
||||
ghoul::opengl::TextureUnit unit;
|
||||
depthmaps.push_back(unit);
|
||||
unit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, depthMapData[0].depthMap);
|
||||
_localRenderer.program->setUniform("light_depth_map", depthmapUnit);
|
||||
}
|
||||
|
||||
_localRenderer.program->setUniform("inv_vp", glm::inverse(data.camera.combinedViewMatrix()));
|
||||
_localRenderer.program->setUniform("light_depth_maps", depthmaps);
|
||||
GLint loc = glGetUniformLocation(*_localRenderer.program, "light_vps");
|
||||
glUniformMatrix4dv(loc, light_vps.size(), GL_FALSE, glm::value_ptr(light_vps.front()));
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
if (!renderGeomOnly) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
Reference in New Issue
Block a user