initial bloom
This commit is contained in:
parent
6e4a9fbc06
commit
8c0be0a3fc
@ -45,6 +45,10 @@
|
||||
<None Include="shaders\shader_5_sun.vert" />
|
||||
<None Include="shaders\shader_5_tex.frag" />
|
||||
<None Include="shaders\shader_5_tex.vert" />
|
||||
<None Include="shaders\shader_bloom.frag" />
|
||||
<None Include="shaders\shader_bloom.vert" />
|
||||
<None Include="shaders\shader_quad.frag" />
|
||||
<None Include="shaders\shader_quad.vert" />
|
||||
<None Include="shaders\shader_skybox.frag" />
|
||||
<None Include="shaders\shader_skybox.vert" />
|
||||
</ItemGroup>
|
||||
|
@ -121,5 +121,17 @@
|
||||
<None Include="shaders\shader_5_tex.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_bloom.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_quad.vert">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
<None Include="shaders\shader_quad.frag">
|
||||
<Filter>Shader Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
16
cw 7/models/test.obj
Normal file
16
cw 7/models/test.obj
Normal file
@ -0,0 +1,16 @@
|
||||
# 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,5 +1,8 @@
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BloomColor;
|
||||
|
||||
float AMBIENT = 0.1;
|
||||
|
||||
uniform vec3 color;
|
||||
@ -12,20 +15,25 @@ in vec2 vecTex;
|
||||
in vec3 viewDirTS;
|
||||
in vec3 lightDirTS;
|
||||
|
||||
out vec4 outColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = vec3(0,0,1);
|
||||
vec3 lightDir = normalize(lightDirTS);
|
||||
|
||||
vec3 textureColor = texture2D(colorTexture, vecTex).xyz;
|
||||
|
||||
vec3 N = texture2D(normalSampler, vecTex).xyz;
|
||||
N = 2.0 * N - 1.0;
|
||||
N = normalize(N);
|
||||
|
||||
//float diffuse=max(0,dot(normal,lightDir));
|
||||
float diffuse=max(0,dot(N,lightDir));
|
||||
outColor = vec4(textureColor*min(1,AMBIENT+diffuse), 1.0);
|
||||
float diffuse=max(0, dot(N, lightDir));
|
||||
FragColor = vec4(textureColor * min(1, AMBIENT + diffuse), 1.0);
|
||||
|
||||
|
||||
float brightness = dot(FragColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f));
|
||||
if(brightness > 0.15f)
|
||||
BloomColor = vec4(FragColor.rgb, 1.0f);
|
||||
else
|
||||
BloomColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ layout(location = 2) in vec2 vertexTexCoord;
|
||||
layout(location = 3) in vec3 vertexTangent;
|
||||
layout(location = 4) in vec3 vertexBitangent;
|
||||
|
||||
|
||||
uniform mat4 transformation;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
|
22
cw 7/shaders/shader_bloom.frag
Normal file
22
cw 7/shaders/shader_bloom.frag
Normal file
@ -0,0 +1,22 @@
|
||||
#version 430 core
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec2 texCoords;
|
||||
|
||||
uniform sampler2D screenTexture;
|
||||
uniform sampler2D bloomTexture;
|
||||
uniform float gamma;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 fragment = texture(screenTexture, texCoords).rgb;
|
||||
vec3 bloom = texture(bloomTexture, texCoords).rgb;
|
||||
|
||||
vec3 color = fragment + bloom;
|
||||
|
||||
float exposure = 0.8f;
|
||||
vec3 toneMapped = vec3(1.0f) - exp(-color * exposure);
|
||||
|
||||
FragColor.rgb = pow(toneMapped, vec3(1.0f / gamma));
|
||||
|
||||
}
|
16
cw 7/shaders/shader_bloom.vert
Normal file
16
cw 7/shaders/shader_bloom.vert
Normal file
@ -0,0 +1,16 @@
|
||||
#version 430 core
|
||||
|
||||
layout (location = 0) in vec2 inPos;
|
||||
layout (location = 1) in vec2 inTexCoords;
|
||||
|
||||
out vec2 texCoords;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(inPos.x, inPos.y, 0.0, 1.0);
|
||||
|
||||
|
||||
texCoords = inTexCoords;
|
||||
|
||||
}
|
15
cw 7/shaders/shader_quad.frag
Normal file
15
cw 7/shaders/shader_quad.frag
Normal file
@ -0,0 +1,15 @@
|
||||
#version 430 core
|
||||
|
||||
|
||||
uniform sampler2D colorTexture;
|
||||
uniform sampler2D highlightTexture;
|
||||
|
||||
in vec2 vecTex;
|
||||
|
||||
out vec4 outColor;
|
||||
void main()
|
||||
{
|
||||
vec3 color = texture(colorTexture,vecTex).rgb;
|
||||
vec3 color2 = texture(highlightTexture,vecTex).rgb;
|
||||
outColor = vec4(color+color2, 1.0);
|
||||
}
|
13
cw 7/shaders/shader_quad.vert
Normal file
13
cw 7/shaders/shader_quad.vert
Normal file
@ -0,0 +1,13 @@
|
||||
#version 430 core
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition;
|
||||
|
||||
|
||||
out vec2 vecTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
//worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz;
|
||||
vecTex = vertexPosition.xy*0.5+0.5;
|
||||
gl_Position = vec4(vertexPosition, 1.0);
|
||||
}
|
@ -4,9 +4,15 @@ uniform samplerCube skybox;
|
||||
|
||||
in vec3 texCoord;
|
||||
|
||||
out vec4 out_color;
|
||||
layout (location = 0) out vec4 FragColor;
|
||||
layout (location = 1) out vec4 BloomColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = texture(skybox,texCoord);
|
||||
FragColor = texture(skybox,texCoord);
|
||||
float brightness = dot(FragColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f));
|
||||
if(brightness > 0.15f)
|
||||
BloomColor = vec4(FragColor.rgb, 1.0f);
|
||||
else
|
||||
BloomColor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
@ -24,6 +24,8 @@ namespace texture {
|
||||
GLuint ship;
|
||||
GLuint rust;
|
||||
|
||||
GLuint sun;
|
||||
|
||||
GLuint mars;
|
||||
GLuint mercury;
|
||||
GLuint venus;
|
||||
@ -47,11 +49,15 @@ GLuint programTex;
|
||||
GLuint programEarth;
|
||||
GLuint programProcTex;
|
||||
GLuint programSkyBox;
|
||||
GLuint programBloom;
|
||||
GLuint programQuad;
|
||||
|
||||
Core::Shader_Loader shaderLoader;
|
||||
|
||||
Core::RenderContext shipContext;
|
||||
Core::RenderContext sphereContext;
|
||||
Core::RenderContext cubeContext;
|
||||
Core::RenderContext test;
|
||||
|
||||
glm::vec3 cameraPos = glm::vec3(-4.f, 0, 0);
|
||||
glm::vec3 cameraDir = glm::vec3(1.f, 0.f, 0.f);
|
||||
@ -80,6 +86,20 @@ float aspectRatio = 1.f;
|
||||
|
||||
unsigned int textureID;
|
||||
|
||||
|
||||
unsigned int hdrFBO;
|
||||
GLuint testMap;
|
||||
|
||||
unsigned int colorBuffers[2];
|
||||
|
||||
int WIDTH = 800;
|
||||
int HEIGHT = 800;
|
||||
|
||||
unsigned int rectVAO, rectVBO;
|
||||
|
||||
|
||||
|
||||
|
||||
glm::mat4 createCameraMatrix()
|
||||
{
|
||||
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir,glm::vec3(0.f,1.f,0.f)));
|
||||
@ -131,6 +151,7 @@ void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::v
|
||||
}
|
||||
|
||||
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
glUseProgram(programTex);
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
|
||||
@ -139,10 +160,21 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
|
||||
glUniform3f(glGetUniformLocation(programTex, "lightPos"), 0, 0, 0);
|
||||
Core::SetActiveTexture(normalMapId, "normalSampler", programTex, 1);
|
||||
Core::SetActiveTexture(textureID, "colorTexture", programTex, 0);
|
||||
|
||||
glUseProgram(programBloom);
|
||||
glUniform1i(glGetUniformLocation(programBloom, "screenTexture"), 0);
|
||||
glUniform1i(glGetUniformLocation(programBloom, "bloomTexture"), 1);
|
||||
glUniform1f(glGetUniformLocation(programBloom, "gamma"), 2.2f);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
Core::DrawContext(context);
|
||||
|
||||
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
|
||||
|
||||
}
|
||||
void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 modelMatrix) {
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glUseProgram(programSkyBox);
|
||||
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
|
||||
@ -150,13 +182,36 @@ void drawObjectSkyBox(Core::RenderContext& context, glm::mat4 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);
|
||||
//Core::SetActiveTexture(textureID, "colorTexture", programSkyBox, 0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
||||
Core::DrawContext(context);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//void drawObjectBloom(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID, GLuint normalMapId) {
|
||||
//
|
||||
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
// 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(normalMapId, "normalSampler", programTex, 2);
|
||||
// Core::SetActiveTexture(textureID, "colorTexture", programTex, 1);
|
||||
// Core::DrawContext(context);
|
||||
//
|
||||
// glUseProgram(programBloom);
|
||||
// glUniform1i(glGetUniformLocation(programBloom, "screenTexture"), 0);
|
||||
// glUniform1i(glGetUniformLocation(programBloom, "bloomTexture"), 1);
|
||||
// glUniform1f(glGetUniformLocation(programBloom, "gamma"), 2.2f);
|
||||
//
|
||||
// //Core::DrawContext(context);
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
void generateAsteroids(glm::vec3 asteroid_Pos, glm::vec3 distance, double step) {
|
||||
glm::vec3 normalizedDir = glm::normalize(distance);
|
||||
asteroid_Pos = asteroid_Pos - normalizedDir *step;
|
||||
@ -189,16 +244,52 @@ glm::mat4 specshipCameraRotrationMatrix = glm::mat4({
|
||||
0.,0.,0.,1.,
|
||||
});
|
||||
|
||||
unsigned int quadVAO = 0;
|
||||
unsigned int quadVBO;
|
||||
void renderQuad()
|
||||
{
|
||||
if (quadVAO == 0)
|
||||
{
|
||||
float quadVertices[] = {
|
||||
// positions // texture coords
|
||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
|
||||
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
|
||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
|
||||
};
|
||||
|
||||
// setup plane VAO
|
||||
glGenVertexArrays(1, &quadVAO);
|
||||
glGenBuffers(1, &quadVBO);
|
||||
glBindVertexArray(quadVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
}
|
||||
glBindVertexArray(quadVAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
||||
void renderScene(GLFWwindow* window)
|
||||
{
|
||||
glClearColor(0.0f, 0.3f, 0.3f, 1.0f);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||
glClearColor(0.0f, 0.f, 0.f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glm::mat4 transformation;
|
||||
float time = glfwGetTime();
|
||||
|
||||
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
|
||||
|
||||
//drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::rust, texture::rustNormal);
|
||||
drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::sun, texture::rustNormal);
|
||||
|
||||
drawObjectTexture(sphereContext, glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::rust, texture::rustNormal);
|
||||
|
||||
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(8.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::earth, texture::earthNormal);
|
||||
drawObjectTexture(sphereContext,
|
||||
@ -213,11 +304,6 @@ void renderScene(GLFWwindow* window)
|
||||
drawObjectTexture(sphereContext, glm::eulerAngleY(time / 8) * glm::translate(glm::vec3(23.f, 0, 0)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.6f)), texture::neptune, texture::rustNormal);
|
||||
|
||||
|
||||
|
||||
//drawObjectColor(shipContext,
|
||||
// glm::translate(cameraPos + 1.5 * cameraDir + cameraUp * -0.5f) * inveseCameraRotrationMatrix * glm::eulerAngleY(glm::pi<float>()),
|
||||
// glm::vec3(0.3, 0.3, 0.5)
|
||||
// );
|
||||
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
spaceshipUp = glm::normalize(glm::cross(spaceshipSide, spaceshipDir));
|
||||
specshipCameraRotrationMatrix = glm::mat4({
|
||||
@ -258,14 +344,60 @@ void renderScene(GLFWwindow* window)
|
||||
//steps = 0;
|
||||
}
|
||||
glUseProgram(0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glUseProgram(programQuad);
|
||||
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
|
||||
//Core::SetActiveTexture(colorBuffers[1], "highlightTexture", programQuad, 1);
|
||||
glUniform1i(glGetUniformLocation(programQuad, "originalTexture"), 0);
|
||||
glUniform1i(glGetUniformLocation(programQuad, "bloomTexture"), 1);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[1]);
|
||||
|
||||
renderQuad();
|
||||
//Core::DrawContext(test);
|
||||
|
||||
//glBindTexture(GL_TEXTURE_2D, 0);
|
||||
//glUseProgram(0);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//// Draw the framebuffer rectangle
|
||||
//glUseProgram(programQuad);
|
||||
////glBindVertexArray(rectVAO);
|
||||
////Core::DrawContext(test);
|
||||
//renderQuad();
|
||||
//glDisable(GL_DEPTH_TEST); // prevents framebuffer rectangle from being discarded
|
||||
////glActiveTexture(GL_TEXTURE0);
|
||||
////glBindTexture(GL_TEXTURE_2D, colorBuffers[0]);
|
||||
////glActiveTexture(GL_TEXTURE1);
|
||||
////glBindTexture(GL_TEXTURE_2D, colorBuffers[1]);
|
||||
////glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
//Core::SetActiveTexture(colorBuffers[0], "colorTexture", programQuad, 0);
|
||||
//Core::SetActiveTexture(colorBuffers[1], "highlightTexture", programQuad, 1);
|
||||
|
||||
//glUseProgram(0);
|
||||
|
||||
//glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
aspectRatio = static_cast<float>(width) / static_cast<float>(height);
|
||||
//aspectRatio = static_cast<float>(width) / static_cast<float>(height);
|
||||
//glViewport(0, 0, width, height);
|
||||
aspectRatio = width / float(height);
|
||||
glViewport(0, 0, width, height);
|
||||
WIDTH = 800;
|
||||
HEIGHT = 800;
|
||||
|
||||
}
|
||||
void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
{
|
||||
@ -283,20 +415,19 @@ void loadModelToContext(std::string path, Core::RenderContext& context)
|
||||
void init(GLFWwindow* window)
|
||||
{
|
||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
|
||||
|
||||
//programTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
|
||||
//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");
|
||||
|
||||
programTex = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
|
||||
programEarth = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
|
||||
programProcTex = shaderLoader.CreateProgram("shaders/shader_5_tex.vert", "shaders/shader_5_tex.frag");
|
||||
|
||||
programSkyBox = shaderLoader.CreateProgram("shaders/shader_skybox.vert", "shaders/shader_skybox.frag");
|
||||
|
||||
programQuad = shaderLoader.CreateProgram("shaders/shader_quad.vert", "shaders/shader_quad.frag");
|
||||
|
||||
programBloom = shaderLoader.CreateProgram("shaders/shader_bloom.vert", "shaders/shader_bloom.frag");
|
||||
|
||||
loadModelToContext("./models/sphere.obj", sphereContext);
|
||||
loadModelToContext("./models/spaceship.obj", shipContext);
|
||||
loadModelToContext("./models/cube.obj", cubeContext);
|
||||
@ -306,6 +437,8 @@ void init(GLFWwindow* window)
|
||||
texture::moon = Core::LoadTexture("textures/moon.jpg");
|
||||
texture::rust = Core::LoadTexture("textures/rust.jpg");
|
||||
|
||||
texture::sun = Core::LoadTexture("textures/2k_sun.jpg");
|
||||
|
||||
texture::mars = Core::LoadTexture("textures/2k_mars.jpg");
|
||||
texture::mercury = Core::LoadTexture("textures/2k_mercury.jpg");
|
||||
texture::venus = Core::LoadTexture("textures/2k_venus_surface.jpg");
|
||||
@ -314,17 +447,69 @@ void init(GLFWwindow* window)
|
||||
texture::uranus = Core::LoadTexture("textures/2k_uranus.jpg");
|
||||
texture::neptune = Core::LoadTexture("textures/2k_neptune.jpg");
|
||||
|
||||
|
||||
|
||||
|
||||
texture::earthNormal = Core::LoadTexture("textures/earth_normalmap.png");
|
||||
texture::shipNormal = Core::LoadTexture("textures/spaceship_normal.jpg");
|
||||
texture::rustNormal = Core::LoadTexture("textures/rust_normal.jpg");
|
||||
texture::moonNormal = Core::LoadTexture("textures/moon_normal.jpg");
|
||||
|
||||
loadModelToContext("./models/test.obj", test);
|
||||
|
||||
|
||||
glGenTextures(1, &textureID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
|
||||
|
||||
|
||||
|
||||
//const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
|
||||
glGenFramebuffers(1, &hdrFBO);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
|
||||
|
||||
glGenTextures(2, colorBuffers);
|
||||
for (unsigned int i = 0; i < 2; i++)
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGBA16F,WIDTH, HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL
|
||||
);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0
|
||||
);
|
||||
}
|
||||
|
||||
unsigned int attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||
glDrawBuffers(2, attachments);
|
||||
|
||||
float rectangleVertices[] =
|
||||
{
|
||||
// Coords // texCoords
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
|
||||
1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
-1.0f, 1.0f, 0.0f, 1.0f
|
||||
};
|
||||
|
||||
glGenVertexArrays(1, &rectVAO);
|
||||
glGenBuffers(1, &rectVBO);
|
||||
glBindVertexArray(rectVAO);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rectVBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(rectangleVertices), &rectangleVertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
|
||||
|
||||
|
||||
|
||||
|
||||
std::uniform_real_distribution<float> angleDistribution(0.0f, 2.0f * glm::pi<float>());
|
||||
std::uniform_real_distribution<float> radiusDistribution(10.f, 17.f);
|
||||
|
||||
@ -365,6 +550,7 @@ void init(GLFWwindow* window)
|
||||
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)
|
||||
@ -399,6 +585,7 @@ void processInput(GLFWwindow* window)
|
||||
{
|
||||
spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
|
||||
spaceshipUp = glm::vec3(0.f, 1.f, 0.f);
|
||||
|
||||
float angleSpeed = 0.01f;
|
||||
float moveSpeed = 0.01f;
|
||||
|
||||
@ -426,9 +613,11 @@ void processInput(GLFWwindow* window)
|
||||
if (glfwGetKey(window, GLFW_KEY_G) == GLFW_PRESS)
|
||||
START_AS = true;
|
||||
|
||||
glfwSetCursorPosCallback(window, mouseCallback);
|
||||
//glfwSetCursorPosCallback(window, mouseCallback);
|
||||
|
||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 2, 0) * 0.1f;
|
||||
//cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 2, 0) * 0.1f;
|
||||
//cameraDir = spaceshipDir;
|
||||
cameraPos = spaceshipPos - 0.5 * spaceshipDir + glm::vec3(0, 1, 0) * 0.2f;
|
||||
cameraDir = spaceshipDir;
|
||||
|
||||
//cameraDir = glm::normalize(-cameraPos);
|
||||
|
@ -23,8 +23,8 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
// tworzenie okna za pomoca glfw
|
||||
const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "FirstWindow", NULL, NULL);
|
||||
//const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
GLFWwindow* window = glfwCreateWindow(800, 800, "FirstWindow", NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
@ -35,7 +35,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// ladowanie OpenGL za pomoca glew
|
||||
glewInit();
|
||||
glViewport(0, 0, mode->width, mode->width);
|
||||
glViewport(0, 0, 800, 800);
|
||||
|
||||
init(window);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user