diff --git a/grk/project/grk-project.vcxproj b/grk/project/grk-project.vcxproj
index e58f79e..94f6e28 100644
--- a/grk/project/grk-project.vcxproj
+++ b/grk/project/grk-project.vcxproj
@@ -48,6 +48,8 @@
+
+
diff --git a/grk/project/grk-project.vcxproj.filters b/grk/project/grk-project.vcxproj.filters
index 778df94..94a14a2 100644
--- a/grk/project/grk-project.vcxproj.filters
+++ b/grk/project/grk-project.vcxproj.filters
@@ -130,5 +130,11 @@
Shader Files
+
+ Shader Files
+
+
+ Shader Files
+
\ No newline at end of file
diff --git a/grk/project/models/cube.obj b/grk/project/models/cube.obj
new file mode 100644
index 0000000..4eb693e
--- /dev/null
+++ b/grk/project/models/cube.obj
@@ -0,0 +1,40 @@
+# Blender v2.90.0 OBJ File: ''
+# www.blender.org
+mtllib cube.mtl
+o Cube
+v -10.000000 -10.000000 10.000000
+v -10.000000 10.000000 10.000000
+v -10.000000 -10.000000 -10.000000
+v -10.000000 10.000000 -10.000000
+v 10.000000 -10.000000 10.000000
+v 10.000000 10.000000 10.000000
+v 10.000000 -10.000000 -10.000000
+v 10.000000 10.000000 -10.000000
+vt 0.375000 0.000000
+vt 0.625000 0.000000
+vt 0.625000 0.250000
+vt 0.375000 0.250000
+vt 0.625000 0.500000
+vt 0.375000 0.500000
+vt 0.625000 0.750000
+vt 0.375000 0.750000
+vt 0.625000 1.000000
+vt 0.375000 1.000000
+vt 0.125000 0.500000
+vt 0.125000 0.750000
+vt 0.875000 0.500000
+vt 0.875000 0.750000
+vn -1.0000 0.0000 0.0000
+vn 0.0000 0.0000 -1.0000
+vn 1.0000 0.0000 0.0000
+vn 0.0000 0.0000 1.0000
+vn 0.0000 -1.0000 0.0000
+vn 0.0000 1.0000 0.0000
+usemtl _PBR
+s 1
+f 1/1/1 2/2/1 4/3/1 3/4/1
+f 3/4/2 4/3/2 8/5/2 7/6/2
+f 7/6/3 8/5/3 6/7/3 5/8/3
+f 5/8/4 6/7/4 2/9/4 1/10/4
+f 3/11/5 7/6/5 5/8/5 1/12/5
+f 8/5/6 4/13/6 2/14/6 6/7/6
diff --git a/grk/project/shaders/shader_skybox.frag b/grk/project/shaders/shader_skybox.frag
new file mode 100644
index 0000000..2253ffc
--- /dev/null
+++ b/grk/project/shaders/shader_skybox.frag
@@ -0,0 +1,12 @@
+#version 430 core
+
+uniform samplerCube skybox;
+
+in vec3 texCoord;
+
+out vec4 out_color;
+
+void main()
+{
+ out_color = texture(skybox,texCoord);
+}
\ No newline at end of file
diff --git a/grk/project/shaders/shader_skybox.vert b/grk/project/shaders/shader_skybox.vert
new file mode 100644
index 0000000..90d66bd
--- /dev/null
+++ b/grk/project/shaders/shader_skybox.vert
@@ -0,0 +1,13 @@
+#version 430 core
+
+layout(location = 0) in vec3 vertexPosition;
+
+uniform mat4 transformation;
+
+out vec3 texCoord;
+
+void main()
+{
+ texCoord = vertexPosition;
+ gl_Position = transformation * vec4(vertexPosition, 1.0);
+}
\ No newline at end of file
diff --git a/grk/project/src/Render_Utils.cpp b/grk/project/src/Render_Utils.cpp
index d725cd4..b1cc537 100644
--- a/grk/project/src/Render_Utils.cpp
+++ b/grk/project/src/Render_Utils.cpp
@@ -188,4 +188,17 @@ void Core::drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, gl
glUniform3f(glGetUniformLocation(program, "spotlightColor"), spaceship->spotlightColor.x, spaceship->spotlightColor.y, spaceship->spotlightColor.z);
glUniform1f(glGetUniformLocation(program, "spotlightPhi"), spaceship->spotlightPhi);
Core::DrawContext(context);
+}
+void Core::drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program) {
+ Spaceship* spaceship = Spaceship::getInstance();
+ glDisable(GL_DEPTH_TEST);
+ glUseProgram(program);
+ glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * spaceship->createCameraMatrix();
+ glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
+ glUniformMatrix4fv(glGetUniformLocation(program, "transformation"), 1, GL_FALSE, (float*)&transformation);
+
+ glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
+ Core::DrawContext(context);
+ glEnable(GL_DEPTH_TEST);
+
}
\ No newline at end of file
diff --git a/grk/project/src/Render_Utils.h b/grk/project/src/Render_Utils.h
index d49c5a8..5c876c6 100644
--- a/grk/project/src/Render_Utils.h
+++ b/grk/project/src/Render_Utils.h
@@ -69,6 +69,7 @@ namespace Core
void DrawVertexArray(const VertexData & data);
void DrawContext(RenderContext& context);
+ void drawSkybox(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint program);
glm::mat4 createPerspectiveMatrix();
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic, GLuint program);
diff --git a/grk/project/src/Texture.cpp b/grk/project/src/Texture.cpp
index 2548b13..0e1a352 100644
--- a/grk/project/src/Texture.cpp
+++ b/grk/project/src/Texture.cpp
@@ -28,6 +28,43 @@ GLuint Core::LoadTexture( const char * filepath )
return id;
}
+GLuint Core::LoadCubemap(const std::vector& faces)
+{
+ GLuint textureID;
+ glGenTextures(1, &textureID);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
+
+ int width, height;
+ unsigned char* data;
+
+ for (unsigned int i = 0; i < faces.size(); i++)
+ {
+ data = SOIL_load_image(("textures/skybox/" + faces[i]).c_str(), &width, &height, 0, SOIL_LOAD_RGBA);
+
+ if (data)
+ {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ SOIL_free_image_data(data);
+ }
+ else
+ {
+ std::cerr << "Cubemap tex failed to load at path:" << faces[i] << std::endl;
+ SOIL_free_image_data(data);
+ glDeleteTextures(1, &textureID);
+ return 0;
+ }
+ }
+
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+
+ return textureID;
+}
+
+
void Core::SetActiveTexture(GLuint textureID, const char * shaderVariableName, GLuint programID, int textureUnit)
{
diff --git a/grk/project/src/Texture.h b/grk/project/src/Texture.h
index 910228e..b2c9924 100644
--- a/grk/project/src/Texture.h
+++ b/grk/project/src/Texture.h
@@ -2,10 +2,13 @@
#include "glew.h"
#include "freeglut.h"
+#include
+#include
namespace Core
{
GLuint LoadTexture(const char * filepath);
+ GLuint LoadCubemap(const std::vector& faces);
// textureID - identyfikator tekstury otrzymany z funkcji LoadTexture
// shaderVariableName - nazwa zmiennej typu 'sampler2D' w shaderze, z ktora ma zostac powiazana tekstura
diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp
index ea9fefb..4c3a850 100644
--- a/grk/project/src/ex_9_1.hpp
+++ b/grk/project/src/ex_9_1.hpp
@@ -5,10 +5,11 @@
#include
#include
#include
+#include
#include "Shader_Loader.h"
#include "Render_Utils.h"
-//#include "Texture.h"
+#include "texture.h"
#include "Box.cpp"
#include
@@ -29,6 +30,10 @@ namespace models {
Core::RenderContext marbleBustContext;
Core::RenderContext spaceshipContext;
Core::RenderContext sphereContext;
+ Core::RenderContext cubeContext;
+}
+namespace texture {
+ GLuint cubemapTexture;
}
GLuint depthMapFBO;
@@ -38,6 +43,7 @@ GLuint program;
GLuint programSun;
GLuint programTest;
GLuint programTex;
+GLuint programCubemap;
Core::Shader_Loader shaderLoader;
@@ -75,7 +81,6 @@ void renderShadowapSun() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
}
-
void renderScene(GLFWwindow* window)
{
glClearColor(0.4f, 0.4f, 0.8f, 1.0f);
@@ -84,6 +89,9 @@ void renderScene(GLFWwindow* window)
updateDeltaTime(time);
renderShadowapSun();
+ drawSkybox(models::cubeContext, glm::translate(glm::mat4(), spaceship->cameraPos), texture::cubemapTexture, programCubemap);
+
+
//space lamp
glUseProgram(programSun);
@@ -165,7 +173,6 @@ void createSuns() {
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(200, 150, -100), glm::vec3(0.03633f, 0.151106, 0.103226f), glm::vec3(0.6f, 0.2f, 0.9f), 3.9));
suns.push_back(&Sun(programSun, models::sphereContext, glm::vec3(-150, -100, -50), glm::vec3(0.83633f, -0.251106, -0.123226f), glm::vec3(0.7f, 0.5f, 0.8f), 4.1));*/
}
-
void init(GLFWwindow* window)
{
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
@@ -174,15 +181,33 @@ void init(GLFWwindow* window)
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
-
- //loadModelToContext("./models/sphere.obj", sphereContext);
- //loadModelToContext("./models/spaceship.obj", spaceship.context);
-
-
+ programCubemap = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
loadModelToContext("./models/marbleBust.obj", models::marbleBustContext);
loadModelToContext("./models/spaceship.obj", models::spaceshipContext);
loadModelToContext("./models/sphere.obj", models::sphereContext);
+ loadModelToContext("./models/cube.obj", models::cubeContext);
+
+ /*std::vector cubeFaces = {
+ "space_rt.png",
+ "space_lf.png",
+ "space_up.png",
+ "space_dn.png",
+ "space_bk.png",
+ "space_ft.png"
+ };*/
+
+ std::vector cubeFaces = {
+ "bkg2_right1.png",
+ "bkg2_left2.png",
+ "bkg2_top3.png",
+ "bkg2_bottom4.png",
+ "bkg2_front5.png",
+ "bkg2_back6.png"
+ };
+
+ texture::cubemapTexture = Core::LoadCubemap(cubeFaces);
+
createSuns();
}
diff --git a/grk/project/textures/skybox/bkg2_back6.png b/grk/project/textures/skybox/bkg2_back6.png
new file mode 100644
index 0000000..b685b78
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_back6.png differ
diff --git a/grk/project/textures/skybox/bkg2_bottom4.png b/grk/project/textures/skybox/bkg2_bottom4.png
new file mode 100644
index 0000000..728a4ae
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_bottom4.png differ
diff --git a/grk/project/textures/skybox/bkg2_front5.png b/grk/project/textures/skybox/bkg2_front5.png
new file mode 100644
index 0000000..9a2e256
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_front5.png differ
diff --git a/grk/project/textures/skybox/bkg2_left2.png b/grk/project/textures/skybox/bkg2_left2.png
new file mode 100644
index 0000000..7508dd4
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_left2.png differ
diff --git a/grk/project/textures/skybox/bkg2_right1.png b/grk/project/textures/skybox/bkg2_right1.png
new file mode 100644
index 0000000..18f9057
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_right1.png differ
diff --git a/grk/project/textures/skybox/bkg2_top3.png b/grk/project/textures/skybox/bkg2_top3.png
new file mode 100644
index 0000000..410750b
Binary files /dev/null and b/grk/project/textures/skybox/bkg2_top3.png differ
diff --git a/grk/project/textures/skybox/space_bk.png b/grk/project/textures/skybox/space_bk.png
new file mode 100644
index 0000000..8366b78
Binary files /dev/null and b/grk/project/textures/skybox/space_bk.png differ
diff --git a/grk/project/textures/skybox/space_dn.png b/grk/project/textures/skybox/space_dn.png
new file mode 100644
index 0000000..4191f53
Binary files /dev/null and b/grk/project/textures/skybox/space_dn.png differ
diff --git a/grk/project/textures/skybox/space_ft.png b/grk/project/textures/skybox/space_ft.png
new file mode 100644
index 0000000..e7b65cb
Binary files /dev/null and b/grk/project/textures/skybox/space_ft.png differ
diff --git a/grk/project/textures/skybox/space_lf.png b/grk/project/textures/skybox/space_lf.png
new file mode 100644
index 0000000..7a67e73
Binary files /dev/null and b/grk/project/textures/skybox/space_lf.png differ
diff --git a/grk/project/textures/skybox/space_rt.png b/grk/project/textures/skybox/space_rt.png
new file mode 100644
index 0000000..5aba731
Binary files /dev/null and b/grk/project/textures/skybox/space_rt.png differ
diff --git a/grk/project/textures/skybox/space_up.png b/grk/project/textures/skybox/space_up.png
new file mode 100644
index 0000000..61626da
Binary files /dev/null and b/grk/project/textures/skybox/space_up.png differ