dodanie przełączania tonemappingu

This commit is contained in:
K4RP4T 2024-02-08 02:16:04 +01:00
parent 1fcde042d9
commit 77f42acbeb
5 changed files with 53 additions and 22 deletions

View File

@ -3,14 +3,14 @@ Pos=60,60
Size=400,400
[Window][Planet]
Pos=1,170
Size=327,229
Pos=1,195
Size=327,227
[Window][Sun]
Pos=1,400
Size=327,121
Pos=1,424
Size=327,122
[Window][General]
Pos=1,0
Size=327,169
Size=327,193

View File

@ -21,6 +21,7 @@ uniform vec3 lightPos;
uniform vec3 lightColor;
uniform bool atmosphereCheck;
uniform bool toneMappingCheck;
uniform float time;
@ -191,10 +192,17 @@ void main()
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
}
vec3 toneMappedColor;
if (toneMappingCheck)
{
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
vec3 toneMappedColor = toneMapping(textureColor * distance);
toneMappedColor = toneMapping(textureColor * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
}
else
toneMappedColor = textureColor;
vec3 ambient = AMBIENT * toneMappedColor;
vec3 attenuatedLightColor = lightColor / pow(length(lightPos - worldPos), 2);

View File

@ -8,6 +8,7 @@ uniform vec3 lightColor;
uniform vec3 cameraPos;
uniform bool glowCheck;
uniform bool toneMappingCheck;
uniform float time;
@ -120,10 +121,18 @@ void main()
else
mixedColor = textureColor * lightColor * 0.2f;
vec3 toneMappedColor;
if (toneMappingCheck)
{
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 100;
vec3 toneMappedColor = toneMapping(mixedColor * distance);
toneMappedColor = toneMapping(mixedColor * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
}
else
toneMappedColor = mixedColor;
vec3 finalColor = toneMappedColor;
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));

View File

@ -15,6 +15,7 @@ uniform vec3 lightColor;
uniform vec3 cameraPos;
uniform bool atmosphereCheck;
uniform bool toneMappingCheck;
uniform float time;
@ -113,19 +114,27 @@ void main()
}
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuse);
vec3 toneMappedColor;
if (toneMappingCheck)
{
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
vec3 toneMappedColor = toneMapping(diffuseColor * distance);
toneMappedColor = toneMapping(diffuseColor * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
}
else
toneMappedColor = diffuseColor;
vec3 finalColor = toneMappedColor;
vec3 finalColor;
if (atmosphereCheck)
{
vec3 noiseColor = noiseColor() * min(1, 20.0 * max(0.02, dot(normal, lightDir))) * lightColor * cloudBrightness;
finalColor = mix(toneMappedColor, noiseColor, noiseColor.r);
}
else
finalColor = toneMappedColor;
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));

View File

@ -65,6 +65,7 @@ bool glowCheck = false;
bool atmosphereCheck = false;
bool lightingCheck = false;
bool skyBoxCheck = false;
bool toneMappingCheck = false;
const char* skyBoxPaths[] = { "./textures/skybox/space_rt.png", "./textures/skybox/space_lf.png", "./textures/skybox/space_up.png", "./textures/skybox/space_dn.png",
"./textures/skybox/space_bk.png", "./textures/skybox/space_ft.png" };
@ -177,7 +178,9 @@ void showGUI() {
if (ImGui::Begin("General"))
{
ImGui::Checkbox("SkyBox", &skyBoxCheck);
ImGui::Checkbox("Sky Box", &skyBoxCheck);
ImGui::Checkbox("Tone Mapping", &toneMappingCheck);
ImGui::SliderInt("Bloom Level", &blur_count, 1, 5, "%d", ImGuiSliderFlags_AlwaysClamp);
ImGui::Checkbox("Lighting Model: ", &lightingCheck);
ImGui::SameLine();
@ -191,8 +194,6 @@ void showGUI() {
ImGui::SliderFloat("Exposure", &lightPower, 1.0f, 20.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
ImGui::SliderInt("Bloom Level", &blur_count, 1, 5, "%d", ImGuiSliderFlags_AlwaysClamp);
}ImGui::End();
if(ImGui::Begin("Planet"))
@ -343,6 +344,7 @@ void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform1f(glGetUniformLocation(programTex, "cloudBrightness"), cloudBrightness);
glUniform1i(glGetUniformLocation(programTex, "atmosphereCheck"), atmosphereCheck);
glUniform1i(glGetUniformLocation(programTex, "toneMappingCheck"), toneMappingCheck);
Core::DrawContext(context);
glUseProgram(0);
@ -375,6 +377,7 @@ void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform1f(glGetUniformLocation(programPbr, "cloudBrightness"), cloudBrightness);
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
glUniform1i(glGetUniformLocation(programPbr, "toneMappingCheck"), toneMappingCheck);
Core::DrawContext(context);
glUseProgram(0);
@ -393,9 +396,11 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform1i(glGetUniformLocation(programSun, "glowCheck"), glowCheck);
glUniform1f(glGetUniformLocation(programSun, "time"), glfwGetTime());
glUniform1i(glGetUniformLocation(programSun, "glowCheck"), glowCheck);
glUniform1i(glGetUniformLocation(programSun, "toneMappingCheck"), toneMappingCheck);
Core::DrawContext(context);
glUseProgram(0);
}