fix sun and shadows position synchronization
This commit is contained in:
parent
3e66ff5924
commit
1b84b7df5e
@ -14,6 +14,7 @@
|
||||
],
|
||||
"textures": [
|
||||
"misc/moon",
|
||||
"misc/moon_flare",
|
||||
"misc/sun",
|
||||
"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 <GL/glew.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/constants.hpp>
|
||||
|
||||
#ifndef M_PI
|
||||
@ -46,18 +47,28 @@ Skybox::Skybox(uint size, Shader& shader)
|
||||
|
||||
mesh = std::make_unique<Mesh<SkyboxVertex>>(vertices, 6);
|
||||
|
||||
sprites.push_back(skysprite {
|
||||
"misc/moon",
|
||||
glm::pi<float>()*0.5f,
|
||||
4.0f,
|
||||
false
|
||||
sprites.push_back(SkySprite {
|
||||
"misc/moon_flare",
|
||||
glm::pi<float>() * 0.5f,
|
||||
0.5f,
|
||||
false,
|
||||
glm::pi<float>() * 0.25f,
|
||||
});
|
||||
|
||||
sprites.push_back(skysprite {
|
||||
"misc/sun",
|
||||
glm::pi<float>()*1.5f,
|
||||
sprites.push_back(SkySprite {
|
||||
"misc/moon",
|
||||
glm::pi<float>() * 0.5f,
|
||||
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) {
|
||||
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;
|
||||
|
||||
glm::vec3 pos(-std::cos(sangle)*distance, std::sin(sangle)*distance, 0);
|
||||
glm::vec3 up(-std::sin(-sangle), std::cos(-sangle), 0.0f);
|
||||
glm::mat4 rotation = glm::rotate(glm::mat4(1.0f), -sangle + glm::pi<float>() * 0.5f, glm::vec3(0, 0, -1));
|
||||
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);
|
||||
if (!sprite.emissive) {
|
||||
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);
|
||||
}
|
||||
batch3d->flush();
|
||||
|
||||
@ -25,11 +25,12 @@ struct SkyboxVertex {
|
||||
{{}, 0}};
|
||||
};
|
||||
|
||||
struct skysprite {
|
||||
struct SkySprite {
|
||||
std::string texture;
|
||||
float phase;
|
||||
float distance;
|
||||
bool emissive;
|
||||
float altitude;
|
||||
};
|
||||
|
||||
class Skybox {
|
||||
@ -42,7 +43,7 @@ class Skybox {
|
||||
|
||||
std::unique_ptr<Mesh<SkyboxVertex>> mesh;
|
||||
std::unique_ptr<Batch3D> batch3d;
|
||||
std::vector<skysprite> sprites;
|
||||
std::vector<SkySprite> sprites;
|
||||
int frameid = 0;
|
||||
|
||||
float prevMie = -1.0f;
|
||||
|
||||
@ -384,10 +384,11 @@ void WorldRenderer::generateShadowsMap(
|
||||
90.0f -
|
||||
((static_cast<int>(t / sunCycleStep)) * sunCycleStep + 0.25f) * 360.0f
|
||||
);
|
||||
float sunAltitude = glm::pi<float>() * 0.25f;
|
||||
shadowCamera.rotate(
|
||||
sunAngle,
|
||||
glm::radians(-45.0f),
|
||||
glm::radians(-0.0f)
|
||||
-glm::cos(sunAngle + glm::pi<float>() * 0.5f) * sunAltitude,
|
||||
sunAngle - glm::pi<float>() * 0.5f,
|
||||
glm::radians(0.0f)
|
||||
);
|
||||
shadowCamera.updateVectors();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user