naprawa tekstur
This commit is contained in:
parent
afcfb5a89f
commit
9e3965583c
2500
cw 9/models/sphere.obj
Normal file
2500
cw 9/models/sphere.obj
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,10 @@
|
||||
#version 430 core
|
||||
#version 430 core
|
||||
|
||||
float AMBIENT = 0.03;
|
||||
float PI = 3.14;
|
||||
|
||||
uniform sampler2D depthMap;
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
uniform vec3 cameraPos;
|
||||
|
||||
@ -23,10 +24,9 @@ uniform vec3 spotlightPhi;
|
||||
uniform float metallic;
|
||||
uniform float roughness;
|
||||
|
||||
uniform float exposition;
|
||||
|
||||
in vec3 vecNormal;
|
||||
in vec3 worldPos;
|
||||
in vec2 vecTex;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
@ -38,25 +38,6 @@ in vec3 sunDirTS;
|
||||
|
||||
in vec3 test;
|
||||
|
||||
// wektor przechowujący punkt widzenia światła
|
||||
in vec4 sunSpacePos;
|
||||
|
||||
// mapa przechowująca wartość cieni
|
||||
uniform sampler2D shadowMap;
|
||||
|
||||
// zmienne przechowujące szerokość i wysokość mapy cieni
|
||||
uniform float shadowMapWidth;
|
||||
uniform float shadowMapHeight;
|
||||
|
||||
// zmienne do PCF - Percentage Closer Filtering
|
||||
|
||||
// promień pixeli - np. 2 oznacza badanie na szerokość 5 bo 2 + 1 + 2
|
||||
const int pcfCount = 8;
|
||||
|
||||
// ilość wszystkich pixeli - (2 * promień + 1) ^ 2
|
||||
const float totalTexels = (pcfCount * 2.0 + 1.0) * (pcfCount * 2.0 + 1.0);
|
||||
|
||||
|
||||
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
||||
float a = roughness*roughness;
|
||||
float a2 = a*a;
|
||||
@ -117,76 +98,31 @@ vec3 PBRLight(vec3 lightDir, vec3 radiance, vec3 normal, vec3 V){
|
||||
return (kD * color / PI + specular) * radiance * NdotL;
|
||||
}
|
||||
|
||||
// metoda obliczająca cień za pomocą PCF
|
||||
|
||||
float calculateShadow(vec4 lightPos, sampler2D Shadow_Map){
|
||||
// ujednorodnienie pozycji światła
|
||||
vec3 _lightPos = lightPos.xyz/lightPos.w;
|
||||
|
||||
// skalowanie z wartości (-1, 1) do wartości (0, 1)
|
||||
_lightPos = _lightPos * 0.5 + 0.5;
|
||||
|
||||
// ustalenie wielości texeli
|
||||
double TexelWidth = 1.0/shadowMapWidth;
|
||||
double TexelHeight = 1.0/shadowMapHeight;
|
||||
|
||||
vec2 TexelSize = vec2(TexelWidth, TexelHeight);
|
||||
|
||||
// zmienna przechowująca wartość cienia
|
||||
float shadowSum = 0.0;
|
||||
|
||||
// algorytm PCF
|
||||
for (int y = -pcfCount ; y <= pcfCount ; y++) {
|
||||
for (int x = -pcfCount ; x <= pcfCount ; x++) {
|
||||
// liczymi wartości (x, y) z przesunięciem
|
||||
vec2 Offset = vec2(x, y) * TexelSize;
|
||||
|
||||
// sprawdzenie wartości z dpeth map oraz przypisanie odpowiedniej wartości dla shadow
|
||||
float shadow = _lightPos.z > texture(Shadow_Map, _lightPos.xy + Offset).r + 0.001 ? 1.0 : 0.0;
|
||||
|
||||
// dodanie wartości do shadow
|
||||
shadowSum += shadow;
|
||||
}
|
||||
}
|
||||
|
||||
// zwrócenie średniej wartości cieni z wszystkich pixeli wokół
|
||||
return ((shadowSum/totalTexels)/lightPos.w);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
|
||||
|
||||
|
||||
vec3 ambient = AMBIENT*color;
|
||||
vec3 attenuatedlightColor = lightColor/pow(length(lightPos-worldPos),2);
|
||||
vec3 ilumination;
|
||||
ilumination = ambient+PBRLight(lightDir,attenuatedlightColor,normal,viewDir);
|
||||
|
||||
//flashlight
|
||||
//vec3 spotlightDir= normalize(spotlightDirTS);
|
||||
vec3 spotlightDir= normalize(spotlightPos-worldPos);
|
||||
|
||||
|
||||
float angle_atenuation = clamp((dot(-normalize(spotlightPos-worldPos),spotlightConeDir)-0.5)*3,0,1);
|
||||
attenuatedlightColor = angle_atenuation*spotlightColor/pow(length(spotlightPos-worldPos),2);
|
||||
ilumination=ilumination+PBRLight(spotlightDir,attenuatedlightColor,normal,viewDir);
|
||||
|
||||
// obliczanie cienia
|
||||
float shadow = calculateShadow(sunSpacePos, shadowMap);
|
||||
|
||||
//sun
|
||||
// zaaplikowanie cienia do koloru światła.
|
||||
ilumination = ilumination + PBRLight(sunDir,sunColor * (1.0 - shadow), normal, viewDir);
|
||||
ilumination=ilumination+PBRLight(sunDir,sunColor,normal,viewDir);
|
||||
|
||||
float diffuse=max(0,dot(normal,lightDir));
|
||||
outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0);
|
||||
|
||||
outColor = vec4(vec3(1.0) - exp(-ilumination*exposition),1);
|
||||
//outColor = vec4(roughness,metallic,0,1);
|
||||
//outColor = vec4(test;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#version 430 core
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
@ -8,10 +8,10 @@ layout(location = 4) in vec3 vertexBitangent;
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
uniform mat4 lightVP;
|
||||
|
||||
out vec3 vecNormal;
|
||||
out vec3 worldPos;
|
||||
out vec2 vecTex;
|
||||
|
||||
uniform vec3 lightPos;
|
||||
uniform vec3 spotlightPos;
|
||||
@ -23,13 +23,12 @@ out vec3 lightDirTS;
|
||||
out vec3 spotlightDirTS;
|
||||
out vec3 sunDirTS;
|
||||
|
||||
out vec4 sunSpacePos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz;
|
||||
vecTex = vertexTexCoord;
|
||||
vecTex.y = 1.0 - vecTex.y;
|
||||
gl_Position = transformation * vec4(vertexPosition, 1.0);
|
||||
|
||||
vec3 w_tangent = normalize(mat3(modelMatrix)*vertexTangent);
|
||||
@ -44,7 +43,4 @@ void main()
|
||||
spotlightDirTS = TBN*SL;
|
||||
sunDirTS = TBN*sunDir;
|
||||
|
||||
// przeliczanie pozycji światła
|
||||
sunSpacePos = lightVP * modelMatrix * vec4(vertexPosition, 1);
|
||||
|
||||
}
|
||||
|
@ -19,28 +19,9 @@ const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
|
||||
|
||||
int WIDTH = 500, HEIGHT = 500;
|
||||
|
||||
namespace models {
|
||||
Core::RenderContext roomContext;
|
||||
Core::RenderContext mattressContext;
|
||||
Core::RenderContext bedContext;
|
||||
Core::RenderContext wardrobeContext;
|
||||
Core::RenderContext wardrobeDoorLeftContext;
|
||||
Core::RenderContext wardrobeDoorRightContext;
|
||||
Core::RenderContext deskContext;
|
||||
Core::RenderContext chairContext;
|
||||
Core::RenderContext windowContext;
|
||||
Core::RenderContext shelfContext;
|
||||
Core::RenderContext lampContext;
|
||||
Core::RenderContext windowsillContext;
|
||||
Core::RenderContext paintingContext;
|
||||
Core::RenderContext doorContext;
|
||||
Core::RenderContext doorframeContext;
|
||||
Core::RenderContext floorthingContext;
|
||||
Core::RenderContext booksContext;
|
||||
Core::RenderContext laptopContext;
|
||||
Core::RenderContext pstryczekContext;
|
||||
Core::RenderContext cactusContext;
|
||||
}
|
||||
float r;
|
||||
float r1;
|
||||
float r2;
|
||||
|
||||
namespace texture {
|
||||
GLuint room;
|
||||
@ -66,6 +47,29 @@ namespace texture {
|
||||
GLuint laptop;
|
||||
}
|
||||
|
||||
namespace models {
|
||||
Core::RenderContext roomContext;
|
||||
Core::RenderContext mattressContext;
|
||||
Core::RenderContext bedContext;
|
||||
Core::RenderContext wardrobeContext;
|
||||
Core::RenderContext wardrobeDoorLeftContext;
|
||||
Core::RenderContext wardrobeDoorRightContext;
|
||||
Core::RenderContext deskContext;
|
||||
Core::RenderContext chairContext;
|
||||
Core::RenderContext windowContext;
|
||||
Core::RenderContext shelfContext;
|
||||
Core::RenderContext lampContext;
|
||||
Core::RenderContext windowsillContext;
|
||||
Core::RenderContext paintingContext;
|
||||
Core::RenderContext doorContext;
|
||||
Core::RenderContext doorframeContext;
|
||||
Core::RenderContext floorthingContext;
|
||||
Core::RenderContext booksContext;
|
||||
Core::RenderContext laptopContext;
|
||||
Core::RenderContext pstryczekContext;
|
||||
Core::RenderContext cactusContext;
|
||||
Core::RenderContext sphereContext;
|
||||
}
|
||||
|
||||
GLuint depthMapFBO;
|
||||
GLuint depthMap;
|
||||
@ -73,53 +77,30 @@ GLuint depthMap;
|
||||
GLuint program;
|
||||
GLuint programSun;
|
||||
GLuint programTex;
|
||||
GLuint programDepth;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
Core::RenderContext shipContext;
|
||||
Core::RenderContext sphereContext;
|
||||
|
||||
glm::vec3 sunPos = glm::vec3(-4.740971f, 2.149999f, 0.369280f);
|
||||
glm::vec3 sunDir = glm::vec3(-0.93633f, 0.351106, 0.003226f);
|
||||
glm::vec3 sunColor = glm::vec3(0.9f, 0.9f, 0.7f) * 5;
|
||||
|
||||
//glm::vec3 sunPos = glm::vec3(-3.631, 9.78959, 5.59173);
|
||||
//glm::vec3 sunDir = glm::vec3(-65.985, 7.96228, 33.1559);
|
||||
|
||||
glm::vec3 sunColor = glm::vec3(0.9f, 0.9f, 0.7f)*5;
|
||||
|
||||
// macierz light view point - punkt widzenia światła
|
||||
glm::mat4 lightVP = glm::ortho(-4.f, 2.5f, -2.f, 5.f, 1.0f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(0.479490f, 1.250000f, -2.124680f);
|
||||
glm::vec3 cameraPos = glm::vec3(0.f, 5.f, 0.f);
|
||||
glm::vec3 cameraDir = glm::vec3(-0.354510f, 0.000000f, 0.935054f);
|
||||
|
||||
glm::vec3 spaceshipPos = glm::vec3(0.065808f, 1.250000f, -2.189549f);
|
||||
glm::vec3 spaceshipDir = glm::vec3(-0.490263f, 0.000000f, 0.871578f);
|
||||
GLuint VAO,VBO;
|
||||
|
||||
float aspectRatio = 1.f;
|
||||
|
||||
float exposition = 1.f;
|
||||
|
||||
float r;
|
||||
float r1;
|
||||
float r2;
|
||||
|
||||
std::vector<glm::vec3> quadsPositions;
|
||||
|
||||
glm::vec3 pointlightPos = glm::vec3(0, 2, 0);
|
||||
glm::vec3 pointlightColor = glm::vec3(0.9, 0.6, 0.6);
|
||||
|
||||
glm::vec3 spotlightPos = glm::vec3(0, 0, 0);
|
||||
glm::vec3 spotlightConeDir = glm::vec3(0, 0, 0);
|
||||
|
||||
//glm::vec3 spotlightPos = glm::vec3(-3.631, 9.78959, 5.59173);
|
||||
//glm::vec3 spotlightConeDir = glm::vec3(-65.985, 7.96228, 33.1559);
|
||||
|
||||
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9)*3;
|
||||
glm::vec3 spotlightColor = glm::vec3(0.4, 0.4, 0.9) * 3;
|
||||
float spotlightPhi = 3.14 / 4;
|
||||
|
||||
|
||||
|
||||
float lastTime = -1.f;
|
||||
float deltaTime = 0.f;
|
||||
|
||||
@ -135,8 +116,8 @@ void updateDeltaTime(float time) {
|
||||
}
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir,glm::vec3(0.f,1.f,0.f)));
|
||||
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide,cameraDir));
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 cameraUp = glm::normalize(glm::cross(cameraSide, cameraDir));
|
||||
glm::mat4 cameraRotrationMatrix = glm::mat4({
|
||||
cameraSide.x,cameraSide.y,cameraSide.z,0,
|
||||
cameraUp.x,cameraUp.y,cameraUp.z ,0,
|
||||
@ -151,7 +132,7 @@ glm::mat4 createCameraMatrix()
|
||||
|
||||
glm::mat4 createPerspectiveMatrix()
|
||||
{
|
||||
|
||||
|
||||
glm::mat4 perspectiveMatrix;
|
||||
float n = 0.05;
|
||||
float f = 20.;
|
||||
@ -160,29 +141,27 @@ glm::mat4 createPerspectiveMatrix()
|
||||
perspectiveMatrix = glm::mat4({
|
||||
1,0.,0.,0.,
|
||||
0.,aspectRatio,0.,0.,
|
||||
0.,0.,(f+n) / (n - f),2*f * n / (n - f),
|
||||
0.,0.,(f + n) / (n - f),2 * f * n / (n - f),
|
||||
0.,0.,-1.,0.,
|
||||
});
|
||||
|
||||
|
||||
perspectiveMatrix=glm::transpose(perspectiveMatrix);
|
||||
|
||||
perspectiveMatrix = glm::transpose(perspectiveMatrix);
|
||||
|
||||
return perspectiveMatrix;
|
||||
}
|
||||
|
||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
|
||||
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, /*glm::vec3 color*/GLuint textureID, float roughness, float metallic) {
|
||||
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "exposition"), exposition);
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "roughness"), roughness);
|
||||
glUniform1f(glGetUniformLocation(program, "metallic"), metallic);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
|
||||
//glUniform3f(glGetUniformLocation(program, "color"), color.x, color.y, color.z);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "cameraPos"), cameraPos.x, cameraPos.y, cameraPos.z);
|
||||
|
||||
@ -196,95 +175,16 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
|
||||
glUniform3f(glGetUniformLocation(program, "spotlightPos"), spotlightPos.x, spotlightPos.y, spotlightPos.z);
|
||||
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spotlightColor.x, spotlightColor.y, spotlightColor.z);
|
||||
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spotlightPhi);
|
||||
|
||||
glUniform1f(glGetUniformLocation(program, "shadowMapWidth"), SHADOW_WIDTH);
|
||||
glUniform1f(glGetUniformLocation(program, "shadowMapHeight"), SHADOW_HEIGHT);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "lightVP"), 1, GL_FALSE, (float*)&lightVP);
|
||||
|
||||
Core::SetActiveTexture(textureID, "colorTexture", program, 0);
|
||||
Core::DrawContext(context);
|
||||
|
||||
}
|
||||
|
||||
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID) {
|
||||
glUseProgram(programTex);
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
||||
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
|
||||
Core::DrawContext(context);
|
||||
|
||||
}
|
||||
|
||||
// metoda inicjalizująca mapę głębokości
|
||||
void initDepthMap() {
|
||||
glGenFramebuffers(1, &depthMapFBO);
|
||||
|
||||
glGenTextures(1, &depthMap);
|
||||
glBindTexture(GL_TEXTURE_2D, depthMap);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
|
||||
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap, 0);
|
||||
glDrawBuffer(GL_NONE);
|
||||
glReadBuffer(GL_NONE);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
|
||||
// metoda renderująca obiekt na mapie głębokości
|
||||
void drawObjectDepth(Core::RenderContext& context, glm::mat4 modelMatrix, glm::mat4 viewProjectionMatrix) {
|
||||
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix);
|
||||
Core::DrawContext(context);
|
||||
}
|
||||
|
||||
// renderowanie mapy głębokości
|
||||
void renderShadowapSun(glm::mat4 lightViewPointMatrix) {
|
||||
void renderShadowapSun() {
|
||||
float time = glfwGetTime();
|
||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
||||
//uzupelnij o renderowanie glebokosci do tekstury
|
||||
|
||||
//ustawianie przestrzeni rysowania
|
||||
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
|
||||
//bindowanie FBO
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
|
||||
//czyszczenie mapy głębokości
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
//ustawianie programu depth
|
||||
glUseProgram(programDepth);
|
||||
|
||||
// umieszczenie w mapie wszystkich modeli które mają rzucać cień
|
||||
drawObjectDepth(models::roomContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::bedContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::mattressContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::wardrobeContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::wardrobeDoorLeftContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::wardrobeDoorRightContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::deskContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::chairContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::windowContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::windowsillContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::shelfContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::lampContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::paintingContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::doorContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::doorframeContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::floorthingContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::laptopContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::pstryczekContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::cactusContext, glm::mat4(), lightViewPointMatrix);
|
||||
drawObjectDepth(models::booksContext, glm::mat4(), lightViewPointMatrix);
|
||||
|
||||
glUseProgram(0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, WIDTH, HEIGHT);
|
||||
@ -296,9 +196,7 @@ void renderScene(GLFWwindow* window)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
float time = glfwGetTime();
|
||||
updateDeltaTime(time);
|
||||
|
||||
// wywołanie funkcji renderowania depth mapy
|
||||
renderShadowapSun(lightVP);
|
||||
renderShadowapSun();
|
||||
|
||||
//space lamp
|
||||
glUseProgram(programSun);
|
||||
@ -306,17 +204,10 @@ void renderScene(GLFWwindow* window)
|
||||
glm::mat4 transformation = viewProjectionMatrix * glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1));
|
||||
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniform3f(glGetUniformLocation(programSun, "color"), sunColor.x / 2, sunColor.y / 2, sunColor.z / 2);
|
||||
glUniform1f(glGetUniformLocation(programSun, "exposition"), exposition);
|
||||
Core::DrawContext(sphereContext);
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0);
|
||||
|
||||
drawObjectPBR(sphereContext,
|
||||
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::eulerAngleY(time) * glm::translate(glm::vec3(1.f, 0, 0)) * glm::scale(glm::vec3(0.1f)),
|
||||
glm::vec3(0.5, 0.5, 0.5), 0.7, 0.0);
|
||||
|
||||
glm::mat4 trans;
|
||||
trans = glm::translate(trans, glm::vec3(8.39806f, 0.021251f, 5.95622f));
|
||||
trans = glm::rotate(trans, r * glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
@ -328,45 +219,30 @@ void renderScene(GLFWwindow* window)
|
||||
glm::mat4 transWardrobeDoorL;
|
||||
transWardrobeDoorL = glm::translate(transWardrobeDoorL, glm::vec3(-5.5f, 1.42f, -0.38f));
|
||||
transWardrobeDoorL = glm::rotate(transWardrobeDoorL, r1 * glm::radians(180.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
drawObjectPBR(models::roomContext, glm::mat4(), glm::vec3(0.1, 0.4, 0.6), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::bedContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::mattressContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeDoorLeftContext, transWardrobeDoorL, glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeDoorRightContext, transWardrobeDoorR, glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::deskContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::chairContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::windowContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::windowsillContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::shelfContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::lampContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::paintingContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::doorContext, trans, glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::doorframeContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::floorthingContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::booksContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::cactusContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::laptopContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
drawObjectPBR(models::pstryczekContext, glm::mat4(), glm::vec3(1, 1, 1), 0.8f, 0.0f);
|
||||
|
||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||
glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
||||
spaceshipSide.x,spaceshipSide.y,spaceshipSide.z,0,
|
||||
spaceshipUp.x,spaceshipUp.y,spaceshipUp.z ,0,
|
||||
-spaceshipDir.x,-spaceshipDir.y,-spaceshipDir.z,0,
|
||||
0.,0.,0.,1.,
|
||||
});
|
||||
//drawObjectPBR(sphereContext, glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), glm::vec3(0.2, 0.7, 0.3), 0.3, 0.0);
|
||||
|
||||
drawObjectPBR(shipContext,
|
||||
glm::translate(spaceshipPos) * specshipCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()) * glm::scale(glm::vec3(0.03f)),
|
||||
glm::vec3(0.3, 0.3, 0.5),
|
||||
0.2,1.0
|
||||
);
|
||||
drawObjectPBR(models::roomContext, glm::mat4(), texture::room, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::bedContext, glm::mat4(), texture::bed, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::mattressContext, glm::mat4(), texture::mattress, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeContext, glm::mat4(), texture::wardrobe, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeDoorLeftContext, transWardrobeDoorL, texture::wardrobeDoorLeft, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::wardrobeDoorRightContext, transWardrobeDoorR, texture::wardrobeDoorRight, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::deskContext, glm::mat4(), texture::desk, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::chairContext, glm::mat4(), texture::chair, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::windowContext, glm::mat4(), texture::window, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::windowsillContext, glm::mat4(), texture::windowsill, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::shelfContext, glm::mat4(), texture::shelf, 0.8f, 0.0f);
|
||||
//drawObjectPBR(models::lampContext, glm::mat4(), texture::lamp, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::paintingContext, glm::mat4(), texture::painting, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::doorContext, trans, texture::door, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::doorframeContext, glm::mat4(), texture::doorframe, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::floorthingContext, glm::mat4(), texture::floorthing, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::booksContext, glm::mat4(), texture::books, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::cactusContext, glm::mat4(), texture::cactus, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::laptopContext, glm::mat4(), texture::laptop, 0.8f, 0.0f);
|
||||
drawObjectPBR(models::pstryczekContext, glm::mat4(), texture::pstryczek, 0.8f, 0.0f);
|
||||
|
||||
spotlightPos = spaceshipPos + 0.2 * spaceshipDir;
|
||||
spotlightConeDir = spaceshipDir;
|
||||
|
||||
glUseProgram(0);
|
||||
glfwSwapBuffers(window);
|
||||
@ -395,16 +271,9 @@ void init(GLFWwindow* window)
|
||||
{
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
// enable testowania mapy głębokości
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||
|
||||
// program odpowiadający za generowanie mapy głębokości
|
||||
programDepth = shaderLoader.CreateProgram("shaders/shader_depth.vert", "shaders/shader_depth.frag");
|
||||
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
|
||||
|
||||
loadModelToContext("./models/room.obj", models::roomContext);
|
||||
loadModelToContext("./models/bed.obj", models::bedContext);
|
||||
@ -426,6 +295,7 @@ void init(GLFWwindow* window)
|
||||
loadModelToContext("./models/cactus.obj", models::cactusContext);
|
||||
loadModelToContext("./models/pstryczek.obj", models::pstryczekContext);
|
||||
loadModelToContext("./models/laptop.obj", models::laptopContext);
|
||||
loadModelToContext("./models/sphere.obj", models::sphereContext);
|
||||
|
||||
texture::room = Core::LoadTexture("textures/room.png");
|
||||
texture::oak = Core::LoadTexture("textures/dark_oak.jpg");
|
||||
@ -436,9 +306,18 @@ void init(GLFWwindow* window)
|
||||
texture::lamp = Core::LoadTexture("textures/lamp.png");
|
||||
texture::painting = Core::LoadTexture("textures/painting.png");
|
||||
texture::door = Core::LoadTexture("textures/door.png");
|
||||
|
||||
// inicjalizacja mapy głębokości
|
||||
initDepthMap();
|
||||
texture::wardrobe = Core::LoadTexture("textures/dark_oak.jpg");
|
||||
texture::wardrobeDoorLeft = Core::LoadTexture("textures/dark_oak.jpg");
|
||||
texture::wardrobeDoorRight = Core::LoadTexture("textures/dark_oak.jpg");
|
||||
texture::desk = Core::LoadTexture("textures/dark_oak.jpg");
|
||||
texture::mattress = Core::LoadTexture("textures/white.jpg");
|
||||
texture::doorframe = Core::LoadTexture("textures/white.jpg");
|
||||
texture::shelf = Core::LoadTexture("textures/white.jpg");
|
||||
texture::pstryczek = Core::LoadTexture("textures/white.jpg");
|
||||
texture::floorthing = Core::LoadTexture("textures/white.jpg");
|
||||
texture::window = Core::LoadTexture("textures/white.jpg");
|
||||
texture::windowsill = Core::LoadTexture("textures/white.jpg");
|
||||
texture::chair = Core::LoadTexture("textures/black.jpg");
|
||||
|
||||
}
|
||||
|
||||
@ -450,42 +329,30 @@ void shutdown(GLFWwindow* window)
|
||||
//obsluga wejscia
|
||||
void processInput(GLFWwindow* window)
|
||||
{
|
||||
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f,1.f,0.f)));
|
||||
glm::vec3 spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
glm::vec3 cameraUp = glm::vec3(0.f, 1.f, 0.f);
|
||||
float angleSpeed = 0.05f * deltaTime * 60;
|
||||
float moveSpeed = 0.05f * deltaTime * 60;
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipDir * moveSpeed;
|
||||
cameraPos += cameraDir * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipDir * moveSpeed;
|
||||
cameraPos -= cameraDir * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_X) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipSide * moveSpeed;
|
||||
cameraPos += cameraSide * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_Z) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipSide * moveSpeed;
|
||||
cameraPos -= cameraSide * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS)
|
||||
spaceshipPos += spaceshipUp * moveSpeed;
|
||||
cameraPos += cameraUp * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_E) == GLFW_PRESS)
|
||||
spaceshipPos -= spaceshipUp * moveSpeed;
|
||||
cameraPos -= cameraUp * moveSpeed;
|
||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
cameraDir = glm::vec3(glm::eulerAngleY(angleSpeed) * glm::vec4(cameraDir, 0));
|
||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||
spaceshipDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(spaceshipDir, 0));
|
||||
cameraDir = glm::vec3(glm::eulerAngleY(-angleSpeed) * glm::vec4(cameraDir, 0));
|
||||
|
||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
cameraDir = spaceshipDir;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_1) == GLFW_PRESS)
|
||||
exposition -= 0.05;
|
||||
if (glfwGetKey(window, GLFW_KEY_2) == GLFW_PRESS)
|
||||
exposition += 0.05;
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_3) == GLFW_PRESS) {
|
||||
printf("spaceshipPos = glm::vec3(%ff, %ff, %ff);\n", spaceshipPos.x, spaceshipPos.y, spaceshipPos.z);
|
||||
printf("spaceshipDir = glm::vec3(%ff, %ff, %ff);\n", spaceshipDir.x, spaceshipDir.y, spaceshipDir.z);
|
||||
}
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_7)) {
|
||||
if (r < -0.55) { r = -0.55; }
|
||||
@ -507,12 +374,8 @@ void processInput(GLFWwindow* window)
|
||||
if (r1 >= 0) { r1 = 0; }
|
||||
else { r1 = r1 + 0.01; }
|
||||
if (r2 <= 0) { r2 = 0; }
|
||||
else { r2 = r2 - 0.01; }
|
||||
else { r2 = r2 - 0.01; }
|
||||
}
|
||||
|
||||
|
||||
//cameraDir = glm::normalize(-cameraPos);
|
||||
|
||||
}
|
||||
|
||||
// funkcja jest glowna petla
|
||||
|
BIN
cw 9/textures/black.jpg
Normal file
BIN
cw 9/textures/black.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 73 KiB |
BIN
cw 9/textures/red.jpg
Normal file
BIN
cw 9/textures/red.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
cw 9/textures/white.jpg
Normal file
BIN
cw 9/textures/white.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
Loading…
Reference in New Issue
Block a user