diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index 9aa76e6..7d3f4e2 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -7,24 +7,36 @@ in vec4 sunPosition; out vec4 oColor; uniform sampler2D uTexture; +uniform sampler2D nightTexture; uniform float farPlane; uniform vec4 fogColor; uniform vec3 cameraCenter; uniform vec3 sunColor; +uniform vec3 directionalVector; const float sunSize = 40.0; void main() { + vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0); + float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.0)); + vec4 dayColor = texture(uTexture, vTexCoord); + if (sunAngle >= 0.0) { + textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle); + textureColor = mix(vec4(0.0, 0.0, 0.0, 1.0), textureColor, 1.0 - sunAngle); + } + else { + textureColor = dayColor; + } float distanceToSun = length(sunPosition - fragPosition); float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition)); float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0); fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0); if (distanceToSun < sunSize) { float sunIntensity = clamp(0.3*exp(1/(distanceToSun/sunSize))-exp(1.0)*0.3, 0.0, 1.0); - vec4 color = mix(vec4(texture(uTexture, vTexCoord)), vec4(sunColor, sunIntensity), sunIntensity); + vec4 color = mix(textureColor, vec4(sunColor, sunIntensity), sunIntensity); oColor = mix(color, fogColor, fogFactor); } else { - oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor); + oColor = mix(textureColor, fogColor, fogFactor); } } diff --git a/graphics.cc b/graphics.cc index 53b889d..966dc2b 100644 --- a/graphics.cc +++ b/graphics.cc @@ -95,8 +95,8 @@ 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); // Exit if we need more texture units - if (number_of_texture_units < 15) { - printf("You need at least 15 texture units to run this application. Exiting\n"); + if (number_of_texture_units < 16) { + printf("You need at least 16 texture units to run this application. Exiting\n"); exit(-1); } @@ -162,10 +162,13 @@ void Graphics::init(Level* level) { framebuffer_light->validate(); flamePostShader->use(); - flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 15); + flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 14); flamePostShader->setUniform("windowSizeX", int(windowSize.x)); flamePostShader->setUniform("windowSizeY", int(windowSize.y)); + skydomeShader->use(); + skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), 15); + updateClosestLights(); }