Reintroduced night texture. Throw a bunch of stuff out.
This commit is contained in:
parent
d24e70dbdd
commit
e02d223574
@ -7,44 +7,21 @@ in vec4 sunPosition;
|
|||||||
out vec4 oColor;
|
out vec4 oColor;
|
||||||
|
|
||||||
uniform sampler2D uTexture;
|
uniform sampler2D uTexture;
|
||||||
|
uniform sampler2D nightTexture;
|
||||||
uniform float farPlane;
|
uniform float farPlane;
|
||||||
uniform vec4 fogColor;
|
uniform vec4 fogColor;
|
||||||
uniform vec3 cameraCenter;
|
uniform vec3 cameraCenter;
|
||||||
uniform vec3 sunColor;
|
uniform vec3 sunColor;
|
||||||
uniform vec3 directionalVector;
|
uniform vec3 directionalVector;
|
||||||
uniform float skydomeSize;
|
|
||||||
|
|
||||||
const float sunSize = 20.0;
|
const float sunSize = 20.0;
|
||||||
const float starSize = 1.0;
|
|
||||||
const vec4 starColor = vec4(1.0, 1.0, 0.9, 1.0);
|
|
||||||
|
|
||||||
const int starCount = 2;
|
|
||||||
vec3 starPositions[starCount] = vec3[](
|
|
||||||
vec3(-0.3102524288591748, 0.9505037096381865, -0.016915328877346533),
|
|
||||||
vec3(-0.14085574439428544, 0.9519584459035886, -0.27190950065041153)
|
|
||||||
);
|
|
||||||
|
|
||||||
float starSizes[starCount] = float[] (
|
|
||||||
float(0.5),
|
|
||||||
float(1.2)
|
|
||||||
);
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0);
|
vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.0));
|
float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.0));
|
||||||
vec4 dayColor = texture(uTexture, vTexCoord);
|
vec4 dayColor = texture(uTexture, vTexCoord);
|
||||||
if (sunAngle >= 0.0) {
|
if (sunAngle >= 0.0) {
|
||||||
vec4 nightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle);
|
||||||
for(int i = 0; i<starCount; i++) {
|
|
||||||
vec3 starPosition = (starPositions[i] * skydomeSize) + vec3(cameraCenter.x, 0.0, cameraCenter.z);
|
|
||||||
float distanceToStar = distance(starPosition, vec3(fragPosition));
|
|
||||||
float thisStarSize = starSize * starSizes[i];
|
|
||||||
if (distanceToStar < thisStarSize) {
|
|
||||||
float starIntensity = clamp(0.3*exp(1/(distanceToStar/thisStarSize))-exp(1.0)*0.3, 0.0, 1.0);
|
|
||||||
nightColor = mix(nightColor, starColor, starIntensity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
textureColor = mix(dayColor, nightColor, sunAngle);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
textureColor = dayColor;
|
textureColor = dayColor;
|
||||||
|
42
graphics.cc
42
graphics.cc
@ -90,20 +90,14 @@ void Graphics::init(Level* level) {
|
|||||||
flameShader = ShaderProgramCreator("flame")
|
flameShader = ShaderProgramCreator("flame")
|
||||||
.attributeLocations(flame_positions->getAttributeLocations()).create();
|
.attributeLocations(flame_positions->getAttributeLocations()).create();
|
||||||
|
|
||||||
flameColorShader = ShaderProgramCreator("flame_color")
|
|
||||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
|
||||||
|
|
||||||
flamePostShader = ShaderProgramCreator("flame_post")
|
flamePostShader = ShaderProgramCreator("flame_post")
|
||||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
||||||
|
|
||||||
mergeShader = ShaderProgramCreator("merge")
|
|
||||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
|
||||||
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
|
printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
|
||||||
// Exit if we need more texture units
|
// Exit if we need more texture units
|
||||||
if (number_of_texture_units < 18) {
|
if (number_of_texture_units < 16) {
|
||||||
printf("You need at least 18 texture units to run this application. Exiting\n");
|
printf("You need at least 16 texture units to run this application. Exiting\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,23 +167,8 @@ void Graphics::init(Level* level) {
|
|||||||
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
|
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
|
||||||
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
|
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
|
||||||
|
|
||||||
flame_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8));
|
skydomeShader->use();
|
||||||
flame_fbo_color_texture->setMinFilter(GL_NEAREST);
|
skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), 15);
|
||||||
flame_fbo_color_texture->setMagFilter(GL_NEAREST);
|
|
||||||
flame_fbo_color_texture->setWrapS(GL_CLAMP_TO_BORDER);
|
|
||||||
flame_fbo_color_texture->setWrapT(GL_CLAMP_TO_BORDER);
|
|
||||||
framebuffer_flame = SharedFrameBufferObject(new FrameBufferObject());
|
|
||||||
framebuffer_flame->attachColorTexture("oColor", flame_fbo_color_texture);
|
|
||||||
framebuffer_flame->setDepthTexture(light_fbo_depth_texture);
|
|
||||||
framebuffer_flame->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
|
|
||||||
framebuffer_flame->validate();
|
|
||||||
|
|
||||||
mergeShader->use();
|
|
||||||
mergeShader->setTexture("flame_fbo", flame_fbo_color_texture, 15);
|
|
||||||
mergeShader->setTexture("light_fbo", light_fbo_color_texture, 16);
|
|
||||||
|
|
||||||
flameColorShader->use();
|
|
||||||
flameColorShader->setTexture("flame_fbo", flame_fbo_color_texture, 17);
|
|
||||||
|
|
||||||
updateClosestLights();
|
updateClosestLights();
|
||||||
}
|
}
|
||||||
@ -322,8 +301,6 @@ void Graphics::render(double time)
|
|||||||
|
|
||||||
// draw flames on top
|
// draw flames on top
|
||||||
flameShader->use();
|
flameShader->use();
|
||||||
framebuffer_flame->bind();
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
// cull faces to get consistent color while using alpha
|
// cull faces to get consistent color while using alpha
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
@ -345,17 +322,6 @@ void Graphics::render(double time)
|
|||||||
flame_positions->render();
|
flame_positions->render();
|
||||||
glDisable(GL_CULL_FACE);
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
flameColorShader->use();
|
|
||||||
fullscreen_quad->render();
|
|
||||||
|
|
||||||
framebuffer_light->bind();
|
|
||||||
mergeShader->use();
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
|
||||||
fullscreen_quad->render();
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
|
|
||||||
// draw slightly larger only for stencil buffer to blur edges
|
// draw slightly larger only for stencil buffer to blur edges
|
||||||
flameShader->use();
|
flameShader->use();
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
@ -35,16 +35,12 @@ class Graphics {
|
|||||||
SharedShaderProgram depthCubeShader;
|
SharedShaderProgram depthCubeShader;
|
||||||
SharedShaderProgram depthShader;
|
SharedShaderProgram depthShader;
|
||||||
SharedShaderProgram flameShader;
|
SharedShaderProgram flameShader;
|
||||||
SharedShaderProgram flameColorShader;
|
|
||||||
SharedShaderProgram flamePostShader;
|
SharedShaderProgram flamePostShader;
|
||||||
SharedShaderProgram mergeShader;
|
|
||||||
std::vector<SharedTexture2D> depth_directionalMaps;
|
std::vector<SharedTexture2D> depth_directionalMaps;
|
||||||
std::vector<SharedFrameBufferObject> framebuffer_directional;
|
std::vector<SharedFrameBufferObject> framebuffer_directional;
|
||||||
std::vector<SharedTextureCubeMap> depth_cubeMaps;
|
std::vector<SharedTextureCubeMap> depth_cubeMaps;
|
||||||
SharedFrameBufferObject framebuffer_cube;
|
SharedFrameBufferObject framebuffer_cube;
|
||||||
SharedFrameBufferObject framebuffer_light;
|
SharedFrameBufferObject framebuffer_light;
|
||||||
SharedFrameBufferObject framebuffer_flame;
|
|
||||||
SharedTexture2D flame_fbo_color_texture;
|
|
||||||
SharedTexture2D light_fbo_color_texture;
|
SharedTexture2D light_fbo_color_texture;
|
||||||
SharedTexture2D light_fbo_depth_texture;
|
SharedTexture2D light_fbo_depth_texture;
|
||||||
SharedVertexArrayObject flame_positions;
|
SharedVertexArrayObject flame_positions;
|
||||||
|
Loading…
Reference in New Issue
Block a user