połączenie "parameters" z "master"
This commit is contained in:
commit
567c62a161
@ -52,6 +52,10 @@
|
||||
<ClInclude Include="src\Texture.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shaderBlur.frag" />
|
||||
<None Include="shaders\shaderBlur.vert" />
|
||||
<None Include="shaders\shader_bloom_final.frag" />
|
||||
<None Include="shaders\shader_bloom_final.vert" />
|
||||
<None Include="shaders\shader_pbr.frag" />
|
||||
<None Include="shaders\shader_pbr.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
|
@ -166,5 +166,17 @@
|
||||
<None Include="shaders\shader_pbr.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom_final.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom_final.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shaderBlur.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shaderBlur.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -2,6 +2,15 @@
|
||||
Pos=60,60
|
||||
Size=400,400
|
||||
|
||||
[Window][Menu]
|
||||
Pos=27,35
|
||||
Size=380,347
|
||||
[Window][Planet]
|
||||
Pos=1,217
|
||||
Size=327,227
|
||||
|
||||
[Window][Sun]
|
||||
Pos=1,445
|
||||
Size=327,118
|
||||
|
||||
[Window][General]
|
||||
Pos=1,0
|
||||
Size=327,216
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 330 core
|
||||
#version 430 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
@ -23,7 +23,7 @@ void main()
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 1; i < 5; ++i)
|
||||
for(int i = 1; i < count; ++i)
|
||||
{
|
||||
result += texture(image, TexCoords + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
|
||||
result += texture(image, TexCoords - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 330 core
|
||||
#version 430 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 330 core
|
||||
#version 430 core
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoords;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 330 core
|
||||
#version 430 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
layout (location = 1) in vec2 aTexCoords;
|
||||
|
||||
|
@ -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 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
|
||||
vec3 toneMappedColor = toneMapping(textureColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
vec3 toneMappedColor;
|
||||
|
||||
if (toneMappingCheck)
|
||||
{
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
|
||||
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);
|
||||
@ -203,21 +211,20 @@ void main()
|
||||
//sun
|
||||
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, toneMappedColor);
|
||||
|
||||
|
||||
|
||||
vec3 pbrColor = vec3(1.0) - exp(-illumination * exposition);
|
||||
|
||||
vec3 finalColor = pbrColor;
|
||||
vec3 finalColor;
|
||||
|
||||
if (atmosphereCheck)
|
||||
{
|
||||
vec3 noiseColor = noiseColor() * min(1, 20.0 * max(0.02, dot(normal, lightDir))) * lightColor * cloudBrightness;
|
||||
finalColor = mix(pbrColor, noiseColor, noiseColor.r);
|
||||
}
|
||||
else
|
||||
finalColor = pbrColor;
|
||||
|
||||
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));
|
||||
|
||||
|
||||
float brightness = dot(finalColor, vec3(0.2126, 0.7152, 0.0722));
|
||||
if(brightness > 0.2)
|
||||
BrightColor = vec4(finalColor, 1.0);
|
||||
else
|
||||
|
@ -7,7 +7,8 @@ uniform vec3 lightColor;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
uniform bool atmosphereCheck;
|
||||
uniform bool glowCheck;
|
||||
uniform bool toneMappingCheck;
|
||||
|
||||
uniform float time;
|
||||
|
||||
@ -19,8 +20,6 @@ in vec2 vtc;
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
vec4 noiseColor;
|
||||
|
||||
vec3 toneMapping(vec3 color)
|
||||
{
|
||||
float exposure = 0.06;
|
||||
@ -67,7 +66,7 @@ float fbm ( in vec2 _st) {
|
||||
return v;
|
||||
}
|
||||
|
||||
vec4 noiseTexture(float time) {
|
||||
vec3 noiseColor() {
|
||||
vec2 st = vtc.xy * 9.;
|
||||
vec3 color = vec3(0.0);
|
||||
|
||||
@ -93,7 +92,7 @@ vec4 noiseTexture(float time) {
|
||||
vec3(1.000,0.306,0.143),
|
||||
clamp(length(r.x),0.0,1.0));
|
||||
|
||||
noiseColor = vec4((f*f*f+1.384*f*f+1.044*f)*color,1.);
|
||||
vec3 noiseColor = vec3((f*f*f+1.384*f*f+1.044*f)*color);
|
||||
|
||||
return noiseColor;
|
||||
}
|
||||
@ -105,22 +104,36 @@ void main()
|
||||
|
||||
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
|
||||
|
||||
if (atmosphereCheck)
|
||||
if (glowCheck)
|
||||
{
|
||||
float atmosphereDot = dot(normal, viewDir);
|
||||
vec3 atmosphereColor = vec3(1.0, 0.08, 0.02);
|
||||
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 2));
|
||||
float glowDot = dot(normal, viewDir);
|
||||
vec3 glowColor = vec3(1.0, 0.08, 0.02);
|
||||
textureColor = mix(textureColor, glowColor, pow(1 - glowDot, 2));
|
||||
}
|
||||
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 15;
|
||||
vec3 mixedColor;
|
||||
|
||||
vec4 textureNoise = noiseTexture(time);
|
||||
vec3 mixedTexture = mix(textureColor, textureNoise.rgb, 0.45f);
|
||||
if (glowCheck)
|
||||
{
|
||||
vec3 noiseColor = noiseColor();
|
||||
mixedColor = mix(textureColor, noiseColor, 0.35);
|
||||
}
|
||||
else
|
||||
mixedColor = textureColor * lightColor * 0.2f;
|
||||
|
||||
vec3 toneMappedColor = toneMapping(mixedTexture * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
vec3 finalColor = toneMappedColor * lightColor * 0.2f;
|
||||
vec3 toneMappedColor;
|
||||
|
||||
if (toneMappingCheck)
|
||||
{
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 100;
|
||||
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));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
|
||||
vec3 toneMappedColor = toneMapping(diffuseColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
if (toneMappingCheck)
|
||||
{
|
||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
|
||||
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));
|
||||
|
||||
|
@ -31,8 +31,8 @@ GLuint programTex;
|
||||
GLuint programPbr;
|
||||
GLuint programSun;
|
||||
GLuint programSkyBox;
|
||||
GLuint programBloomFinal;
|
||||
GLuint programBlur;
|
||||
GLuint programBloomFinal;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
@ -44,7 +44,7 @@ const char* const planetTexPaths[] = { "./textures/planets/mercury.png", "./text
|
||||
"./textures/planets/volcanic.png", "./textures/planets/desert.png", "./textures/planets/tropical.png", "./textures/planets/toxic.jpg", "./textures/planets/swamp.png",
|
||||
"./textures/planets/savannah.png", "./textures/planets/alpine.png", "./textures/planets/ceres.jpg", "./textures/planets/eris.jpg", "./textures/planets/haumea.jpg",
|
||||
"./textures/planets/makemake.jpg" };
|
||||
int planetTexIndex = 80;
|
||||
int planetTexIndex = 0;
|
||||
GLuint planetTex;
|
||||
|
||||
glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f);
|
||||
@ -54,15 +54,18 @@ float planetRough = 0.5f;
|
||||
float planetMetal = 0.5f;
|
||||
|
||||
const char* const sunTexPaths[] = { "./textures/suns/lava.png", "./textures/suns/sol.jpg", "./textures/suns/orange.jpg", "./textures/suns/star.png", "./textures/suns/sun.jpg" };
|
||||
int sunTexIndex = 20;
|
||||
int sunTexIndex = 0;
|
||||
GLuint sunTex;
|
||||
|
||||
glm::vec3 sunPos = glm::vec3(20.f, 0.f, 20.f);
|
||||
glm::vec3 sunDir = glm::vec3(1.f, 0.f, 1.f);
|
||||
float sunSize = 0.05f;
|
||||
|
||||
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" };
|
||||
@ -70,6 +73,7 @@ GLuint skyBoxTex;
|
||||
|
||||
glm::vec3 skyBoxPos = glm::vec3(0.f, 0.f, 0.f);
|
||||
float skyBoxSize = 3.f;
|
||||
float skyBoxRot = 0.f;
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(-2.f, 0.f, 0.f);
|
||||
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
|
||||
@ -83,7 +87,6 @@ unsigned int colorBuffers[2];
|
||||
|
||||
unsigned int rboDepth;
|
||||
|
||||
|
||||
unsigned int pingpongFBO[2];
|
||||
unsigned int pingpongColorbuffers[2];
|
||||
|
||||
@ -101,6 +104,8 @@ float cloudIntensity = 15.f;
|
||||
float cloudMotion = 0.f;
|
||||
float cloudBrightness = 0.08f;
|
||||
|
||||
float PI = 3.14159f;
|
||||
|
||||
glm::mat4 createCameraMatrix() {
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
|
||||
@ -124,7 +129,6 @@ glm::mat4 createPerspectiveMatrix() {
|
||||
float n = 0.01f;
|
||||
float f = 200.f;
|
||||
float fov = 105.f;
|
||||
float PI = 3.14159f;
|
||||
float S = 1 / (tan((fov / 2) * (PI / 180)));
|
||||
|
||||
perspectiveMatrix = glm::mat4({
|
||||
@ -168,36 +172,94 @@ void renderQuad()
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
||||
void showGUI() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui::Begin("Menu");
|
||||
ImGui::SliderFloat("Size", &planetSize, 0.001f, 0.01f);
|
||||
ImGui::SliderFloat("Rotation", &planetRot, -1.5f, 1.5f);
|
||||
ImGui::SliderFloat("Light Power", &lightPower, 0.01f, 20.0f);
|
||||
ImGui::SliderInt("Bloom", &blur_count, 0, 6);
|
||||
if (ImGui::Button("Texture", ImVec2(60, 20))) {
|
||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(++planetTexIndex % 20)]);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Sun", ImVec2(60, 20))) {
|
||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(++sunTexIndex % 5)]);
|
||||
}
|
||||
|
||||
ImGui::Text("PBR Settings");
|
||||
ImGui::Checkbox("Lighting Model", &lightingCheck);
|
||||
ImGui::SliderFloat("Metal", &planetMetal, 0.01f, 1.0f);
|
||||
ImGui::SliderFloat("Roughness", &planetRough, 0.01f, 1.0f);
|
||||
if (ImGui::Begin("General"))
|
||||
{
|
||||
ImGui::Checkbox("Sky Box", &skyBoxCheck);
|
||||
|
||||
ImGui::Text("Atmosphere Settings"); ImGui::Checkbox("Atmosphere", &atmosphereCheck);
|
||||
if (skyBoxCheck)
|
||||
ImGui::SliderFloat("Rotation", &skyBoxRot, 0.0f, 360.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
|
||||
ImGui::SliderFloat("Cloud Intensity", &cloudIntensity, 0.01f, 20.0f);
|
||||
ImGui::SliderFloat("Cloud Brightness", &cloudBrightness, 0.01f, 0.28f);
|
||||
ImGui::SliderFloat("Cloud Motion", &cloudMotion, 0.01f, 8.0f);
|
||||
ImGui::Checkbox("Tone Mapping", &toneMappingCheck);
|
||||
ImGui::SliderInt("Bloom Level", &blur_count, 1, 5, "%d", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::Checkbox("Lighting Model: ", &lightingCheck);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::End();
|
||||
if (lightingCheck) {
|
||||
ImGui::Text("PBR");
|
||||
ImGui::SliderFloat("Roughness", &planetRough, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::SliderFloat("Metallicity", &planetMetal, 0.0f, 1.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
else
|
||||
ImGui::Text("Diffuse");
|
||||
|
||||
ImGui::SliderFloat("Exposure", &lightPower, 1.0f, 20.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
|
||||
}ImGui::End();
|
||||
|
||||
if(ImGui::Begin("Planet"))
|
||||
{
|
||||
ImGui::Text("Texture");
|
||||
if (ImGui::Button("Prev", ImVec2(60, 20))) {
|
||||
--planetTexIndex;
|
||||
|
||||
if (planetTexIndex < 0)
|
||||
planetTexIndex = sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1;
|
||||
|
||||
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Next", ImVec2(60, 20))) {
|
||||
++planetTexIndex;
|
||||
|
||||
if (planetTexIndex > sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1)
|
||||
planetTexIndex = 0;
|
||||
|
||||
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("Size", &planetSize, 0.001f, 0.01f, "%.5f", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::SliderFloat("Rotation", &planetRot, -2.0f, 2.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
|
||||
ImGui::Checkbox("Atmosphere", &atmosphereCheck);
|
||||
if (atmosphereCheck) {
|
||||
ImGui::Text("Clouds");
|
||||
ImGui::SliderFloat("Intensity", &cloudIntensity, 0.0f, 100.0f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::SliderFloat("Brightness", &cloudBrightness, 0.0f, 0.20f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
ImGui::SliderFloat("Motion", &cloudMotion, -0.5f, 0.5f, "%.3f", ImGuiSliderFlags_AlwaysClamp);
|
||||
}
|
||||
}ImGui::End();
|
||||
|
||||
if (ImGui::Begin("Sun"))
|
||||
{
|
||||
ImGui::Text("Texture");
|
||||
if (ImGui::Button("Prev", ImVec2(60, 20))) {
|
||||
--sunTexIndex;
|
||||
|
||||
if (sunTexIndex < 0)
|
||||
sunTexIndex = sizeof(sunTexPaths) / sizeof(sunTexPaths[0]) - 1;
|
||||
|
||||
sunTex = Core::LoadTexture(sunTexPaths[sunTexIndex]);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Next", ImVec2(60, 20))) {
|
||||
++sunTexIndex;
|
||||
|
||||
if (sunTexIndex > sizeof(sunTexPaths) / sizeof(sunTexPaths[0]) - 1)
|
||||
sunTexIndex = 0;
|
||||
|
||||
sunTex = Core::LoadTexture(sunTexPaths[sunTexIndex]);
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("Size", &sunSize, 0.01f, 0.1f, "%.4f", ImGuiSliderFlags_AlwaysClamp);
|
||||
|
||||
ImGui::Checkbox("Glow", &glowCheck);
|
||||
|
||||
}ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
@ -287,6 +349,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);
|
||||
@ -319,6 +382,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);
|
||||
@ -337,9 +401,11 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
|
||||
|
||||
glUniform3f(glGetUniformLocation(programSun, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
glUniform1i(glGetUniformLocation(programSun, "atmosphereCheck"), atmosphereCheck);
|
||||
glUniform1f(glGetUniformLocation(programSun, "time"), glfwGetTime());
|
||||
|
||||
glUniform1i(glGetUniformLocation(programSun, "glowCheck"), glowCheck);
|
||||
glUniform1i(glGetUniformLocation(programSun, "toneMappingCheck"), toneMappingCheck);
|
||||
|
||||
Core::DrawContext(context);
|
||||
glUseProgram(0);
|
||||
}
|
||||
@ -358,12 +424,11 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint text
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void drawPlanetBlur() {
|
||||
void drawBlur() {
|
||||
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++)
|
||||
for (unsigned int i = 0; i < blur_count * 2; i++)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, pingpongFBO[horizontal]);
|
||||
glUniform1i(glGetUniformLocation(programBlur, "horizontal"), horizontal);
|
||||
@ -389,7 +454,7 @@ void drawPlanetBlur() {
|
||||
}
|
||||
|
||||
void renderScene(GLFWwindow* window) {
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClearColor(0.0f, 0.0f, 0.05f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
float time = glfwGetTime();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||
@ -407,25 +472,26 @@ void renderScene(GLFWwindow* window) {
|
||||
|
||||
//rysowanie słońca
|
||||
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
|
||||
glm::mat4 sunRotate = glm::rotate(PI, glm::vec3(0, 1, 0));
|
||||
glm::mat4 sunTranslate = glm::translate(sunPos);
|
||||
glm::mat4 sunRotate = glm::rotate(180.f, glm::vec3(0, 1, 0));
|
||||
|
||||
drawSun(sphereContext, sunTranslate * sunRotate * sunScale, sunTex);
|
||||
|
||||
//rysowanie skyboxa
|
||||
skyBoxPos = cameraPos;
|
||||
glm::mat4 skyBoxScale = glm::scale(glm::vec3(skyBoxSize));
|
||||
glm::mat4 skyBoxRotate = glm::rotate(glm::radians(skyBoxRot), glm::vec3(0, 1, 0));
|
||||
glm::mat4 skyBoxTranslate = glm::translate(skyBoxPos);
|
||||
|
||||
drawSkyBox(cubeContext, skyBoxTranslate * skyBoxScale, skyBoxTex);
|
||||
if (skyBoxCheck)
|
||||
drawSkyBox(cubeContext, skyBoxTranslate * skyBoxRotate * skyBoxScale, skyBoxTex);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
drawPlanetBlur();
|
||||
drawBlur();
|
||||
|
||||
showGUI();
|
||||
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
@ -453,16 +519,40 @@ void loadModelToContext(std::string path, Core::RenderContext& context) {
|
||||
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
//tekstura planety
|
||||
if (key == GLFW_KEY_T && action == GLFW_PRESS)
|
||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(++planetTexIndex % 20)]);
|
||||
if (key == GLFW_KEY_Y && action == GLFW_PRESS && planetTexIndex > 0)
|
||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(--planetTexIndex % 20)]);
|
||||
if (key == GLFW_KEY_T && action == GLFW_PRESS) {
|
||||
++planetTexIndex;
|
||||
|
||||
if (planetTexIndex > sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1)
|
||||
planetTexIndex = 0;
|
||||
|
||||
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
|
||||
}
|
||||
else if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
|
||||
--planetTexIndex;
|
||||
|
||||
if (planetTexIndex < 0)
|
||||
planetTexIndex = sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1;
|
||||
|
||||
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
|
||||
}
|
||||
|
||||
//tekstura słońca
|
||||
if (key == GLFW_KEY_U && action == GLFW_PRESS)
|
||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(++sunTexIndex % 5)]);
|
||||
if (key == GLFW_KEY_I && action == GLFW_PRESS && sunTexIndex > 0)
|
||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(--sunTexIndex % 5)]);
|
||||
if (key == GLFW_KEY_U && action == GLFW_PRESS) {
|
||||
++sunTexIndex;
|
||||
|
||||
if (sunTexIndex > sizeof(sunTexPaths) / sizeof(sunTexPaths[0]) - 1)
|
||||
sunTexIndex = 0;
|
||||
|
||||
sunTex = Core::LoadTexture(sunTexPaths[sunTexIndex]);
|
||||
}
|
||||
else if (key == GLFW_KEY_I && action == GLFW_PRESS) {
|
||||
--sunTexIndex;
|
||||
|
||||
if (sunTexIndex < 0)
|
||||
sunTexIndex = sizeof(sunTexPaths) / sizeof(sunTexPaths[0]) - 1;
|
||||
|
||||
sunTex = Core::LoadTexture(sunTexPaths[sunTexIndex]);
|
||||
}
|
||||
|
||||
//atmosfera
|
||||
if (key == GLFW_KEY_O && action == GLFW_PRESS)
|
||||
@ -472,12 +562,24 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
|
||||
if (key == GLFW_KEY_P && action == GLFW_PRESS)
|
||||
lightingCheck = !lightingCheck;
|
||||
|
||||
//poświata słońca
|
||||
if (key == GLFW_KEY_E && action == GLFW_PRESS)
|
||||
glowCheck = !glowCheck;
|
||||
|
||||
//skybox
|
||||
if (key == GLFW_KEY_Q && action == GLFW_PRESS)
|
||||
skyBoxCheck = !skyBoxCheck;
|
||||
|
||||
//tonemapping
|
||||
if (key == GLFW_KEY_F && action == GLFW_PRESS)
|
||||
toneMappingCheck = !toneMappingCheck;
|
||||
|
||||
//bloom
|
||||
if (key == GLFW_KEY_M && action == GLFW_PRESS) {
|
||||
blur_count++;
|
||||
if (blur_count > 5)
|
||||
blur_count = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//obsluga wejscia
|
||||
@ -513,17 +615,17 @@ void processInput(GLFWwindow* window)
|
||||
//obrót planety
|
||||
float rotationSpeed = 0.0025f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS && planetRot < 1.5f)
|
||||
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS && planetRot < 2.0f)
|
||||
planetRot += rotationSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.5f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -2.0f)
|
||||
planetRot -= rotationSpeed;
|
||||
|
||||
//jasność
|
||||
float powerSpeed = 0.05f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 16.f)
|
||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 20.f)
|
||||
lightPower += powerSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 1.f)
|
||||
lightPower -= powerSpeed;
|
||||
|
||||
lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||
@ -555,18 +657,32 @@ void processInput(GLFWwindow* window)
|
||||
//ruch chmur
|
||||
float motionSpeed = 0.0025f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS && cloudMotion < 1.5f)
|
||||
if (glfwGetKey(window, GLFW_KEY_V) == GLFW_PRESS && cloudMotion < 0.5f)
|
||||
cloudMotion += motionSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS && cloudMotion > -1.5f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_C) == GLFW_PRESS && cloudMotion > -0.5f)
|
||||
cloudMotion -= motionSpeed;
|
||||
|
||||
//jasność chmur
|
||||
float brightnessSpeed = 0.0005f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS && cloudBrightness < 0.16f)
|
||||
if (glfwGetKey(window, GLFW_KEY_N) == GLFW_PRESS && cloudBrightness < 0.2f)
|
||||
cloudBrightness += brightnessSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS && cloudBrightness > 0.02f)
|
||||
else if (glfwGetKey(window, GLFW_KEY_B) == GLFW_PRESS && cloudBrightness > 0.01f)
|
||||
cloudBrightness -= brightnessSpeed;
|
||||
|
||||
//wielkość słońca
|
||||
if (glfwGetKey(window, GLFW_KEY_7) == GLFW_PRESS && sunSize < 0.1f)
|
||||
sunSize += sizeSpeed * 10;
|
||||
else if (glfwGetKey(window, GLFW_KEY_8) == GLFW_PRESS && sunSize > 0.01f)
|
||||
sunSize -= sizeSpeed * 10;
|
||||
|
||||
//obrót skyboxa
|
||||
float rotSpeed = 1.0f;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_9) == GLFW_PRESS && skyBoxRot < 360.0f)
|
||||
skyBoxRot += rotSpeed;
|
||||
else if (glfwGetKey(window, GLFW_KEY_0) == GLFW_PRESS && skyBoxRot > 0.0f)
|
||||
skyBoxRot -= rotSpeed;
|
||||
}
|
||||
|
||||
void init(GLFWwindow* window) {
|
||||
@ -580,11 +696,9 @@ void init(GLFWwindow* window) {
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
ImGui_ImplOpenGL3_Init("#version 430");
|
||||
ImGui::StyleColorsDark;
|
||||
|
||||
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
@ -612,6 +726,8 @@ void shutdown(GLFWwindow* window) {
|
||||
shaderLoader.DeleteProgram(programPbr);
|
||||
shaderLoader.DeleteProgram(programSun);
|
||||
shaderLoader.DeleteProgram(programSkyBox);
|
||||
shaderLoader.DeleteProgram(programBlur);
|
||||
shaderLoader.DeleteProgram(programBloomFinal);
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
Loading…
Reference in New Issue
Block a user