połączenie pbr z tonemappingiem i dodanie możliwości zmiany chropowatości i metaliczności

This commit is contained in:
K4RP4T 2024-01-26 22:40:06 +01:00
parent 704b4d87be
commit 1a4986df7b
8 changed files with 62 additions and 74 deletions

View File

@ -1,14 +1,12 @@
#version 430 core
//float AMBIENT = 0.03f;
float AMBIENT = 0.1f;
float AMBIENT = 0.25f;
float PI = 3.14159f;
uniform sampler2D depthMap;
uniform vec3 cameraPos;
//uniform vec3 color;
uniform sampler2D colorTexture;
uniform vec3 sunDir;
@ -17,11 +15,6 @@ uniform vec3 sunColor;
uniform vec3 lightPos;
uniform vec3 lightColor;
//uniform vec3 spotlightPos;
//uniform vec3 spotlightColor;
//uniform vec3 spotlightConeDir;
//uniform vec3 spotlightPhi;
uniform float metallic;
uniform float roughness;
@ -35,11 +28,8 @@ out vec4 outColor;
in vec3 viewDirTS;
in vec3 lightDirTS;
//in vec3 spotlightDirTS;
in vec3 sunDirTS;
//in vec3 test;
float DistributionGGX(vec3 normal, vec3 H, float roughness)
{
float a = roughness * roughness;
@ -84,7 +74,6 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 color)
{
float diffuse = max(0, dot(normal, lightDir));
//vec3 V = normalize(cameraPos - worldPos);
vec3 F0 = vec3(0.04);
F0 = mix(F0, color, metallic);
@ -108,37 +97,36 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 color)
return (kD * color / PI + specular) * radiance * NdotL;
}
vec3 toneMapping(vec3 color)
{
float exposure = 0.03;
vec3 mapped = 1 - exp(-color * exposure);
return mapped;
}
void main()
{
//vec3 normal = vec3(0,0,1);
vec3 normal = normalize(vecNormal);
//vec3 viewDir = normalize(viewDirTS);
vec3 viewDir = normalize(cameraPos - worldPos);
//vec3 lightDir = normalize(lightDirTS);
vec3 lightDir = normalize(lightPos - worldPos);
vec4 textureColor = texture2D(colorTexture, vtc);
vec3 ambient = AMBIENT * vec3(textureColor);
float diffuse = max(0, dot(normal, lightDir));
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 300;
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
//gamma correction
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
vec3 ambient = AMBIENT * toneMappedColor;
vec3 attenuatedLightColor = lightColor / pow(length(lightPos - worldPos), 2);
vec3 illumination;
illumination = ambient + PBRLight(lightDir, attenuatedLightColor, normal, viewDir, vec3(textureColor));
//flashlight
//vec3 spotlightDir = normalize(spotlightDirTS);
//vec3 spotlightDir = normalize(spotlightPos -worldPos);
//float angleAttenuation = clamp((dot(-normalize(spotlightPos - worldPos), spotlightConeDir) - 0.5) * 3, 0, 1);
//attenuatedLightColor = angleAttenuation * spotlightColor / pow(length(spotlightPos - worldPos), 2);
//illumination = illumination + PBRLight(spotlightDir, attenuatedLightColor, normal, viewDir, vec3(textureColor));
illumination = ambient + PBRLight(lightDir, attenuatedLightColor, normal, viewDir, toneMappedColor);
//sun
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, vec3(textureColor));
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, toneMappedColor);
outColor = vec4(vec3(1.0) - exp(-illumination * exposition * 0.01f), 1);
//outColor = vec4(roughness, metallic, 0, 1);
//outColor = vec4(test);
outColor = vec4(vec3(1.0) - exp(-illumination * exposition), 1);
}

View File

@ -14,13 +14,11 @@ out vec3 worldPos;
out vec2 vtc;
uniform vec3 lightPos;
//uniform vec3 spotlightPos;
uniform vec3 cameraPos;
uniform vec3 sunDir;
out vec3 viewDirTS;
out vec3 lightDirTS;
//out vec3 spotlightDirTS;
out vec3 sunDirTS;
void main()
@ -39,7 +37,5 @@ void main()
viewDirTS = TBN * V;
vec3 L = normalize(lightPos - worldPos);
lightDirTS = TBN * L;
//vec3 SL = normalize(spotlightPos - worldPos);
//spotlightDirTS = TBN * SL;
sunDirTS = TBN * sunDir;
}

View File

@ -10,5 +10,5 @@ out vec4 out_color;
void main()
{
vec4 textureColor = texture(skybox, texCoord);
out_color = vec4(vec3(textureColor) * lightColor * 0.03f, 1.0f);
out_color = vec4(vec3(textureColor) * lightColor * 0.3f, 1.0f);
}

View File

