add skybox
This commit is contained in:
parent
870aec4a9a
commit
fbcc0ed3f3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,7 +2,7 @@
|
||||
<Project>
|
||||
<ProjectOutputs>
|
||||
<ProjectOutput>
|
||||
<FullPath>C:\Users\Tomek\Source\Repos\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe</FullPath>
|
||||
<FullPath>C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe</FullPath>
|
||||
</ProjectOutput>
|
||||
</ProjectOutputs>
|
||||
<ContentFiles />
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.30.30705:TargetPlatformVersion=10.0.19041.0:
|
||||
Debug|Win32|C:\Users\Tomek\Source\Repos\GrafikaProjekt\GrafikaProjekt\|
|
||||
Debug|Win32|C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\|
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1 @@
|
||||
main.cpp
|
||||
C:\Users\Tomek\source\repos\GrafikaProjekt\GrafikaProjekt\pliki\src\main.cpp(145,12): warning C4244: "argument": konwersja z "time_t" do "unsigned int", możliwa utrata danych
|
||||
Camera.obj : warning LNK4075: zignorowano opcję „/EDITANDCONTINUE” z powodu określenia opcji „/INCREMENTAL:NO”
|
||||
projekt.vcxproj -> C:\Users\Tomek\Source\Repos\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe
|
||||
projekt.vcxproj -> C:\Users\luksli\Desktop\GrafikaProjekt\GrafikaProjekt\Debug\grk-cw6.exe
|
||||
|
BIN
GrafikaProjekt/pliki/Debug/stb_imag.obj
Normal file
BIN
GrafikaProjekt/pliki/Debug/stb_imag.obj
Normal file
Binary file not shown.
BIN
GrafikaProjekt/pliki/Debug/stb_image.obj
Normal file
BIN
GrafikaProjekt/pliki/Debug/stb_image.obj
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -32,11 +32,12 @@
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug.h" />
|
||||
<ClInclude Include="src\SOIL\stbi_DDS_aug_c.h" />
|
||||
<ClInclude Include="src\SOIL\stb_image_aug.h" />
|
||||
<ClInclude Include="src\stb_image.h" />
|
||||
<ClInclude Include="src\Texture.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_color.frag" />
|
||||
<None Include="shaders\shader_color.vert" />
|
||||
<None Include="shaders\shader_cubemap.frag" />
|
||||
<None Include="shaders\shader_cubemap.vert" />
|
||||
<None Include="shaders\shader_tex.frag" />
|
||||
<None Include="shaders\shader_tex.vert" />
|
||||
</ItemGroup>
|
||||
|
@ -83,19 +83,22 @@
|
||||
<ClInclude Include="src\Texture.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\stb_image.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="shaders\shader_color.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_color.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_tex.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_cubemap.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_cubemap.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,13 +0,0 @@
|
||||
#version 410 core
|
||||
|
||||
uniform vec3 objectColor;
|
||||
uniform vec3 lightDir;
|
||||
|
||||
in vec3 interpNormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = normalize(interpNormal);
|
||||
float diffuse = max(dot(normal, -lightDir), 0.0);
|
||||
gl_FragColor = vec4(objectColor * diffuse, 1.0);
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
#version 410 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
layout(location = 1) in vec3 vertexNormal;
|
||||
layout(location = 2) in vec2 vertexTexCoord;
|
||||
|
||||
uniform mat4 modelViewProjectionMatrix;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
out vec3 interpNormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProjectionMatrix * vec4(vertexPosition, 1.0);
|
||||
interpNormal = (modelMatrix * vec4(vertexNormal, 0.0)).xyz;
|
||||
}
|
12
GrafikaProjekt/pliki/shaders/shader_cubemap.frag
Normal file
12
GrafikaProjekt/pliki/shaders/shader_cubemap.frag
Normal file
@ -0,0 +1,12 @@
|
||||
#version 410 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec3 TexCoords;
|
||||
|
||||
uniform samplerCube skybox;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(skybox, TexCoords);
|
||||
}
|
14
GrafikaProjekt/pliki/shaders/shader_cubemap.vert
Normal file
14
GrafikaProjekt/pliki/shaders/shader_cubemap.vert
Normal file
@ -0,0 +1,14 @@
|
||||
#version 410 core
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
out vec3 TexCoords;
|
||||
|
||||
uniform mat4 projection;
|
||||
uniform mat4 view;
|
||||
|
||||
void main()
|
||||
{
|
||||
TexCoords = aPos;
|
||||
gl_Position = projection * view * vec4(aPos, 1.0);
|
||||
}
|
@ -5,13 +5,14 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "Shader_Loader.h"
|
||||
#include "Render_Utils.h"
|
||||
#include "Camera.h"
|
||||
#include "Texture.h"
|
||||
|
||||
GLuint programColor;
|
||||
GLuint programCubemap;
|
||||
GLuint programTexture;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
@ -20,6 +21,50 @@ Core::RenderContext shipContext;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext fishContext;
|
||||
|
||||
float skyboxVertices[] = {
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
-10.0f, -10.0f, -10.0f,
|
||||
10.0f, -10.0f, -10.0f,
|
||||
10.0f, -10.0f, -10.0f,
|
||||
10.0f, 10.0f, -10.0f,
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
-10.0f, -10.0f, -10.0f,
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
-10.0f, 10.0f, 10.0f,
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
|
||||
10.0f, -10.0f, -10.0f,
|
||||
10.0f, -10.0f, 10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
10.0f, 10.0f, -10.0f,
|
||||
10.0f, -10.0f, -10.0f,
|
||||
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
-10.0f, 10.0f, 10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
10.0f, -10.0f, 10.0f,
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
10.0f, 10.0f, -10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
10.0f, 10.0f, 10.0f,
|
||||
-10.0f, 10.0f, 10.0f,
|
||||
-10.0f, 10.0f, -10.0f,
|
||||
|
||||
-10.0f, -10.0f, -10.0f,
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
10.0f, -10.0f, -10.0f,
|
||||
10.0f, -10.0f, -10.0f,
|
||||
-10.0f, -10.0f, 10.0f,
|
||||
10.0f, -10.0f, 10.0f
|
||||
};
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(0, 0, 5);
|
||||
glm::vec3 cameraDir; // Wektor "do przodu" kamery
|
||||
glm::vec3 cameraSide; // Wektor "w bok" kamery
|
||||
@ -27,6 +72,7 @@ glm::vec3 cameraUp;
|
||||
float cameraAngle = 0;
|
||||
|
||||
int lastMouseX, lastMouseY, mouseX, mouseY;
|
||||
unsigned int cubemapTexture;
|
||||
|
||||
glm::mat4 cameraMatrix, perspectiveMatrix;
|
||||
|
||||
@ -34,6 +80,8 @@ glm::vec3 lightDir = glm::normalize(glm::vec3(1.0f, -0.9f, -1.0f));
|
||||
|
||||
glm::quat rotation = glm::quat(1, 0, 0, 0);
|
||||
|
||||
unsigned int skyboxVAO, skyboxVBO;
|
||||
|
||||
GLuint textureAsteroid;
|
||||
GLuint textureSubmarine;
|
||||
GLuint textureFish1;
|
||||
@ -72,22 +120,37 @@ glm::mat4 createCameraMatrix()
|
||||
return Core::createViewMatrixQuat(cameraPos, rotation);
|
||||
}
|
||||
|
||||
void drawObjectColor(Core::RenderContext context, glm::mat4 modelMatrix, glm::vec3 color)
|
||||
unsigned int loadCubemap()
|
||||
{
|
||||
GLuint program = programColor;
|
||||
unsigned int textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
||||
std::string faces[] = { "textures/uw_rt.png", "textures/uw_lf.png" , "textures/uw_up.png" , "textures/uw_dn.png" , "textures/uw_bk.png", "textures/uw_ft.png" };
|
||||
|
||||
glUseProgram(program);
|
||||
int width, height, nrChannels;
|
||||
for (unsigned int i = 0; i < sizeof(faces) / sizeof(*faces); i++)
|
||||
{
|
||||
unsigned char* data = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
|
||||
if (data)
|
||||
{
|
||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
|
||||
0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data
|
||||
);
|
||||
stbi_image_free(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Cubemap tex failed to load at path: " << faces[i] << std::endl;
|
||||
stbi_image_free(data);
|
||||
}
|
||||
}
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_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);
|
||||
|
||||
glUniform3f(glGetUniformLocation(program, "objectColor"), color.x, color.y, color.z);
|
||||
glUniform3f(glGetUniformLocation(program, "lightDir"), lightDir.x, lightDir.y, lightDir.z);
|
||||
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelViewProjectionMatrix"), 1, GL_FALSE, (float*)&transformation);
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
|
||||
|
||||
Core::DrawContext(context);
|
||||
|
||||
glUseProgram(0);
|
||||
return textureID;
|
||||
}
|
||||
|
||||
void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuint textureId)
|
||||
@ -107,6 +170,30 @@ void drawObjectTexture(Core::RenderContext context, glm::mat4 modelMatrix, GLuin
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void drawObjectCubemap(glm::mat4 modelMatrix, unsigned int textureId)
|
||||
{
|
||||
GLuint program = programCubemap;
|
||||
|
||||
glUseProgram(program);
|
||||
|
||||
glDepthFunc(GL_LEQUAL); // change depth function so depth test passes when values are equal to depth buffer's content
|
||||
//view = glm::mat4(glm::mat3(camera.GetViewMatrix())); // remove translation from the view matrix
|
||||
glm::mat4 transformation = perspectiveMatrix * cameraMatrix * modelMatrix;
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "view"), 1, GL_FALSE, (float*)&glm::mat4());
|
||||
glUniformMatrix4fv(glGetUniformLocation(program, "projection"), 1, GL_FALSE, (float*)&transformation);
|
||||
//skyboxShader.setMat4("view", view);
|
||||
//skyboxShader.setMat4("projection", projection);
|
||||
glBindVertexArray(skyboxVAO);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapTexture);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glBindVertexArray(0);
|
||||
glDepthFunc(GL_LESS);
|
||||
|
||||
glUseProgram(0);
|
||||
}
|
||||
|
||||
void renderScene()
|
||||
{
|
||||
// Aktualizacja macierzy widoku i rzutowania
|
||||
@ -120,6 +207,8 @@ void renderScene()
|
||||
glm::mat4 shipModelMatrix = glm::translate(cameraPos + cameraDir * 0.5f) * glm::mat4_cast(glm::inverse(rotation)) * shipInitialTransformation;
|
||||
//drawObjectColor(shipContext, shipModelMatrix, glm::vec3(0.6f));
|
||||
|
||||
drawObjectCubemap(glm::translate(glm::vec3(0, 0, 0)), cubemapTexture);
|
||||
|
||||
drawObjectTexture(shipContext, shipModelMatrix, textureSubmarine);
|
||||
drawObjectTexture(sphereContext, glm::translate(glm::vec3(0, -1.2, 0)), textureAsteroid);
|
||||
drawObjectTexture(fishContext, glm::translate(glm::vec3(0, 0, 0)), textureFish1);
|
||||
@ -144,18 +233,27 @@ void init()
|
||||
{
|
||||
srand(time(0));
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
programColor = shaderLoader.CreateProgram("shaders/shader_color.vert", "shaders/shader_color.frag");
|
||||
programCubemap = shaderLoader.CreateProgram("shaders/shader_cubemap.vert", "shaders/shader_cubemap.frag");
|
||||
programTexture = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
|
||||
loadModelToContext("models/submarine.obj", shipContext);
|
||||
loadModelToContext("models/teren1.obj", sphereContext);
|
||||
loadModelToContext("models/fish1.obj", fishContext);
|
||||
textureAsteroid = Core::LoadTexture("textures/sub.png");
|
||||
textureSubmarine = Core::LoadTexture("textures/sub.png");
|
||||
cubemapTexture = loadCubemap();
|
||||
|
||||
glGenVertexArrays(1, &skyboxVAO);
|
||||
glGenBuffers(1, &skyboxVBO);
|
||||
glBindVertexArray(skyboxVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, skyboxVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
}
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
shaderLoader.DeleteProgram(programColor);
|
||||
shaderLoader.DeleteProgram(programCubemap);
|
||||
shaderLoader.DeleteProgram(programTexture);
|
||||
}
|
||||
|
||||
|
7897
GrafikaProjekt/pliki/src/stb_image.h
Normal file
7897
GrafikaProjekt/pliki/src/stb_image.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
GrafikaProjekt/pliki/textures/uw_bk.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_bk.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
BIN
GrafikaProjekt/pliki/textures/uw_dn.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_dn.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
GrafikaProjekt/pliki/textures/uw_ft.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_ft.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
GrafikaProjekt/pliki/textures/uw_lf.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_lf.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
GrafikaProjekt/pliki/textures/uw_rt.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_rt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
BIN
GrafikaProjekt/pliki/textures/uw_up.png
Normal file
BIN
GrafikaProjekt/pliki/textures/uw_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 835 KiB |
Loading…
Reference in New Issue
Block a user