mxsgd 2024-02-07 23:02:00 +01:00
commit 422109ae49
3 changed files with 32 additions and 24 deletions

View File

@ -1,10 +1,17 @@
#version 430 core
uniform vec3 objectColor;
in vec3 interpNormal;
uniform float exposition;
uniform sampler2D sunTexture;
out vec4 outColor;
in vec2 TexCoords;
void main()
{
gl_FragColor = vec4(objectColor, 1.0);
vec3 textureColor = texture2D(sunTexture, TexCoords).xyz;
vec3 adjustedColor = 1.0 - exp(-textureColor * exposition);
// Output the color with unchanged alpha
outColor = vec4(clamp(adjustedColor, 0.0, 1.0), 1.0);
//outColor = vec4(textureColor*min(1,exposition), 1.0);
}

View File

@ -1,15 +1,15 @@
#version 430 core
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec2 vertexTexCoord;
layout(location = 2) in vec3 vertexNormal;
layout(location = 1) in vec3 vertexNormal;
layout(location = 2) in vec2 vertexTexCoord;
uniform mat4 transformation;
out vec3 interpNormal;
out vec2 TexCoords;
void main()
{
interpNormal = vertexNormal;
gl_Position = transformation * vec4(vertexPosition, 1.0);
TexCoords = vertexTexCoord;
}

View File

@ -207,7 +207,6 @@ 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);
@ -252,6 +251,19 @@ void drawAmmoReloadBar() {
glUseProgram(0);
}
void drawObjectSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint textureID)
{
glUseProgram(programSun);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programSun, "transformation"), 1, GL_FALSE, (float*)&transformation);
glUniform1f(glGetUniformLocation(programSun, "exposition"), 1.f);
Core::SetActiveTexture(textureID, "sunTexture", programSun, 0);
glActiveTexture(GL_TEXTURE0); // Activate texture unit 0
glBindTexture(GL_TEXTURE_2D, textureID);
Core::DrawContext(sphereContext);
}
void generateAsteroids(glm::vec3 asteroid_Pos, glm::vec3 distance, double step) {
glm::vec3 normalizedDir = glm::normalize(distance);
asteroid_Pos = asteroid_Pos - normalizedDir *step;
@ -367,14 +379,6 @@ void generatePlanetoidBelt() {
}
}
//if(star==1)
//{
// star = 0;
//}
//else
//{
// exit(0);
//}
}
glm::vec3 spaceshipSide = glm::normalize(glm::cross(spaceshipDir, glm::vec3(0.f, 1.f, 0.f)));
@ -419,12 +423,9 @@ void renderScene(GLFWwindow* window)
glm::mat4 transformation;
float time = glfwGetTime();
drawObjectSkyBox(cubeContext, glm::translate(cameraPos));
drawObjectTexture(sphereContext, glm::translate(glm::vec3(20.0f, 0.0f, 0.0f)) * glm::scale(glm::mat4(), glm::vec3(2.0f, 2.0f, 2.0f)), texture::sun, texture::rustNormal, texture::metalnessSphere, texture::roughnessSphere);
drawObjectSun(sphereContext, glm::translate(glm::vec3(20.0f, 0.0f, 0.0f)) * glm::scale(glm::mat4(), glm::vec3(2)), texture::sun);
drawObjectTexture(sphereContext, glm::translate(glm::vec3(18.0f, 0.0f, 3.0f)) * glm::eulerAngleY(time) * glm::scale(glm::vec3(0.3f)), texture::earth, texture::earthNormal, texture::metalnessSphere, texture::roughnessSphere);
//drawObjectTexture(sphereContext,
@ -508,8 +509,8 @@ void init(GLFWwindow* window)
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");
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
loadModelToContext("./models/sphere.obj", sphereContext);
loadModelToContext("./models/spaceship_new.obj", shipContext);