połączenie "normalne" z "master"

This commit is contained in:
K4RP4T 2024-02-08 03:02:16 +01:00
commit 80225d9b74
49 changed files with 70 additions and 13 deletions

View File

@ -7,6 +7,7 @@ float AMBIENT = 0.05;
float PI = 3.14159;
uniform sampler2D colorTexture;
uniform sampler2D textureNormal;
uniform float exposition;
uniform float metallic;
@ -184,6 +185,11 @@ void main()
vec3 lightDir = normalize(lightPos - worldPos);
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
vec3 N = texture2D(textureNormal, vtc).rgb;
vec3 normalTexture = normalize((N * 2.0 - 1.0));
float diffuseNormal = max(0, dot(normalTexture, lightDir));
if (atmosphereCheck)
{
@ -192,12 +198,13 @@ void main()
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
}
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuseNormal);
vec3 toneMappedColor;
if (toneMappingCheck)
{
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
toneMappedColor = toneMapping(textureColor * distance);
toneMappedColor = toneMapping(diffuseColor * distance);
//gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
}

View File

@ -7,6 +7,7 @@ float AMBIENT = 0.05;
float PI = 3.14159;
uniform sampler2D colorTexture;
uniform sampler2D textureNormal;
uniform vec3 color;
uniform vec3 lightPos;
@ -27,6 +28,10 @@ in vec3 vecNormal;
in vec3 worldPos;
in vec2 vtc;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 sunDirTS;
//out vec4 outColor;
vec3 toneMapping(vec3 color)
@ -105,6 +110,11 @@ void main()
float diffuse = max(0, dot(normal, lightDir));
vec3 textureColor = texture2D(colorTexture, vtc).rgb;
vec3 N = texture2D(textureNormal, vtc).rgb;
vec3 normalTexture = normalize((N * 2.0 - 1.0));
float diffuseNormal = max(0, dot(normalTexture, lightDir));
if (atmosphereCheck)
{
@ -113,7 +123,7 @@ void main()
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
}
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuse);
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuse) * min(1, AMBIENT + diffuseNormal);
vec3 toneMappedColor;
if (toneMappingCheck)
@ -145,4 +155,5 @@ void main()
outColor = vec4(finalColor, 1.0);
}

View File

@ -3,6 +3,8 @@
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation;
uniform mat4 modelMatrix;
@ -11,11 +13,30 @@ out vec3 vecNormal;
out vec3 worldPos;
out vec2 vtc;
uniform vec3 lightPos;
uniform vec3 cameraPos;
uniform vec3 sunDir;
out vec3 viewDirTS;
out vec3 lightDirTS;
out vec3 sunDirTS;
void main()
{
worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz;
vecNormal = (modelMatrix * vec4(vertexNormal, 0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0);
vtc = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y);
vec3 w_tangent = normalize(mat3(modelMatrix) * vertexTangent);
vec3 w_bitangent = normalize(mat3(modelMatrix) * vertexBitangent);
mat3 TBN = transpose(mat3(w_tangent, w_bitangent, vecNormal));
vec3 V = normalize(cameraPos - worldPos);
viewDirTS = TBN * V;
vec3 L = normalize(lightPos - worldPos);
lightDirTS = TBN * L;
sunDirTS = TBN * sunDir;
}

View File

