shadery normalnych + nowe tekstury normalnych

This commit is contained in:
sasankasa 2024-02-08 01:12:49 +01:00
parent 3512eeece1
commit 0d2e870b85
35 changed files with 60 additions and 12 deletions

View File

@ -7,6 +7,7 @@ float AMBIENT = 0.05;
float PI = 3.14159; float PI = 3.14159;
uniform sampler2D colorTexture; uniform sampler2D colorTexture;
uniform sampler2D textureNormal;
uniform float exposition; uniform float exposition;
uniform float metallic; uniform float metallic;
@ -183,6 +184,11 @@ void main()
vec3 lightDir = normalize(lightPos - worldPos); vec3 lightDir = normalize(lightPos - worldPos);
vec3 textureColor = texture2D(colorTexture, vtc).rgb; 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) if (atmosphereCheck)
{ {
@ -191,8 +197,10 @@ void main()
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3)); textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3));
} }
vec3 diffuseColor = textureColor * min(1, AMBIENT + diffuseNormal);
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10; vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
vec3 toneMappedColor = toneMapping(textureColor * distance); vec3 toneMappedColor = toneMapping(diffuseColor * distance);
//gamma correction //gamma correction
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2)); toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));

View File

@ -7,6 +7,7 @@ float AMBIENT = 0.05;
float PI = 3.14159; float PI = 3.14159;
uniform sampler2D colorTexture; uniform sampler2D colorTexture;
uniform sampler2D textureNormal;
uniform vec3 color; uniform vec3 color;
uniform vec3 lightPos; uniform vec3 lightPos;
@ -26,6 +27,10 @@ in vec3 vecNormal;
in vec3 worldPos; in vec3 worldPos;
in vec2 vtc; in vec2 vtc;
in vec3 viewDirTS;
in vec3 lightDirTS;
in vec3 sunDirTS;
//out vec4 outColor; //out vec4 outColor;
vec3 toneMapping(vec3 color) vec3 toneMapping(vec3 color)
@ -104,6 +109,11 @@ void main()
float diffuse = max(0, dot(normal, lightDir)); float diffuse = max(0, dot(normal, lightDir));
vec3 textureColor = texture2D(colorTexture, vtc).rgb; 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) if (atmosphereCheck)
{ {
@ -112,7 +122,7 @@ void main()
textureColor = mix(textureColor, atmosphereColor, pow(1 - atmosphereDot, 3)); 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 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000; vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
vec3 toneMappedColor = toneMapping(diffuseColor * distance); vec3 toneMappedColor = toneMapping(diffuseColor * distance);
@ -136,4 +146,5 @@ void main()
outColor = vec4(finalColor, 1.0); outColor = vec4(finalColor, 1.0);
} }

View File

@ -3,6 +3,8 @@
layout(location = 0) in vec3 vertexPosition; layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexNormal; layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord; layout(location = 2) in vec2 vertexTexCoord;
layout(location = 3) in vec3 vertexTangent;
layout(location = 4) in vec3 vertexBitangent;
uniform mat4 transformation; uniform mat4 transformation;
uniform mat4 modelMatrix; uniform mat4 modelMatrix;
@ -11,11 +13,30 @@ out vec3 vecNormal;
out vec3 worldPos; out vec3 worldPos;
out vec2 vtc; out vec2 vtc;
uniform vec3 lightPos;
uniform vec3 cameraPos;
uniform vec3 sunDir;
out vec3 viewDirTS;
out vec3 lightDirTS;
out vec3 sunDirTS;
void main() void main()
{ {
worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz; worldPos = (modelMatrix * vec4(vertexPosition, 1)).xyz;
vecNormal = (modelMatrix * vec4(vertexNormal, 0)).xyz; vecNormal = (modelMatrix * vec4(vertexNormal, 0)).xyz;
gl_Position = transformation * vec4(vertexPosition, 1.0); gl_Position = transformation * vec4(vertexPosition, 1.0);
vtc = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y); 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

@ -35,7 +35,13 @@ const char* const planetTexPaths[] = { "./textures/planets/rocky.jpg", "./textur
"./textures/planets/makemake.jpg" }; "./textures/planets/makemake.jpg" };
int planetTexIndex = 80; int planetTexIndex = 80;
GLuint planetTex; GLuint planetTex;
GLuint planetRock;
const char* const normalTexPaths[] = { "./textures/planets/normalne/rocky.png", "./textures/planets/normalne/beach.png", "./textures/planets/normalne/circles.png", "./textures/planets/normalne/denim.png",
"./textures/planets/normalne/dirty.png", "./textures/planets/normalne/kora.png", "./textures/planets/normalne/leather.png", "./textures/planets/normalne/mchowa.png", "./textures/planets/normalne/red_stone.png",
"./textures/planets/normalne/rocks.png", "./textures/planets/normalne/rust.png", "./textures/planets/normalne/snow-foot.png", "./textures/planets/normalne/swamp.png", "./textures/planets/normalne/toxic.png",
"./textures/planets/normalne/tropical.png", "./textures/planets/normalne/volcanic.png", "./textures/planets/normalne/watermelon.png", "./textures/planets/normalne/wood.png" };
int normalTexIndex = 80;
GLuint normalTex;
glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f); glm::vec3 planetPos = glm::vec3(0.f, 0.f, 0.f);
float planetSize = 0.005f; float planetSize = 0.005f;
@ -222,9 +228,11 @@ void shaderBloomConfig() {
glUniform1i(glGetUniformLocation(programBloomFinal, "bloomBlur"), 1); 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); glUseProgram(programTex);
Core::SetActiveTexture(texture, "colorTexture", programTex, 0); Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
Core::SetActiveTexture(textureNormal, "textureNormal", programTex, 1);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix; glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
@ -247,9 +255,10 @@ void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint t
glUseProgram(0); 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); glUseProgram(programPbr);
Core::SetActiveTexture(texture, "colorTexture", programPbr, 0); Core::SetActiveTexture(texture, "colorTexture", programPbr, 0);
Core::SetActiveTexture(textureNormal, "textureNormal", programPbr, 1);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix; glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation); glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation);
@ -354,12 +363,12 @@ void renderScene(GLFWwindow* window) {
glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0)); glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0));
glm::mat4 planetTranslate = glm::translate(planetPos); glm::mat4 planetTranslate = glm::translate(planetPos);
/*if (lightingCheck) if (lightingCheck)
drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex); drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, normalTex);
else else
drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);*/ drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, normalTex);
drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetRock); //drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetRock, rockNormal);
//rysowanie słońca //rysowanie słońca
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize)); glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
@ -544,8 +553,7 @@ void init(GLFWwindow* window) {
planetTex = Core::LoadTexture(planetTexPaths[std::abs(planetTexIndex % 21)]); planetTex = Core::LoadTexture(planetTexPaths[std::abs(planetTexIndex % 21)]);
sunTex = Core::LoadTexture(sunTexPaths[std::abs(sunTexIndex % 5)]); sunTex = Core::LoadTexture(sunTexPaths[std::abs(sunTexIndex % 5)]);
normalTex = Core::LoadTexture(normalTexPaths[std::abs(normalTexIndex % 23)]);
planetRock = Core::LoadTexture("textures/planets/rocky.jpg");
skyBoxTex = Core::LoadSkyBox(skyBoxPaths); 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: 6.4 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: 6.6 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: 8.9 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: 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: 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.

Before

Width:  |  Height:  |  Size: 175 KiB

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