dodany skybox

This commit is contained in:
mikgaw@st.amu.edu.pl 2024-02-20 21:33:03 +01:00
parent dc63bd23de
commit 3a3bf5eb4b
21 changed files with 96 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,8 +2,8 @@
main.cpp
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\shared\minwindef.h(130,1): warning C4005: "APIENTRY": ponowna definicja makra
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\dependencies\glfw-3.3.8.bin.WIN32\include\GLFW\glfw3.h(123,1): message : zobacz poprzednią definicję „APIENTRY”
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(76,10): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(147,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(78,10): warning C4305: "inicjowanie": obcięcie z "double" do "float"
D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\projekt_grk\src\ex_7_1.hpp(154,13): warning C4244: "inicjowanie": konwersja z "double" do "float", możliwa utrata danych
Box.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
LINK : warning LNK4098: domyślna biblioteka „MSVCRT” powoduje konflikt z innymi bibliotekami; użyj opcji /NODEFAULTLIB:biblioteka
grk-cw7.vcxproj -> D:\STUDIA_sem5\GRAFIKA-PROJEKT\grk\Debug\projekt_grk.exe

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -41,10 +41,12 @@
<None Include="shaders\shader_5_1.vert" />
<None Include="shaders\shader_5_1_tex.frag" />
<None Include="shaders\shader_5_1_tex.vert" />
<None Include="shaders\shader_5_1_tex_copy.frag" />
<None Include="shaders\shader_5_1_tex_copy.vert" />
<None Include="shaders\shader_5_sun.frag" />
<None Include="shaders\shader_5_sun.vert" />
<None Include="shader_5_1_tex_copy.frag" />
<None Include="shader_5_1_tex_copy.vert" />
<None Include="shaders\shader_skybox.frag" />
<None Include="shaders\shader_skybox.vert" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F2FC2E8F-CBA6-49D7-8B73-4BFBCB64D310}</ProjectGuid>

View File

@ -109,10 +109,16 @@
<None Include="shaders\shader_5_1_tex.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shader_5_1_tex_copy.frag">
<None Include="shaders\shader_5_1_tex_copy.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shader_5_1_tex_copy.vert">
<None Include="shaders\shader_5_1_tex_copy.vert">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_skybox.frag">
<Filter>Shader Files</Filter>
</None>
<None Include="shaders\shader_skybox.vert">
<Filter>Shader Files</Filter>
</None>
</ItemGroup>

View File

@ -0,0 +1,12 @@
#version 430 core
uniform samplerCube skybox;
in vec3 texCoord;
out vec4 out_color;
void main()
{
out_color = texture(skybox,texCoord);
}

View File

@ -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);
}

View File

@ -14,16 +14,15 @@
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
#include "SOIL/SOIL.h"
namespace texture {
//GLuint clouds;
GLuint earth;
GLuint moon;
GLuint ship;
GLuint sun;
GLuint mars;
GLuint grid;
@ -38,10 +37,12 @@ GLuint programSun;
GLuint programTex;
GLuint programEarth;
GLuint programProcTex;
GLuint programSkyBox;
Core::Shader_Loader shaderLoader;
Core::RenderContext shipContext;
Core::RenderContext sphereContext;
Core::RenderContext cubeContext;
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
@ -51,6 +52,7 @@ glm::vec3 spaceshipDir = glm::vec3(1.f, 0.f, 0.f);
GLuint VAO,VBO;
float aspectRatio = 1.f;
unsigned int textureID;
glm::mat4 createCameraMatrix()
@ -102,6 +104,7 @@ void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::v
Core::DrawContext(context);
}
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
GLuint prog = programTex;
glUseProgram(prog);
@ -116,7 +119,6 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
}
void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID)
{
GLuint prog = programSun;
@ -129,6 +131,19 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture
Core::DrawContext(context);
}
void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
glDisable(GL_DEPTH_TEST);
glUseProgram(programSkyBox);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniformMatrix4fv(glGetUniformLocation(programSkyBox, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
glUniform3f(glGetUniformLocation(programSkyBox, "lightPos"), 0, 0, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
Core::DrawContext(context);
glEnable(GL_DEPTH_TEST);
}
void renderScene(GLFWwindow* window)
@ -138,16 +153,17 @@ void renderScene(GLFWwindow* window)
glm::mat4 transformation;
float time = glfwGetTime();
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
drawSun(sphereContext, glm::mat4(), texture::sun);
drawObjectTexture(sphereContext, glm::mat4(), texture::ship, texture::asteroidNormal);
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)), texture::earth, texture::earthNormal);
drawObjectTexture(sphereContext, 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)), texture::moon, texture::asteroidNormal);
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({
@ -195,19 +211,54 @@ void init(GLFWwindow* window)
programEarth = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
programProcTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship.obj", shipContext);
loadModelToContext("./models/cube.obj", cubeContext);
texture::earth = Core::LoadTexture("textures/earth2.png");
texture::ship = Core::LoadTexture("textures/spaceship.jpg");
texture::moon = Core::LoadTexture("textures/moon.jpg");
texture::sun = Core::LoadTexture("textures/sun.jpg");
texture::mars = Core::LoadTexture("textures/mars.jpg");
texture::earthNormal = Core::LoadTexture("textures/earth2_normals.png");
texture::shipNormal = Core::LoadTexture("textures/spaceship_normal.jpg");
texture::asteroidNormal = Core::LoadTexture("textures/moon_normal.jpg");
//tutaj skybox
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
std::vector<std::string> filepaths = {
"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"
};
int w, h;
unsigned char* data;
for (unsigned int i = 0; i < 6; i++)
{
data = SOIL_load_image(filepaths[i].c_str(), &w, &h, 0, SOIL_LOAD_RGBA);
glTexImage2D(
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data
);
}
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);
}
void shutdown(GLFWwindow* window)

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 KiB