@ -39,14 +39,22 @@ Core::Shader_Loader shaderLoader;
Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
const char* const planetTexPaths[] = { "./textures/planets/mercury.png", "./textures/planets/venus.jpg", "./textures/planets/earth.jpg", "./textures/planets/mars.jpg",
"./textures/planets/jupiter.jpg", "./textures/planets/saturn.jpg", "./textures/planets/uranus.jpg", "./textures/planets/neptune.jpg", "./textures/planets/icy.png",
"./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" };
const char* const planetTexPaths[] = { "./textures/planets/ceres.jpg", "./textures/planets/desert.png", "./textures/planets/dirty.png", "./textures/planets/earth.jpg", "./textures/planets/eris.jpg",
"./textures/planets/haumea.jpg", "./textures/planets/Icy.png", "./textures/planets/jupiter.jpg", "./textures/planets/kora.png", "./textures/planets/makemake.jpg", "./textures/planets/mars.jpg",
"./textures/planets/mchowa.png", "./textures/planets/mercury.png", "./textures/planets/neptune.jpg", "./textures/planets/saturn.jpg", "./textures/planets/Savannah.png",
"./textures/planets/snow-foot.png", "./textures/planets/Swamp.png", "./textures/planets/Tropical.png", "./textures/planets/uranus.jpg",
"./textures/planets/venus.jpg", "./textures/planets/Volcanic.png", "./textures/planets/watermelon.png", "./textures/planets/wood.png" };
int planetTexIndex = 0;
GLuint planetTex;
const char* const normalTexPaths[] = { "./textures/planets/normalne/ceres.png", "./textures/planets/normalne/desert.png", "./textures/planets/normalne/dirty.png", "./textures/planets/normalne/earth_normalmap.png",
"./textures/planets/normalne/eris.png", "./textures/planets/normalne/haumea.png", "./textures/planets/normalne/icy.png", "./textures/planets/normalne/jupiter.png",
"./textures/planets/normalne/kora.png", "./textures/planets/normalne/makemake.png", "./textures/planets/normalne/mars.png", "./textures/planets/normalne/mchowa.png",
"./textures/planets/normalne/mercury.png", "./textures/planets/normalne/neptune.jpg", "./textures/planets/normalne/saturn.png", "./textures/planets/normalne/savannah.png",
"./textures/planets/normalne/snow-foot.png", "./textures/planets/normalne/swamp.png", "./textures/planets/normalne/tropical.png", "./textures/planets/normalne/uranus.png",
"./textures/planets/normalne/venus.png", "./textures/planets/normalne/volcanic.png", "./textures/planets/normalne/watermelon.png", "./textures/planets/normalne/wood.png" };
GLuint normalTex;
glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f);
float planetSize = 0.005f;
float planetRot = 0.f;
@ -211,6 +219,7 @@ void showGUI() {
planetTexIndex = sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1;
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
normalTex = Core::LoadTexture(normalTexPaths[planetTexIndex]);
}
ImGui::SameLine();
if (ImGui::Button("Next", ImVec2(60, 20))) {
@ -220,6 +229,7 @@ void showGUI() {
planetTexIndex = 0;
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
normalTex = Core::LoadTexture(normalTexPaths[planetTexIndex]);
}
ImGui::SliderFloat("Size", &planetSize, 0.001f, 0.01f, "%.5f", ImGuiSliderFlags_AlwaysClamp);
@ -329,9 +339,11 @@ void shaderBloomConfig() {
glUniform1i(glGetUniformLocation(programBloomFinal, "bloomBlur"), 1);
}
void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, GLuint textureNormal) {
glUseProgram(programTex);
Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
Core::SetActiveTexture(textureNormal, "textureNormal", programTex, 1);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
@ -355,9 +367,10 @@ void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUseProgram(0);
}
void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, GLuint textureNormal) {
glUseProgram(programPbr);
Core::SetActiveTexture(texture, "colorTexture", programPbr, 0);
Core::SetActiveTexture(textureNormal, "textureNormal", programPbr, 1);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation);
@ -466,9 +479,11 @@ void renderScene(GLFWwindow* window) {
glm::mat4 planetTranslate = glm::translate(planetPos);
if (lightingCheck)
drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, normalTex);
else
drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, normalTex);
//drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetRock, rockNormal);
//rysowanie słońca
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
@ -526,6 +541,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
planetTexIndex = 0;
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
normalTex = Core::LoadTexture(normalTexPaths[planetTexIndex]);
}
else if (key == GLFW_KEY_Y && action == GLFW_PRESS) {
--planetTexIndex;
@ -534,6 +550,7 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
planetTexIndex = sizeof(planetTexPaths) / sizeof(planetTexPaths[0]) - 1;
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
normalTex = Core::LoadTexture(normalTexPaths[planetTexIndex]);
}
//tekstura słońca
@ -711,8 +728,9 @@ void init(GLFWwindow* window) {
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/cube.obj", cubeContext);
planetTex = Core::LoadTexture(planetTexPaths[std::abs(planetTexIndex % 20)]);
sunTex = Core::LoadTexture(sunTexPaths[std::abs(sunTexIndex % 5)]);
planetTex = Core::LoadTexture(planetTexPaths[planetTexIndex]);
normalTex = Core::LoadTexture(normalTexPaths[planetTexIndex]);
sunTex = Core::LoadTexture(sunTexPaths[sunTexIndex]);
skyBoxTex = Core::LoadSkyBox(skyBoxPaths);

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 MiB