fixed window resize issue
This commit is contained in:
parent
816d346cb7
commit
ce6f718b27
@ -5,6 +5,7 @@ in vec2 TexCoords;
|
||||
|
||||
uniform sampler2D image;
|
||||
|
||||
uniform int count;
|
||||
uniform bool horizontal;
|
||||
uniform float weight[5] = float[] (0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
|
||||
|
||||
@ -14,7 +15,7 @@ void main()
|
||||
vec3 result = texture(image, TexCoords).rgb * weight[0];
|
||||
if(horizontal)
|
||||
{
|
||||
for(int i = 1; i < 5; ++i)
|
||||
for(int i = 1; i < count; ++i)
|
||||
{
|
||||
result += texture(image, TexCoords + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
|
||||
result += texture(image, TexCoords - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
|
||||
|
@ -211,10 +211,10 @@ void main() {
|
||||
|
||||
|
||||
float brightness = dot(mixedColor, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness > 1.0)
|
||||
if(brightness > 1.5)
|
||||
BrightColor = vec4(mixedColor, 1.0);
|
||||
else
|
||||
BrightColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
BrightColor = vec4(0.5, 0.5, 0.5, 1.0);
|
||||
|
||||
outColor = vec4(mixedColor, 1.0);
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ GLuint programTex;
|
||||
GLuint programPbr;
|
||||
GLuint programSun;
|
||||
GLuint programSkyBox;
|
||||
//GLuint programBloom;
|
||||
GLuint programBloomFinal;
|
||||
GLuint programBlur;
|
||||
|
||||
@ -81,7 +80,9 @@ int HDR_WIDTH;
|
||||
int HDR_HEIGHT;
|
||||
|
||||
bool bloom = true;
|
||||
float exposure = 1.5f;
|
||||
float bloom_exposure = 1.f;
|
||||
int blur_count = 1;
|
||||
|
||||
float lightPower = 8.f;
|
||||
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||
|
||||
@ -158,7 +159,7 @@ void renderQuad()
|
||||
}
|
||||
|
||||
void initHDR(GLFWwindow* window) {
|
||||
glfwGetFramebufferSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||
glfwGetWindowSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||
glGenFramebuffers(1, &hdrFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||
// create 2 floating point color buffers (1 for normal rendering, other for brightness threshold values)
|
||||
@ -178,7 +179,7 @@ void initHDR(GLFWwindow* window) {
|
||||
|
||||
void initRBO(GLFWwindow* window) {
|
||||
|
||||
glfwGetFramebufferSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||
glfwGetWindowSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||
glGenRenderbuffers(1, &rboDepth);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, rboDepth);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, HDR_WIDTH, HDR_HEIGHT);
|
||||
@ -192,8 +193,8 @@ void initRBO(GLFWwindow* window) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
void blurPingPong() {
|
||||
|
||||
void blurPingPong(GLFWwindow* window) {
|
||||
glfwGetWindowSize(window, &HDR_WIDTH, &HDR_HEIGHT);
|
||||
glGenFramebuffers(2, pingpongFBO);
|
||||
glGenTextures(2, pingpongColorbuffers);
|
||||
for (unsigned int i = 0; i < 2; i++)
|
||||
@ -316,6 +317,7 @@ void drawPlanetBlur() {
|
||||
bool horizontal = true, first_iteration = true;
|
||||
unsigned int amount = 10;
|
||||
glUseProgram(programBlur);
|
||||
glUniform1i(glGetUniformLocation(programBlur, "count"), blur_count);
|
||||
for (unsigned int i = 0; i < amount; i++)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
|
||||
@ -337,7 +339,7 @@ void drawPlanetBlur() {
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, pingpongColorbuffers[!horizontal]);
|
||||
glUniform1i(glGetUniformLocation(programBloomFinal, "bloom"), bloom);
|
||||
glUniform1f(glGetUniformLocation(programBloomFinal, "exposure"), exposure);
|
||||
glUniform1f(glGetUniformLocation(programBloomFinal, "exposure"), bloom_exposure);
|
||||
renderQuad();
|
||||
}
|
||||
|
||||
@ -379,6 +381,10 @@ void renderScene(GLFWwindow* window) {
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||
aspectRatio = float(width) / float(height);
|
||||
|
||||
initHDR(window);
|
||||
initRBO(window);
|
||||
blurPingPong(window);
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
@ -416,8 +422,12 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
||||
if (key == GLFW_KEY_P && action == GLFW_PRESS)
|
||||
lightingCheck = !lightingCheck;
|
||||
|
||||
if (key == GLFW_KEY_B && action == GLFW_PRESS)
|
||||
bloom = !bloom;
|
||||
if (key == GLFW_KEY_B && action == GLFW_PRESS) {
|
||||
blur_count++;
|
||||
if (blur_count > 5)
|
||||
blur_count = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//obsluga wejscia
|
||||
@ -487,7 +497,8 @@ void processInput(GLFWwindow* window)
|
||||
|
||||
void init(GLFWwindow* window) {
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
initHDR(window);
|
||||
initRBO(window);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
|
||||
@ -509,9 +520,7 @@ void init(GLFWwindow* window) {
|
||||
|
||||
skyBoxTex = Core::LoadSkyBox(skyBoxPaths);
|
||||
|
||||
initHDR(window);
|
||||
initRBO(window);
|
||||
blurPingPong();
|
||||
blurPingPong(window);
|
||||
|
||||
shaderBloomConfig();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user