Merge pull request 'sun_textures+ship_texturing_works' (#14) from sun_textures into master

Reviewed-on: #14
This commit is contained in:
Wojciech Goralewski 2024-02-05 23:50:36 +01:00
commit 203110adf5
9 changed files with 44 additions and 15 deletions

View File

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

View File

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

View File

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

View File

@ -25,6 +25,8 @@ 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;

View File

@ -50,7 +50,7 @@ struct TextureTuple {
};
std::vector<TextureTuple> planetTextures;
std::vector<GLuint> 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<std::pair<std::string, std::string>> texturePaths = {
@ -297,11 +301,23 @@ void loadPlanetsTextures() {
{"./textures/planets/planet4.png", "./textures/planets/planet4normal.png"}
};
std::vector<std::string> 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");

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 283 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB