dodanie efektu atmosfery oraz interakcji z nim i pbr, poprawienie inputu, dodanie tonemappingu do słońca, naprawienie gamma correction i usunięcie śmieci
This commit is contained in:
parent
d363d89620
commit
136be27135
@ -40,14 +40,10 @@
|
|||||||
<None Include="shaders\shader_pbr.vert" />
|
<None Include="shaders\shader_pbr.vert" />
|
||||||
<None Include="shaders\shader_skybox.frag" />
|
<None Include="shaders\shader_skybox.frag" />
|
||||||
<None Include="shaders\shader_skybox.vert" />
|
<None Include="shaders\shader_skybox.vert" />
|
||||||
<None Include="shaders\shader_noise.frag" />
|
|
||||||
<None Include="shaders\shader_smap.vert" />
|
|
||||||
<None Include="shaders\shader_tex.frag" />
|
<None Include="shaders\shader_tex.frag" />
|
||||||
<None Include="shaders\shader_tex.vert" />
|
<None Include="shaders\shader_tex.vert" />
|
||||||
<None Include="shaders\shader_sun.frag" />
|
<None Include="shaders\shader_sun.frag" />
|
||||||
<None Include="shaders\shader_sun.vert" />
|
<None Include="shaders\shader_sun.vert" />
|
||||||
<None Include="shaders\test.frag" />
|
|
||||||
<None Include="shaders\test.vert" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{3952C396-B1C6-44CD-96DD-C1AC15D32978}</ProjectGuid>
|
<ProjectGuid>{3952C396-B1C6-44CD-96DD-C1AC15D32978}</ProjectGuid>
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
# Blender v3.2.1 OBJ File: 'untitled.blend'
|
|
||||||
# www.blender.org
|
|
||||||
mtllib plane.mtl
|
|
||||||
o Plane.001
|
|
||||||
v -1.000000 -1.000000 -0.000000
|
|
||||||
v 1.000000 -1.000000 -0.000000
|
|
||||||
v -1.000000 1.000000 0.000000
|
|
||||||
v 1.000000 1.000000 0.000000
|
|
||||||
vt 0.000000 0.000000
|
|
||||||
vt 1.000000 0.000000
|
|
||||||
vt 1.000000 1.000000
|
|
||||||
vt 0.000000 1.000000
|
|
||||||
vn 0.0000 -0.0000 1.0000
|
|
||||||
usemtl None
|
|
||||||
s off
|
|
||||||
f 1/1/1 2/2/1 4/3/1 3/4/1
|
|
@ -1,80 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
float PI = 3.14159f;
|
|
||||||
|
|
||||||
uniform sampler2D colorTexture;
|
|
||||||
|
|
||||||
uniform float exposition;
|
|
||||||
|
|
||||||
in vec3 vecNormal;
|
|
||||||
in vec3 worldPos;
|
|
||||||
in vec2 vtc;
|
|
||||||
|
|
||||||
out vec4 outColor;
|
|
||||||
|
|
||||||
in vec3 viewDirTS;
|
|
||||||
in vec3 lightDirTS;
|
|
||||||
in vec3 sunDirTS;
|
|
||||||
|
|
||||||
uniform float u_time;
|
|
||||||
float pi = 3.14159;
|
|
||||||
// 2D Random
|
|
||||||
float random (in vec2 st) {
|
|
||||||
return fract(sin(dot(st.xy,
|
|
||||||
vec2(12.9898,78.233)))
|
|
||||||
* 43758.5453123);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2D Noise based on Morgan McGuire @morgan3d
|
|
||||||
// https://www.shadertoy.com/view/4dS3Wd
|
|
||||||
float noise (in vec2 st) {
|
|
||||||
vec2 i = floor(st);
|
|
||||||
vec2 f = fract(st);
|
|
||||||
|
|
||||||
// Four corners in 2D of a tile
|
|
||||||
float a = random(i);
|
|
||||||
float b = random(i + vec2(1.0, 0.0));
|
|
||||||
float c = random(i + vec2(0.0, 1.0));
|
|
||||||
float d = random(i + vec2(1.0, 1.0));
|
|
||||||
|
|
||||||
vec2 randA = vec2(a *2.0 *pi);
|
|
||||||
vec2 randB = vec2(b *2.0 *pi);
|
|
||||||
vec2 randC = vec2(c *2.0 *pi);
|
|
||||||
vec2 randD = vec2(d *2.0 *pi);
|
|
||||||
|
|
||||||
vec2 offsetA = a-st;
|
|
||||||
vec2 offsetB = b-st;
|
|
||||||
vec2 offsetC = c-st;
|
|
||||||
vec2 offsetD = d-st;
|
|
||||||
|
|
||||||
offsetA = offsetA*randA;
|
|
||||||
offsetB = offsetB*randB;
|
|
||||||
offsetC = offsetC*randC;
|
|
||||||
offsetD = offsetD*randD;
|
|
||||||
|
|
||||||
float resA = smoothstep(offsetA.x,offsetA.y, f.y);
|
|
||||||
float resB = smoothstep(offsetB.x,offsetB.y, f.y);
|
|
||||||
float resC = smoothstep(offsetC.x,offsetC.y, f.y);
|
|
||||||
float resD = smoothstep(offsetD.x,offsetD.y, f.y);
|
|
||||||
|
|
||||||
vec2 u = smoothstep(0.,1.,f);
|
|
||||||
|
|
||||||
|
|
||||||
float ab= mix(a, b, u.x);
|
|
||||||
float cd = mix(c, d, u.x);
|
|
||||||
return mix(ab,cd,u.y);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
|
|
||||||
vec2 st = vtc;
|
|
||||||
vec2 pos = vec2(st*3.776);
|
|
||||||
|
|
||||||
// Use the noise function
|
|
||||||
float n = 1.836 * 0.676*noise(pos*2.576);
|
|
||||||
n = smoothstep(-0.096, 1.176, n);
|
|
||||||
|
|
||||||
outColor = vec4(vec3(n), 1);
|
|
||||||
}
|
|
@ -1,24 +1,23 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
float AMBIENT = 0.25f;
|
float AMBIENT = 0.05;
|
||||||
float PI = 3.14159f;
|
float PI = 3.14159;
|
||||||
|
|
||||||
uniform sampler2D depthMap;
|
|
||||||
|
|
||||||
uniform vec3 cameraPos;
|
|
||||||
|
|
||||||
uniform sampler2D colorTexture;
|
uniform sampler2D colorTexture;
|
||||||
|
|
||||||
|
uniform float exposition;
|
||||||
|
uniform float metallic;
|
||||||
|
uniform float roughness;
|
||||||
|
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
uniform vec3 sunDir;
|
uniform vec3 sunDir;
|
||||||
uniform vec3 sunColor;
|
uniform vec3 sunColor;
|
||||||
|
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
|
|
||||||
uniform float metallic;
|
uniform bool atmosphereCheck;
|
||||||
uniform float roughness;
|
|
||||||
|
|
||||||
uniform float exposition;
|
|
||||||
|
|
||||||
in vec3 vecNormal;
|
in vec3 vecNormal;
|
||||||
in vec3 worldPos;
|
in vec3 worldPos;
|
||||||
@ -99,7 +98,7 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V, vec3 color)
|
|||||||
|
|
||||||
vec3 toneMapping(vec3 color)
|
vec3 toneMapping(vec3 color)
|
||||||
{
|
{
|
||||||
float exposure = 0.03;
|
float exposure = 0.06;
|
||||||
vec3 mapped = 1 - exp(-color * exposure);
|
vec3 mapped = 1 - exp(-color * exposure);
|
||||||
return mapped;
|
return mapped;
|
||||||
}
|
}
|
||||||
@ -107,18 +106,21 @@ vec3 toneMapping(vec3 color)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 normal = normalize(vecNormal);
|
vec3 normal = normalize(vecNormal);
|
||||||
|
|
||||||
vec3 viewDir = normalize(cameraPos - worldPos);
|
vec3 viewDir = normalize(cameraPos - worldPos);
|
||||||
|
|
||||||
vec3 lightDir = normalize(lightPos - worldPos);
|
vec3 lightDir = normalize(lightPos - worldPos);
|
||||||
|
|
||||||
vec4 textureColor = texture2D(colorTexture, vtc);
|
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||||
|
|
||||||
float diffuse = max(0, dot(normal, lightDir));
|
float atmosphereDot = dot(normal, viewDir);
|
||||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 300;
|
vec3 atmosphereColor = vec3(0.04, 0.2, 1.0);
|
||||||
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
|
|
||||||
|
if (atmosphereCheck)
|
||||||
|
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.1);
|
||||||
|
|
||||||
|
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10;
|
||||||
|
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
|
||||||
//gamma correction
|
//gamma correction
|
||||||
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||||
|
|
||||||
vec3 ambient = AMBIENT * toneMappedColor;
|
vec3 ambient = AMBIENT * toneMappedColor;
|
||||||
vec3 attenuatedLightColor = lightColor / pow(length(lightPos - worldPos), 2);
|
vec3 attenuatedLightColor = lightColor / pow(length(lightPos - worldPos), 2);
|
||||||
@ -128,5 +130,7 @@ void main()
|
|||||||
//sun
|
//sun
|
||||||
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, toneMappedColor);
|
illumination = illumination + PBRLight(sunDir, sunColor, normal, viewDir, toneMappedColor);
|
||||||
|
|
||||||
outColor = vec4(vec3(1.0) - exp(-illumination * exposition), 1);
|
vec3 pbrColor = vec3(1.0) - exp(-illumination * exposition);
|
||||||
|
|
||||||
|
outColor = vec4(pbrColor, 1);
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,5 @@ out vec4 out_color;
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 textureColor = texture(skybox, texCoord);
|
vec4 textureColor = texture(skybox, texCoord);
|
||||||
out_color = vec4(vec3(textureColor) * lightColor * 0.3f, 1.0f);
|
out_color = vec4(vec3(textureColor) * lightColor * 0.35f, 1.0f);
|
||||||
}
|
}
|
@ -1,13 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 vertexPosition;
|
|
||||||
layout(location = 1) in vec3 vertexNormal;
|
|
||||||
layout(location = 2) in vec2 vertexTexCoord;
|
|
||||||
|
|
||||||
uniform mat4 viewProjectionMatrix;
|
|
||||||
uniform mat4 modelMatrix;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = viewProjectionMatrix * modelMatrix * vec4(vertexPosition, 1.0);
|
|
||||||
}
|
|
@ -1,10 +1,12 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
float AMBIENT = 0.1;
|
|
||||||
|
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
|
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
|
uniform bool atmosphereCheck;
|
||||||
|
|
||||||
in vec3 vecNormal;
|
in vec3 vecNormal;
|
||||||
in vec3 worldPos;
|
in vec3 worldPos;
|
||||||
in vec2 vtc;
|
in vec2 vtc;
|
||||||
@ -13,8 +15,30 @@ out vec4 outColor;
|
|||||||
|
|
||||||
uniform sampler2D colorTexture;
|
uniform sampler2D colorTexture;
|
||||||
|
|
||||||
|
vec3 toneMapping(vec3 color)
|
||||||
|
{
|
||||||
|
float exposure = 0.06;
|
||||||
|
vec3 mapped = 1 - exp(-color * exposure);
|
||||||
|
return mapped;
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
vec3 normal = normalize(vecNormal);
|
||||||
|
vec3 viewDir = normalize(cameraPos - worldPos);
|
||||||
|
|
||||||
vec4 textureColor = texture2D(colorTexture, vtc);
|
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||||
outColor = vec4(vec3(textureColor) * lightColor * 0.15f, 1.0);
|
|
||||||
|
float atmosphereDot = dot(normal, viewDir);
|
||||||
|
vec3 atmosphereColor = vec3(1.0, 0.04, 0.01);
|
||||||
|
|
||||||
|
if (atmosphereCheck)
|
||||||
|
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.25);
|
||||||
|
|
||||||
|
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 25;
|
||||||
|
vec3 toneMappedColor = toneMapping(vec3(textureColor) * distance);
|
||||||
|
//gamma correction
|
||||||
|
toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||||
|
|
||||||
|
outColor = vec4(toneMappedColor * lightColor * 0.2f, 1.0);
|
||||||
}
|
}
|
@ -13,6 +13,9 @@ out vec2 vtc;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
worldPos = (modelMatrix * vec4(vertexPosition, 1)).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);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
|
|
||||||
float AMBIENT = 0.1;
|
float AMBIENT = 0.05;
|
||||||
|
|
||||||
|
uniform sampler2D colorTexture;
|
||||||
|
|
||||||
uniform vec3 color;
|
uniform vec3 color;
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
uniform vec3 lightColor;
|
uniform vec3 lightColor;
|
||||||
|
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
|
uniform bool atmosphereCheck;
|
||||||
|
|
||||||
in vec3 vecNormal;
|
in vec3 vecNormal;
|
||||||
in vec3 worldPos;
|
in vec3 worldPos;
|
||||||
in vec2 vtc;
|
in vec2 vtc;
|
||||||
vec4 textureColor;
|
|
||||||
out vec4 outColor;
|
|
||||||
|
|
||||||
vec3 outputColor;
|
out vec4 outColor;
|
||||||
uniform sampler2D colorTexture;
|
|
||||||
|
|
||||||
vec3 toneMapping(vec3 color)
|
vec3 toneMapping(vec3 color)
|
||||||
{
|
{
|
||||||
@ -24,17 +27,24 @@ vec3 toneMapping(vec3 color)
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 lightDir = normalize(lightPos - worldPos);
|
|
||||||
vec3 normal = normalize(vecNormal);
|
vec3 normal = normalize(vecNormal);
|
||||||
|
vec3 viewDir = normalize(cameraPos - worldPos);
|
||||||
|
vec3 lightDir = normalize(lightPos - worldPos);
|
||||||
|
|
||||||
float diffuse = max(0, dot(normal, lightDir));
|
float diffuse = max(0, dot(normal, lightDir));
|
||||||
textureColor = texture2D(colorTexture, vtc);
|
|
||||||
|
|
||||||
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 200;
|
vec4 textureColor = texture2D(colorTexture, vtc);
|
||||||
outputColor = vec3(textureColor) * min(1, AMBIENT + diffuse) * distance;
|
|
||||||
|
|
||||||
//gamma correction
|
float atmosphereDot = dot(normal, viewDir);
|
||||||
//outputColor = pow(outputColor, vec3(1.0/2.2));
|
vec3 atmosphereColor = vec3(0.04, 0.2, 1.0);
|
||||||
|
|
||||||
outputColor = toneMapping(outputColor);
|
if (atmosphereCheck)
|
||||||
outColor = vec4(outputColor , 1.0);
|
textureColor = mix(textureColor, vec4(atmosphereColor / atmosphereDot, 1.0), 0.05);
|
||||||
|
|
||||||
|
vec3 distance = lightColor / pow(length(lightPos - worldPos), 2.0) * 10000;
|
||||||
|
vec3 toneMappedColor = toneMapping(vec3(textureColor) * min(1, AMBIENT + diffuse) * distance);
|
||||||
|
//gamma correction
|
||||||
|
//toneMappedColor = pow(toneMappedColor, vec3(1.0/2.2));
|
||||||
|
|
||||||
|
outColor = vec4(toneMappedColor, 1);
|
||||||
}
|
}
|
@ -1,12 +0,0 @@
|
|||||||
#version 330 core
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec2 tc;
|
|
||||||
|
|
||||||
uniform sampler2D depthMap;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
float depthValue = texture(depthMap, tc).r;
|
|
||||||
FragColor = vec4(vec3(depthValue+0.5), 1.0);
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
#version 430 core
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 vertexPosition;
|
|
||||||
layout(location = 1) in vec3 vertexNormal;
|
|
||||||
layout(location = 2) in vec2 vertexTexCoord;
|
|
||||||
|
|
||||||
|
|
||||||
out vec2 tc;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
tc = vertexTexCoord;
|
|
||||||
gl_Position = vec4(vertexPosition*0.9, 1.0);
|
|
||||||
}
|
|
@ -14,55 +14,10 @@
|
|||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/*
|
|
||||||
namespace texturePlanets {
|
|
||||||
GLuint blank;
|
|
||||||
GLuint earth;
|
|
||||||
GLuint planet;
|
|
||||||
GLuint mercury;
|
|
||||||
GLuint venus;
|
|
||||||
GLuint mars;
|
|
||||||
GLuint alpine;
|
|
||||||
GLuint ceres;
|
|
||||||
GLuint eris;
|
|
||||||
GLuint haumea;
|
|
||||||
GLuint icy;
|
|
||||||
GLuint jupiter;
|
|
||||||
GLuint makemake;
|
|
||||||
GLuint martian;
|
|
||||||
GLuint neptune;
|
|
||||||
GLuint saturn;
|
|
||||||
GLuint savannah;
|
|
||||||
GLuint swamp;
|
|
||||||
GLuint tropical;
|
|
||||||
GLuint uranus;
|
|
||||||
GLuint venusian;
|
|
||||||
GLuint volcanic;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace textureSuns {
|
|
||||||
GLuint sun1;
|
|
||||||
GLuint sun2;
|
|
||||||
GLuint sun3;
|
|
||||||
GLuint sun4;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace textureMoons {
|
|
||||||
GLuint moon1;
|
|
||||||
GLuint moon2;
|
|
||||||
GLuint moon3;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace textureMaterials {
|
|
||||||
GLuint clouds;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
GLuint programDepth;
|
|
||||||
GLuint programTex;
|
GLuint programTex;
|
||||||
GLuint programPbr;
|
GLuint programPbr;
|
||||||
GLuint programSun;
|
GLuint programSun;
|
||||||
GLuint programSkyBox;
|
GLuint programSkyBox;
|
||||||
GLuint programNoise;
|
|
||||||
|
|
||||||
Core::Shader_Loader shaderLoader;
|
Core::Shader_Loader shaderLoader;
|
||||||
|
|
||||||
@ -91,6 +46,9 @@ glm::vec3 sunPos = glm::vec3(20.f, 0.f, 20.f);
|
|||||||
glm::vec3 sunDir = glm::vec3(1.f, 0.f, 1.f);
|
glm::vec3 sunDir = glm::vec3(1.f, 0.f, 1.f);
|
||||||
float sunSize = 0.05f;
|
float sunSize = 0.05f;
|
||||||
|
|
||||||
|
bool atmosphereCheck = false;
|
||||||
|
bool lightingCheck = false;
|
||||||
|
|
||||||
const char* skyBoxPaths[] = { "./textures/skybox/space_rt.png", "./textures/skybox/space_lf.png", "./textures/skybox/space_up.png", "./textures/skybox/space_dn.png",
|
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" };
|
"./textures/skybox/space_bk.png", "./textures/skybox/space_ft.png" };
|
||||||
GLuint skyBoxTex;
|
GLuint skyBoxTex;
|
||||||
@ -113,7 +71,7 @@ unsigned int depthMapFBO;
|
|||||||
int HDR_WIDTH = 1024;
|
int HDR_WIDTH = 1024;
|
||||||
int HDR_HEIGHT = 1024;
|
int HDR_HEIGHT = 1024;
|
||||||
|
|
||||||
float lightPower = 10.f;
|
float lightPower = 8.f;
|
||||||
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
glm::vec3 lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||||
|
|
||||||
glm::mat4 createCameraMatrix() {
|
glm::mat4 createCameraMatrix() {
|
||||||
@ -194,15 +152,47 @@ void initDepthMap() {
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPlanet(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
|
void drawPlanetTex(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
|
||||||
glUseProgram(programTex);
|
glUseProgram(programTex);
|
||||||
Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
|
Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
|
||||||
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);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
||||||
glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
||||||
|
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
|
|
||||||
|
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
|
||||||
|
|
||||||
|
Core::DrawContext(context);
|
||||||
|
glUseProgram(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawPlanetPbr(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
|
||||||
|
glUseProgram(programPbr);
|
||||||
|
Core::SetActiveTexture(texture, "colorTexture", programPbr, 0);
|
||||||
|
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||||
|
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(programPbr, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
|
|
||||||
|
glUniform1f(glGetUniformLocation(programPbr, "exposition"), lightPower);
|
||||||
|
glUniform1f(glGetUniformLocation(programPbr, "roughness"), planetRough);
|
||||||
|
glUniform1f(glGetUniformLocation(programPbr, "metallic"), planetMetal);
|
||||||
|
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
|
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "sunColor"), lightColor.x, lightColor.y, lightColor.z);
|
||||||
|
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
||||||
|
|
||||||
|
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
|
||||||
|
|
||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
@ -214,8 +204,14 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
|
|||||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSun, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(programSun, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programSun, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
glUniform3f(glGetUniformLocation(programSun, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
||||||
glUniform3f(glGetUniformLocation(programSun, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
glUniform3f(glGetUniformLocation(programSun, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
||||||
|
|
||||||
|
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||||
|
|
||||||
|
glUniform1i(glGetUniformLocation(programPbr, "atmosphereCheck"), atmosphereCheck);
|
||||||
|
|
||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
@ -227,50 +223,15 @@ void drawSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint text
|
|||||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programSkyBox, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
glUniform3f(glGetUniformLocation(programSkyBox, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
||||||
Core::DrawContext(context);
|
|
||||||
glUseProgram(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, float roughness, float metallic) {
|
|
||||||
glUseProgram(programPbr);
|
|
||||||
Core::SetActiveTexture(texture, "colorTexture", programPbr, 0);
|
|
||||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
|
||||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programPbr, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programPbr, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
|
||||||
|
|
||||||
glUniform1f(glGetUniformLocation(programPbr, "exposition"), lightPower);
|
|
||||||
|
|
||||||
glUniform1f(glGetUniformLocation(programPbr, "roughness"), roughness);
|
|
||||||
glUniform1f(glGetUniformLocation(programPbr, "metallic"), metallic);
|
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programPbr, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programPbr, "sunDir"), sunDir.x, sunDir.y, sunDir.z);
|
|
||||||
glUniform3f(glGetUniformLocation(programPbr, "sunColor"), lightColor.x, lightColor.y, lightColor.z);
|
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(programPbr, "lightPos"), sunPos.x, sunPos.y, sunPos.z);
|
|
||||||
glUniform3f(glGetUniformLocation(programPbr, "lightColor"), lightColor.x, lightColor.y, lightColor.z);
|
|
||||||
|
|
||||||
Core::DrawContext(context);
|
Core::DrawContext(context);
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawObjectNoise(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, float roughness, float metallic) {
|
|
||||||
glUseProgram(programNoise);
|
|
||||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
|
||||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programNoise, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
|
||||||
glUniformMatrix4fv(glGetUniformLocation(programNoise, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
|
||||||
|
|
||||||
Core::DrawContext(context);
|
|
||||||
glUseProgram(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void renderScene(GLFWwindow* window) {
|
void renderScene(GLFWwindow* window) {
|
||||||
glClearColor(0.5f, 0.0f, 0.25f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
float time = glfwGetTime();
|
float time = glfwGetTime();
|
||||||
|
|
||||||
@ -279,9 +240,10 @@ 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);
|
||||||
|
|
||||||
//drawPlanet(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
|
if (lightingCheck)
|
||||||
drawObjectPBR(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, planetRough, planetMetal);
|
drawPlanetPbr(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
|
||||||
drawObjectNoise(sphereContext, planetTranslate * planetRotate * planetScale, planetTex, planetRough, planetMetal);
|
else
|
||||||
|
drawPlanetTex(sphereContext, planetTranslate * planetRotate * planetScale, planetTex);
|
||||||
|
|
||||||
//rysowanie słońca
|
//rysowanie słońca
|
||||||
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
|
glm::mat4 sunScale = glm::scale(glm::vec3(sunSize));
|
||||||
@ -316,37 +278,27 @@ void loadModelToContext(std::string path, Core::RenderContext& context) {
|
|||||||
context.initFromAssimpMesh(scene->mMeshes[0]);
|
context.initFromAssimpMesh(scene->mMeshes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void init(GLFWwindow* window) {
|
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
{
|
||||||
|
//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)]);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
//tekstura słońca
|
||||||
//glDisable(GL_DEPTH_TEST);
|
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)]);
|
||||||
|
|
||||||
//initDepthMap();
|
//atmosfera
|
||||||
initHDR();
|
if (key == GLFW_KEY_O && action == GLFW_PRESS)
|
||||||
|
atmosphereCheck = !atmosphereCheck;
|
||||||
|
|
||||||
//programDepth = shaderLoader.CreateProgram("shaders/shader_smap.vert", "shaders/shader_smap.frag");
|
//typ światła
|
||||||
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
if (key == GLFW_KEY_P && action == GLFW_PRESS)
|
||||||
programPbr = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
lightingCheck = !lightingCheck;
|
||||||
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
|
||||||
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
|
||||||
programNoise = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_noise.frag");
|
|
||||||
|
|
||||||
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)]);
|
|
||||||
|
|
||||||
skyBoxTex = Core::LoadSkyBox(skyBoxPaths);
|
|
||||||
}
|
|
||||||
|
|
||||||
void shutdown(GLFWwindow* window) {
|
|
||||||
shaderLoader.DeleteProgram(programDepth);
|
|
||||||
shaderLoader.DeleteProgram(programTex);
|
|
||||||
shaderLoader.DeleteProgram(programPbr);
|
|
||||||
shaderLoader.DeleteProgram(programSun);
|
|
||||||
shaderLoader.DeleteProgram(programSkyBox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//obsluga wejscia
|
//obsluga wejscia
|
||||||
@ -356,7 +308,7 @@ void processInput(GLFWwindow* window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
//ruch kamerą
|
//ruch kamery
|
||||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||||
float cameraSpeed = 0.02f;
|
float cameraSpeed = 0.02f;
|
||||||
|
|
||||||
@ -387,32 +339,12 @@ void processInput(GLFWwindow* window)
|
|||||||
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.f)
|
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS && planetRot > -1.f)
|
||||||
planetRot -= rotationSpeed;
|
planetRot -= rotationSpeed;
|
||||||
|
|
||||||
//zmiana tekstury planety
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_T) == GLFW_PRESS) {
|
|
||||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(++planetTexIndex % 20)]);
|
|
||||||
Sleep(200);
|
|
||||||
}
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_Y) == GLFW_PRESS && planetTexIndex > 0) {
|
|
||||||
planetTex = Core::LoadTexture(planetTexPaths[std::abs(--planetTexIndex % 20)]);
|
|
||||||
Sleep(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
//zmiana tekstury słońca
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_U) == GLFW_PRESS) {
|
|
||||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(++sunTexIndex % 5)]);
|
|
||||||
Sleep(200);
|
|
||||||
}
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_I) == GLFW_PRESS && sunTexIndex > 0) {
|
|
||||||
sunTex = Core::LoadTexture(sunTexPaths[std::abs(--sunTexIndex % 5)]);
|
|
||||||
Sleep(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
//jasność
|
//jasność
|
||||||
float powerSpeed = 0.05f;
|
float powerSpeed = 0.05f;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 25.f)
|
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS && lightPower < 16.f)
|
||||||
lightPower += powerSpeed;
|
lightPower += powerSpeed;
|
||||||
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.5f)
|
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS && lightPower > 2.f)
|
||||||
lightPower -= powerSpeed;
|
lightPower -= powerSpeed;
|
||||||
|
|
||||||
lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
lightColor = glm::vec3(lightPower, lightPower, lightPower);
|
||||||
@ -434,6 +366,38 @@ void processInput(GLFWwindow* window)
|
|||||||
planetMetal -= metalSpeed;
|
planetMetal -= metalSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init(GLFWwindow* window) {
|
||||||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
//glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
//initDepthMap();
|
||||||
|
//initHDR();
|
||||||
|
|
||||||
|
glfwSetKeyCallback(window, key_callback);
|
||||||
|
|
||||||
|
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||||
|
programPbr = shaderLoader.CreateProgram("shaders/shader_pbr.vert", "shaders/shader_pbr.frag");
|
||||||
|
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
|
||||||
|
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||||
|
|
||||||
|
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)]);
|
||||||
|
|
||||||
|
skyBoxTex = Core::LoadSkyBox(skyBoxPaths);
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown(GLFWwindow* window) {
|
||||||
|
shaderLoader.DeleteProgram(programTex);
|
||||||
|
shaderLoader.DeleteProgram(programPbr);
|
||||||
|
shaderLoader.DeleteProgram(programSun);
|
||||||
|
shaderLoader.DeleteProgram(programSkyBox);
|
||||||
|
}
|
||||||
|
|
||||||
// funkcja jest glowna petla
|
// funkcja jest glowna petla
|
||||||
void renderLoop(GLFWwindow* window) {
|
void renderLoop(GLFWwindow* window) {
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
Loading…
Reference in New Issue
Block a user