diff --git a/grk/project/Sun.h b/grk/project/Sun.h index 5e4dee4..7053ec4 100644 --- a/grk/project/Sun.h +++ b/grk/project/Sun.h @@ -14,20 +14,25 @@ public: GLuint program; Core::RenderContext sphereContext; glm::mat4 positionMatrix; + GLuint textureID; - Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, glm::vec3 color, double scale) { + Sun(GLuint program, Core::RenderContext sphereContext, glm::vec3 pos, glm::vec3 dir, GLuint textureID, glm::vec3 color, double scale) { this->program = program; this->sphereContext = sphereContext; this->sunPos = pos; this->sunDir = dir; this->sunColor = color; this->scale = scale; + this->textureID = textureID; } Sun(){} void draw() { glUseProgram(program); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, textureID); + glUniform1i(glGetUniformLocation(program, "sunTexture"), 0); glm::mat4 viewProjectionMatrix = Core::createPerspectiveMatrix() * Spaceship::getInstance()->createCameraMatrix(); positionMatrix = glm::translate(sunPos); glm::mat4 transformation = viewProjectionMatrix * positionMatrix * glm::scale(glm::vec3(scale)); diff --git a/grk/project/shaders/shader_8_sun.frag b/grk/project/shaders/shader_8_sun.frag index 1dd40b8..def6581 100644 --- a/grk/project/shaders/shader_8_sun.frag +++ b/grk/project/shaders/shader_8_sun.frag @@ -3,9 +3,13 @@ uniform vec3 color; uniform float exposition; +uniform sampler2D sunTexture; +in vec2 TexCoords; out vec4 outColor; void main() -{ - outColor = vec4(vec3(1.0) - exp(-color*exposition),1); -} +{ + vec4 texColor = texture(sunTexture, TexCoords); + vec3 brightColor = texColor.rgb * 4.0; + outColor = vec4(vec3(1.0) - exp(-brightColor*exposition),texColor.a); +} \ No newline at end of file diff --git a/grk/project/shaders/shader_8_sun.vert b/grk/project/shaders/shader_8_sun.vert index 57204e2..7934774 100644 --- a/grk/project/shaders/shader_8_sun.vert +++ b/grk/project/shaders/shader_8_sun.vert @@ -5,9 +5,11 @@ layout(location = 1) in vec3 vertexNormal; layout(location = 2) in vec2 vertexTexCoord; uniform mat4 transformation; +out vec2 TexCoords; void main() { gl_Position = transformation * vec4(vertexPosition, 1.0); //gl_Position = vec4(vertexPosition, 1.0); + TexCoords = vertexTexCoord; } diff --git a/grk/project/shaders/shader_tex.vert b/grk/project/shaders/shader_tex.vert index 4cd0898..3d35a3f 100644 --- a/grk/project/shaders/shader_tex.vert +++ b/grk/project/shaders/shader_tex.vert @@ -25,7 +25,9 @@ out mat3 TBN; void main() { TexCoords = vertexTexCoord * -1; - + TexCoords = vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y); + + worldPos = (modelMatrix* vec4(vertexPosition,1)).xyz; vecNormal = (modelMatrix* vec4(vertexNormal,0)).xyz; gl_Position = transformation * vec4(vertexPosition, 1.0); diff --git a/grk/project/src/ex_9_1.hpp b/grk/project/src/ex_9_1.hpp index a0a4e74..6ae33b0 100644 --- a/grk/project/src/ex_9_1.hpp +++ b/grk/project/src/ex_9_1.hpp @@ -50,7 +50,7 @@ struct TextureTuple { }; std::vector planetTextures; - +std::vector sunTexturesIds; void createGalaxy(glm::vec3 galaxyPosition); @@ -82,7 +82,7 @@ float lastTime = -1.f; float deltaTime = 0.f; Spaceship* spaceship = Spaceship::getInstance(); -void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef); +void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId,float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef); Core::SpriteRenderer* spriteRenderer; void updateDeltaTime(float time) { @@ -253,18 +253,22 @@ void createSuns() { void createGalaxy(glm::vec3 galaxyPosition) { float planetsSizes[] = { 1.f, 1.5f, 0.8f, 1.2f, 0.2f }; - createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), 3, planetsSizes, 5, 15.f, 0.2f); + GLuint sunTexId = sunTexturesIds[0]; + createSolarSystem(galaxyPosition + glm::vec3(0, 2, 0), sunTexId,3, planetsSizes, 5, 15.f, 0.2f); float planetsSizes2[] = { 0.6f, 1.1f, 0.9f }; - createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), 2, planetsSizes2, 3, 15.f, 0.2f); + GLuint sunTexId2 = sunTexturesIds[1]; + createSolarSystem(galaxyPosition + glm::vec3(150, 5, 0), sunTexId2, 2, planetsSizes2, 3, 15.f, 0.2f); float planetsSizes3[] = { 0.7f, 1.5f, 1.2f, 1.f }; - createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), 4, planetsSizes3, 4, 20.f, 0.2f); + GLuint sunTexId3 = sunTexturesIds[2]; + createSolarSystem(galaxyPosition + glm::vec3(-20, -30, 50), sunTexId3, 4, planetsSizes3, 4, 20.f, 0.2f); float planetSizes4[] = { 1.f, 0.5f }; - createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), 5, planetsSizes3, 2, 25.f, 0.2f); + GLuint sunTexId4 = sunTexturesIds[3]; + createSolarSystem(galaxyPosition + glm::vec3(100, 20, -50), sunTexId4, 5, planetsSizes3, 2, 25.f, 0.2f); } -void createSolarSystem(glm::vec3 sunPos, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) { +void createSolarSystem(glm::vec3 sunPos, GLuint sunTexId, float sunScale, float* planetSizes, int numberOfPlanets, float planetsDistance, float planetSpeedCoef) { GameUtils* gu = GameUtils::getInstance(); - sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale); + sun = new Sun(programSun, models::sphereContext, sunPos, glm::vec3(-0.93633f, 0.351106, 0.003226f), sunTexId, glm::vec3(0.9f, 0.9f, 0.7f) * 5, sunScale); gu->getSuns()->push_back(sun); for (int i = 0; i < numberOfPlanets; i++) { TextureTuple textures = getRandomPlanetTexture(); @@ -287,7 +291,7 @@ void createEnemies() { } -void loadPlanetsTextures() { +void loadPlanetsAndSunTextures() { planetTextures.clear(); std::vector> texturePaths = { @@ -297,11 +301,23 @@ void loadPlanetsTextures() { {"./textures/planets/planet4.png", "./textures/planets/planet4normal.png"} }; + std::vector sunTexturePaths{ + {"./textures/suns/8k_sun.jpg"}, + {"./textures/suns/sun2.png"}, + {"./textures/suns/sun3.jpg"}, + {"./textures/suns/sun4.jpg"} + }; + for (const auto& paths : texturePaths) { GLuint textureID = Core::LoadTexture(paths.first.c_str()); GLuint normalMapID = Core::LoadTexture(paths.second.c_str()); planetTextures.push_back({ textureID, normalMapID }); } + + for (const auto& path : sunTexturePaths) { + GLuint sunTextureId = Core::LoadTexture(path.c_str()); + sunTexturesIds.push_back(sunTextureId); + } } @@ -344,7 +360,7 @@ void init(GLFWwindow* window) "bkg2_back6.png" }; - loadPlanetsTextures(); + loadPlanetsAndSunTextures(); texture::cubemapTexture = Core::LoadCubemap(cubeFaces); texture::spaceshipTexture = Core::LoadTexture("./textures/spaceship/Material.001_Base_color.jpg"); texture::spaceshipNormal = Core::LoadTexture("./textures/spaceship/Material.001_Normal_DirectX.jpg"); diff --git a/grk/project/textures/suns/8k_sun.jpg b/grk/project/textures/suns/8k_sun.jpg new file mode 100644 index 0000000..5b0ac0a Binary files /dev/null and b/grk/project/textures/suns/8k_sun.jpg differ diff --git a/grk/project/textures/suns/sun2.png b/grk/project/textures/suns/sun2.png new file mode 100644 index 0000000..a56eb81 Binary files /dev/null and b/grk/project/textures/suns/sun2.png differ diff --git a/grk/project/textures/suns/sun3.jpg b/grk/project/textures/suns/sun3.jpg new file mode 100644 index 0000000..8b73ae3 Binary files /dev/null and b/grk/project/textures/suns/sun3.jpg differ diff --git a/grk/project/textures/suns/sun4.jpg b/grk/project/textures/suns/sun4.jpg new file mode 100644 index 0000000..2ade027 Binary files /dev/null and b/grk/project/textures/suns/sun4.jpg differ