Got multiple shadows working. The really ugly way.
This commit is contained in:
parent
705d9e3875
commit
49b7cb34fe
@ -6,8 +6,8 @@ add_subdirectory(converter)
|
||||
PROJECT(MarbleRaceGroupC)
|
||||
|
||||
# ACGL setup
|
||||
SET(ACGL_OPENGL_SUPPORT CORE_40)
|
||||
ADD_DEFINITIONS(-DACGL_OPENGL_VERSION_40)
|
||||
SET(ACGL_OPENGL_SUPPORT CORE_32)
|
||||
ADD_DEFINITIONS(-DACGL_OPENGL_VERSION_32)
|
||||
ADD_DEFINITIONS(-DACGL_OPENGL_PROFILE_CORE)
|
||||
# create the newest availabe OpenGL context, independent of the ACGL version:
|
||||
#ADD_DEFINITIONS(-DGLFW_OPENGL_LATEST_VERSION)
|
||||
|
@ -9,7 +9,38 @@ out vec4 oColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform sampler2DShadow shadowMap;
|
||||
uniform samplerCubeShadow shadowMap_cube[1];
|
||||
uniform samplerCubeShadow shadowMap_cube0;
|
||||
uniform samplerCubeShadow shadowMap_cube1;
|
||||
uniform samplerCubeShadow shadowMap_cube2;
|
||||
uniform samplerCubeShadow shadowMap_cube3;
|
||||
uniform samplerCubeShadow shadowMap_cube4;
|
||||
uniform samplerCubeShadow shadowMap_cube5;
|
||||
uniform samplerCubeShadow shadowMap_cube6;
|
||||
uniform samplerCubeShadow shadowMap_cube7;
|
||||
uniform samplerCubeShadow shadowMap_cube8;
|
||||
uniform samplerCubeShadow shadowMap_cube9;
|
||||
uniform samplerCubeShadow shadowMap_cube10;
|
||||
uniform samplerCubeShadow shadowMap_cube11;
|
||||
uniform samplerCubeShadow shadowMap_cube12;
|
||||
uniform samplerCubeShadow shadowMap_cube13;
|
||||
uniform samplerCubeShadow shadowMap_cube14;
|
||||
uniform samplerCubeShadow shadowMap_cube15;
|
||||
uniform samplerCubeShadow shadowMap_cube16;
|
||||
uniform samplerCubeShadow shadowMap_cube17;
|
||||
uniform samplerCubeShadow shadowMap_cube18;
|
||||
uniform samplerCubeShadow shadowMap_cube19;
|
||||
uniform samplerCubeShadow shadowMap_cube20;
|
||||
uniform samplerCubeShadow shadowMap_cube21;
|
||||
uniform samplerCubeShadow shadowMap_cube22;
|
||||
uniform samplerCubeShadow shadowMap_cube23;
|
||||
uniform samplerCubeShadow shadowMap_cube24;
|
||||
uniform samplerCubeShadow shadowMap_cube25;
|
||||
uniform samplerCubeShadow shadowMap_cube26;
|
||||
uniform samplerCubeShadow shadowMap_cube27;
|
||||
uniform samplerCubeShadow shadowMap_cube28;
|
||||
uniform samplerCubeShadow shadowMap_cube29;
|
||||
uniform samplerCubeShadow shadowMap_cube30;
|
||||
uniform samplerCubeShadow shadowMap_cube31;
|
||||
uniform vec3 ambientColor;
|
||||
uniform float ambientFactor;
|
||||
uniform float diffuseFactor;
|
||||
@ -113,11 +144,15 @@ void main()
|
||||
specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
|
||||
*specularFactor*intensity*lightColors[i];
|
||||
if (i == 0) {
|
||||
visibility = samplePointShadow(shadowMap_cube[0], lightDirection);
|
||||
visibility *= samplePointShadow(shadowMap_cube0, lightDirection);
|
||||
}
|
||||
if (i == 1) {
|
||||
visibility *= samplePointShadow(shadowMap_cube1, lightDirection);
|
||||
}
|
||||
if (i == 2) {
|
||||
visibility *= samplePointShadow(shadowMap_cube2, lightDirection);
|
||||
}
|
||||
}
|
||||
/*float value = texture(shadowMap_cube, lightDirection);
|
||||
oColor = vec4(value, value, value, 255);*/
|
||||
}
|
||||
|
||||
// shadows
|
||||
|
30
graphics.cc
30
graphics.cc
@ -53,10 +53,9 @@ void Graphics::init(Level* level) {
|
||||
framebuffer->setDepthTexture(depthTexture);
|
||||
framebuffer->validate();
|
||||
|
||||
/*depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
|
||||
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {*/
|
||||
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(std::min(int(level->getLights()->size()), 1));
|
||||
for (unsigned int i = 0; i<1 && i<depth_cubeMaps.size(); i++) {
|
||||
// always generate and bind 32 cube maps, because otherwise the shader won't work
|
||||
depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(32);
|
||||
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {
|
||||
depth_cubeMaps.at(i) = SharedTextureCubeMap(new TextureCubeMap(glm::vec2(cube_size, cube_size), GL_DEPTH_COMPONENT24));
|
||||
depth_cubeMaps.at(i)->setMinFilter(GL_NEAREST);
|
||||
depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST);
|
||||
@ -69,6 +68,17 @@ void Graphics::init(Level* level) {
|
||||
|
||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
|
||||
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
|
||||
|
||||
lightingShader->use();
|
||||
|
||||
lightingShader->setTexture("shadowMap", depthTexture, 1);
|
||||
|
||||
if (level->getLights()->size() > 0) {
|
||||
for(unsigned int i = 0; i<32; i++){
|
||||
// start with texture unit 2 because the first two are used by the texture and the directional shadow map
|
||||
lightingShader->setTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glm::uvec2 Graphics::getWindowSize() {
|
||||
@ -89,8 +99,7 @@ void Graphics::render(double time)
|
||||
glm::vec3(0.0f, 0.0f, -1.0f),glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, -1.0f, 0.0f)};
|
||||
|
||||
framebuffer_cube->bind();
|
||||
//for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
|
||||
for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) {
|
||||
for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
|
||||
// render each side of the cube
|
||||
for (int i_face = 0; i_face<6; i_face++) {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0);
|
||||
@ -126,13 +135,6 @@ void Graphics::render(double time)
|
||||
|
||||
lightingShader->use();
|
||||
|
||||
if (level->getLights()->size() > 0) {
|
||||
glActiveTexture(GL_TEXTURE0+2);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, depth_cubeMaps.at(0)->getObjectName());
|
||||
GLint textureUnits[1] = {2};
|
||||
glUniform1iv(lightingShader->getUniformLocation("shadowMap_cube"), 1, textureUnits);
|
||||
}
|
||||
|
||||
//set lighting parameters
|
||||
|
||||
// TODO look into doing this less often, offload to another thread?
|
||||
@ -153,8 +155,6 @@ void Graphics::render(double time)
|
||||
);
|
||||
glm::mat4 depthBiasVP = biasMatrix*depthViewProjectionMatrix;
|
||||
|
||||
lightingShader->setTexture("shadowMap", depthTexture, 1);
|
||||
|
||||
lightingShader->setUniform("farPlane", farPlane);
|
||||
|
||||
// set fog Parameters
|
||||
|
Loading…
Reference in New Issue
Block a user