shadery normalnych + nowe tekstury normalnych
@ -7,6 +7,7 @@ float AMBIENT = 0.05;
|
||||
float PI = 3.14159;
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D textureNormal;
|
||||
|
||||
uniform float exposition;
|
||||
uniform float metallic;
|
||||
@ -183,6 +184,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)
|
||||
{
|
||||
@ -191,8 +197,10 @@ void main()
|
||||
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 toneMappedColor = toneMapping(textureColor * distance);
|
||||
vec3 toneMappedColor = toneMapping(diffuseColor * distance);
|
||||
//gamma correction
|
||||
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||
|
||||
|
@ -7,6 +7,7 @@ float AMBIENT = 0.05;
|
||||
float PI = 3.14159;
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D textureNormal;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec3 lightPos;
|
||||
@ -26,6 +27,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)
|
||||
@ -104,6 +109,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)
|
||||
{
|
||||
@ -112,8 +122,8 @@ 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 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 1000;
|
||||
vec3 toneMappedColor = toneMapping(diffuseColor * distance);
|
||||
//gamma correction
|
||||
@ -136,4 +146,5 @@ void main()
|
||||
|
||||
|
||||
outColor = vec4(finalColor, 1.0);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -35,7 +35,13 @@ const char* const planetTexPaths[] = { "./textures/planets/rocky.jpg", "./textur
|
||||
"./textures/planets/makemake.jpg" };
|
||||
int planetTexIndex = 80;
|
||||
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);
|
||||
float planetSize = 0.005f;
|
||||
@ -222,9 +228,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);
|
||||
@ -247,9 +255,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);
|
||||
@ -354,12 +363,12 @@ void renderScene(GLFWwindow* window) {
|
||||
glm::mat4 planetRotate = glm::rotate(time * planetRot, glm::vec3(0, 1, 0));
|
||||
glm::mat4 planetTranslate = glm::translate(planetPos);
|
||||
|
||||
/*if (lightingCheck)
|
||||
drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
|
||||
if (lightingCheck)
|
||||
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);
|
||||
//drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetRock, rockNormal);
|
||||
|
||||
//rysowanie słońca
|
||||
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
|
||||
@ -544,8 +553,7 @@ void init(GLFWwindow* window) {
|
||||
|
||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(planetTexIndex % 21)]);
|
||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(sunTexIndex % 5)]);
|
||||
|
||||
planetRock = Core::LoadTexture("textures/planets/rocky.jpg");
|
||||
normalTex = Core::LoadTexture(normalTexPaths[std::abs(normalTexIndex % 23)]);
|
||||
|
||||
skyBoxTex = Core::LoadSkyBox(skyBoxPaths);
|
||||
|
||||
|
BIN
grk/cw 6/textures/planets/denim.png
Normal file
After Width: | Height: | Size: 9.5 MiB |
BIN
grk/cw 6/textures/planets/dirty.png
Normal file
After Width: | Height: | Size: 9.1 MiB |
BIN
grk/cw 6/textures/planets/kora.png
Normal file
After Width: | Height: | Size: 8.1 MiB |
BIN
grk/cw 6/textures/planets/leather.png
Normal file
After Width: | Height: | Size: 8.9 MiB |
BIN
grk/cw 6/textures/planets/mchowa.png
Normal file
After Width: | Height: | Size: 6.0 MiB |
BIN
grk/cw 6/textures/planets/normalne/beach.png
Normal file
After Width: | Height: | Size: 6.4 MiB |
BIN
grk/cw 6/textures/planets/normalne/circles.png
Normal file
After Width: | Height: | Size: 349 KiB |
BIN
grk/cw 6/textures/planets/normalne/denim.png
Normal file
After Width: | Height: | Size: 23 MiB |
BIN
grk/cw 6/textures/planets/normalne/dirty.png
Normal file
After Width: | Height: | Size: 6.6 MiB |
BIN
grk/cw 6/textures/planets/normalne/kora.png
Normal file
After Width: | Height: | Size: 8.9 MiB |
BIN
grk/cw 6/textures/planets/normalne/leather.png
Normal file
After Width: | Height: | Size: 8.1 MiB |
BIN
grk/cw 6/textures/planets/normalne/mchowa.png
Normal file
After Width: | Height: | Size: 8.9 MiB |
BIN
grk/cw 6/textures/planets/normalne/normalna-proba.jpg
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
grk/cw 6/textures/planets/normalne/red_stone.png
Normal file
After Width: | Height: | Size: 27 MiB |
BIN
grk/cw 6/textures/planets/normalne/rocks.png
Normal file
After Width: | Height: | Size: 6.8 MiB |
BIN
grk/cw 6/textures/planets/normalne/rocky.png
Normal file
After Width: | Height: | Size: 22 MiB |
BIN
grk/cw 6/textures/planets/normalne/rust.png
Normal file
After Width: | Height: | Size: 3.7 MiB |
BIN
grk/cw 6/textures/planets/normalne/snow-foot.png
Normal file
After Width: | Height: | Size: 9.1 MiB |
BIN
grk/cw 6/textures/planets/normalne/swamp.png
Normal file
After Width: | Height: | Size: 4.9 MiB |
BIN
grk/cw 6/textures/planets/normalne/toxic.png
Normal file
After Width: | Height: | Size: 2.1 MiB |
BIN
grk/cw 6/textures/planets/normalne/tropical.png
Normal file
After Width: | Height: | Size: 3.3 MiB |
BIN
grk/cw 6/textures/planets/normalne/volcanic.png
Normal file
After Width: | Height: | Size: 4.2 MiB |
BIN
grk/cw 6/textures/planets/normalne/watermelon.png
Normal file
After Width: | Height: | Size: 2.3 MiB |
BIN
grk/cw 6/textures/planets/normalne/wood.png
Normal file
After Width: | Height: | Size: 4.7 MiB |
BIN
grk/cw 6/textures/planets/rocks.png
Normal file
After Width: | Height: | Size: 8.4 MiB |
Before Width: | Height: | Size: 175 KiB |
BIN
grk/cw 6/textures/planets/rocky.png
Normal file
After Width: | Height: | Size: 22 MiB |
BIN
grk/cw 6/textures/planets/rust.png
Normal file
After Width: | Height: | Size: 6.0 MiB |
BIN
grk/cw 6/textures/planets/snow-foot.png
Normal file
After Width: | Height: | Size: 5.4 MiB |
BIN
grk/cw 6/textures/planets/watermelon.png
Normal file
After Width: | Height: | Size: 5.2 MiB |
BIN
grk/cw 6/textures/planets/wood.png
Normal file
After Width: | Height: | Size: 7.0 MiB |