fix sun and shadows position synchronization
This commit is contained in:
parent
3e66ff5924
commit
1b84b7df5e
@ -14,6 +14,7 @@
|
|||||||
],
|
],
|
||||||
"textures": [
|
"textures": [
|
||||||
"misc/moon",
|
"misc/moon",
|
||||||
|
"misc/moon_flare",
|
||||||
"misc/sun",
|
"misc/sun",
|
||||||
"gui/crosshair"
|
"gui/crosshair"
|
||||||
]
|
]
|
||||||
|
|||||||
BIN
res/textures/misc/moon_flare.png
Normal file
BIN
res/textures/misc/moon_flare.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@ -15,6 +15,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/constants.hpp>
|
#include <glm/gtc/constants.hpp>
|
||||||
|
|
||||||
#ifndef M_PI
|
#ifndef M_PI
|
||||||
@ -46,18 +47,28 @@ Skybox::Skybox(uint size, Shader& shader)
|
|||||||
|
|
||||||
mesh = std::make_unique<Mesh<SkyboxVertex>>(vertices, 6);
|
mesh = std::make_unique<Mesh<SkyboxVertex>>(vertices, 6);
|
||||||
|
|
||||||
sprites.push_back(skysprite {
|
sprites.push_back(SkySprite {
|
||||||
"misc/moon",
|
"misc/moon_flare",
|
||||||
glm::pi<float>()*0.5f,
|
glm::pi<float>() * 0.5f,
|
||||||
4.0f,
|
0.5f,
|
||||||
false
|
false,
|
||||||
|
glm::pi<float>() * 0.25f,
|
||||||
});
|
});
|
||||||
|
|
||||||
sprites.push_back(skysprite {
|
sprites.push_back(SkySprite {
|
||||||
"misc/sun",
|
"misc/moon",
|
||||||
glm::pi<float>()*1.5f,
|
glm::pi<float>() * 0.5f,
|
||||||
4.0f,
|
4.0f,
|
||||||
true
|
false,
|
||||||
|
glm::pi<float>() * 0.25f,
|
||||||
|
});
|
||||||
|
|
||||||
|
sprites.push_back(SkySprite {
|
||||||
|
"misc/sun",
|
||||||
|
glm::pi<float>() * 1.5f,
|
||||||
|
4.0f,
|
||||||
|
true,
|
||||||
|
glm::pi<float>() * 0.25f,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,16 +135,19 @@ void Skybox::draw(
|
|||||||
for (auto& sprite : sprites) {
|
for (auto& sprite : sprites) {
|
||||||
batch3d->texture(assets.get<Texture>(sprite.texture));
|
batch3d->texture(assets.get<Texture>(sprite.texture));
|
||||||
|
|
||||||
float sangle = daytime * glm::pi<float>()*2.0 + sprite.phase;
|
float sangle = daytime * glm::pi<float>() * 2.0 + sprite.phase;
|
||||||
float distance = sprite.distance;
|
float distance = sprite.distance;
|
||||||
|
|
||||||
glm::vec3 pos(-std::cos(sangle)*distance, std::sin(sangle)*distance, 0);
|
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), -sangle + glm::pi<float>() * 0.5f, glm::vec3(0, 0, -1));
|
||||||
glm::vec3 up(-std::sin(-sangle), std::cos(-sangle), 0.0f);
|
rotation = glm::rotate(rotation, sprite.altitude, glm::vec3(1, 0, 0));
|
||||||
|
glm::vec3 pos = glm::vec4(0, distance, 0, 1) * rotation;
|
||||||
|
glm::vec3 up = glm::vec4(1, 0, 0, 1) * rotation;
|
||||||
|
glm::vec3 right = glm::vec4(0, 0, 1, 1) * rotation;
|
||||||
glm::vec4 tint (1,1,1, opacity);
|
glm::vec4 tint (1,1,1, opacity);
|
||||||
if (!sprite.emissive) {
|
if (!sprite.emissive) {
|
||||||
tint *= 0.6f+std::cos(angle)*0.4;
|
tint *= 0.6f+std::cos(angle)*0.4;
|
||||||
}
|
}
|
||||||
batch3d->sprite(pos, glm::vec3(0, 0, 1),
|
batch3d->sprite(pos, right,
|
||||||
up, 1, 1, UVRegion(), tint);
|
up, 1, 1, UVRegion(), tint);
|
||||||
}
|
}
|
||||||
batch3d->flush();
|
batch3d->flush();
|
||||||
|
|||||||
@ -25,11 +25,12 @@ struct SkyboxVertex {
|
|||||||
{{}, 0}};
|
{{}, 0}};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct skysprite {
|
struct SkySprite {
|
||||||
std::string texture;
|
std::string texture;
|
||||||
float phase;
|
float phase;
|
||||||
float distance;
|
float distance;
|
||||||
bool emissive;
|
bool emissive;
|
||||||
|
float altitude;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Skybox {
|
class Skybox {
|
||||||
@ -42,7 +43,7 @@ class Skybox {
|
|||||||
|
|
||||||
std::unique_ptr<Mesh<SkyboxVertex>> mesh;
|
std::unique_ptr<Mesh<SkyboxVertex>> mesh;
|
||||||
std::unique_ptr<Batch3D> batch3d;
|
std::unique_ptr<Batch3D> batch3d;
|
||||||
std::vector<skysprite> sprites;
|
std::vector<SkySprite> sprites;
|
||||||
int frameid = 0;
|
int frameid = 0;
|
||||||
|
|
||||||
float prevMie = -1.0f;
|
float prevMie = -1.0f;
|
||||||
|
|||||||
@ -384,10 +384,11 @@ void WorldRenderer::generateShadowsMap(
|
|||||||
90.0f -
|
90.0f -
|
||||||
((static_cast<int>(t / sunCycleStep)) * sunCycleStep + 0.25f) * 360.0f
|
((static_cast<int>(t / sunCycleStep)) * sunCycleStep + 0.25f) * 360.0f
|
||||||
);
|
);
|
||||||
|
float sunAltitude = glm::pi<float>() * 0.25f;
|
||||||
shadowCamera.rotate(
|
shadowCamera.rotate(
|
||||||
sunAngle,
|
-glm::cos(sunAngle + glm::pi<float>() * 0.5f) * sunAltitude,
|
||||||
glm::radians(-45.0f),
|
sunAngle - glm::pi<float>() * 0.5f,
|
||||||
glm::radians(-0.0f)
|
glm::radians(0.0f)
|
||||||
);
|
);
|
||||||
shadowCamera.updateVectors();
|
shadowCamera.updateVectors();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user