@ -16,5 +16,5 @@ uniform sampler2D colorTexture;
void main()
{
vec4 textureColor = texture2D(colorTexture, vtc);
outColor = vec4(vec3(textureColor) * lightColor * 0.015f, 1.0);
outColor = vec4(vec3(textureColor) * lightColor * 0.15f, 1.0);
}

View File

@ -15,9 +15,10 @@ out vec4 outColor;
vec3 outputColor;
uniform sampler2D colorTexture;
vec3 toneMapping(vec3 color) {
vec3 toneMapping(vec3 color)
{
float exposure = 0.06;
vec3 mapped = 1 - exp(-color*exposure);
vec3 mapped = 1 - exp(-color * exposure);
return mapped;
}
@ -27,6 +28,7 @@ void main()
vec3 normal = normalize(vecNormal);
float diffuse = max(0, dot(normal, lightDir));
textureColor = texture2D(colorTexture, vtc);
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 200;
outputColor = vec3(textureColor) * min(1, AMBIENT + diffuse) * distance;

View File

@ -79,8 +79,8 @@ GLuint planetTex;
glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f);
float planetSize = 0.005f;
float planetRot = 0.f;
float planetRough = 0.4f;
float planetMetal = 0.4f;
float planetRough = 0.5f;
float planetMetal = 0.5f;
const char* const sunTexPaths[] = { "./textures/suns/sol.jpg", "./textures/suns/orange.jpg", "./textures/suns/lava.png", "./textures/suns/star.png", "./textures/suns/sun.jpg" };
int sunTexIndex = 20;
@ -112,7 +112,7 @@ unsigned int depthMapFBO;
int HDR_WIDTH = 1024;
int HDR_HEIGHT = 1024;
float lightPower = 100.f;
float lightPower = 10.f;
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
glm::mat4 createCameraMatrix() {
@ -193,7 +193,6 @@ void initDepthMap() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void drawPlanet(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
glUseProgram(programTex);
Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
@ -245,8 +244,6 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform1f(glGetUniformLocation(programPbr, "roughness"), roughness);
glUniform1f(glGetUniformLocation(programPbr, "metallic"), metallic);
//glUniform3f(glGetUniformLocation(programPbr, "color"), color.x, color.y, color.z);
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
glUniform3f(glGetUniformLocation(programPbr, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
@ -255,10 +252,6 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUniform3f(glGetUniformLocation(programPbr, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
glUniform3f(glGetUniformLocation(programPbr, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
//glUniform3f(glGetUniformLocation(programPbr, "spotlightConeDir"), spotlightConeDir.x, spotlightConeDir.y, spotlightConeDir.z);
//glUniform3f(glGetUniformLocation(programPbr, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
//glUniform3f(glGetUniformLocation(programPbr, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
//glUniform1f(glGetUniformLocation(programPbr, "spotlightPhi"), spotlightPhi);
Core::DrawContext(context);
glUseProgram(0);
}
@ -399,15 +392,31 @@ void processInput(GLFWwindow* window)
Sleep(200);
}
//siła światła
float powerSpeed = 1.f;
//jasność
float powerSpeed = 0.05f;
if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS && lightPower < 300.f)
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 25.f)
lightPower += powerSpeed;
if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS && lightPower > 10.f)
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.5f)
lightPower -= powerSpeed;
lightColor = glm::vec3(lightPower, lightPower, lightPower);
//chropowatość
float roughSpeed = 0.002f;
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS && planetRough < 1.f)
planetRough += roughSpeed;
if (glfwGetKey(window, GLFW_KEY_4) == GLFW_PRESS && planetRough > 0.f)
planetRough -= roughSpeed;
//metaliczność
float metalSpeed = 0.002f;
if (glfwGetKey(window, GLFW_KEY_5) == GLFW_PRESS && planetMetal < 1.f)
planetMetal += metalSpeed;
if (glfwGetKey(window, GLFW_KEY_6) == GLFW_PRESS && planetMetal > 0.f)
planetMetal -= metalSpeed;
}
// funkcja jest glowna petla

View File

@ -28,6 +28,6 @@ UP/DOWN - wielkość planety
LEFT/RIGHT - obrót planety
T/Y - tekstura planety
U/I - tekstura słońca
O/P - siła światła
1/2 - jasność
3/4 - chropowatość
5/6 - metaliczność

View File

@ -1,15 +1,8 @@
na 22.01.2024
na 29.01.2024
https://andkok.faculty.wmi.amu.edu.pl/grk/
Oliwia:
- znaleźć tekstury (done)
- perlin noise - poczytać i spróbować coś zrobić
Kacper:
- skybox
- przyciski funkcyjne (done)
Natalia:
- Bloom
- jak zostanie skończone, to perlin noise
Do zrobienia:
- pbr (done)
- bloom
- perlin noise