This commit is contained in:
serk 2017-01-22 14:02:23 +01:00
parent 0a589d6a11
commit 71c249426b
4 changed files with 12 additions and 9 deletions

View file

@ -1,6 +1,6 @@
uniform vec2 resolution; uniform vec2 resolution;
uniform float time; uniform float time;
uniform float night; uniform float hour;
float rand(vec2 n) { float rand(vec2 n) {
return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
@ -39,9 +39,8 @@ void main(void) {
else uv.y -= abs(time * 0.1); else uv.y -= abs(time * 0.1);
vec3 colorPink = vec3(255.,0.,255.); vec3 colorPink = vec3(255.,0.,255.);
vec3 colorBlue = vec3(0.,255.,255.); vec3 colorBlue = vec3(0.,255.,255.);
vec4 color = vec4(((colorPink.x*night) + (colorBlue.x*(1.-night)))/2., vec4 color = vec4(((colorBlue.x*hour) + (colorPink.x*(1.-hour)))/2.,
((colorPink.y*night) + (colorBlue.y*(1.-night)))/2., ((colorBlue.y*hour) + (colorPink.y*(1.-hour)))/2.,
((colorPink.z*night) + (colorBlue.z*(1.-night)))/2., 255) / 255.; ((colorBlue.z*hour) + (colorPink.z*(1.-hour)))/2., 255) / 255.;
// color = vec4(122.,202.,255.,255.)/ 255.;
gl_FragColor = (grid(fract(uv))) * color - line(umuv.y, 0., 0.175, 0.025) * color * 2.; gl_FragColor = (grid(fract(uv))) * color - line(umuv.y, 0., 0.175, 0.025) * color * 2.;
} }

View file

@ -66,8 +66,9 @@ float isNight() {
struct tm * ptm; struct tm * ptm;
time ( &rawtime ); time ( &rawtime );
ptm = gmtime ( &rawtime ); ptm = gmtime ( &rawtime );
float hour = (float ((ptm->tm_hour+UTC)%24))/(23.);
return (float ((ptm->tm_hour+UTC)%24))/(23.); float result = (std::cos(hour*(2*PI)) + 1.f)/2.;
return result;
} }
void Combat::initShader() { void Combat::initShader() {
@ -78,7 +79,7 @@ void Combat::initShader() {
_shader.loadFromFile(WORK_DIR+"Resources/shader.frag", sf::Shader::Fragment); _shader.loadFromFile(WORK_DIR+"Resources/shader.frag", sf::Shader::Fragment);
_shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT)); _shader.setParameter("resolution", sf::Vector2f(W_WIDTH, W_HEIGHT));
_shader.setParameter("time", time); _shader.setParameter("time", time);
_shader.setParameter("night", isNight()); _shader.setParameter("hour", isNight());
ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png")); ASSERT(_haloT.loadFromFile(WORK_DIR+"Resources/platform-halo.png"));
_halo.setTexture(_haloT); _halo.setTexture(_haloT);

View file

@ -12,7 +12,8 @@
#include "wave.hpp" #include "wave.hpp"
#include <time.h> #include <time.h>
#define UTC (0) #define PI 3.14159265
class Combat : public Scene { class Combat : public Scene {

View file

@ -16,6 +16,8 @@ const int SCENE_NUM = 4;
#define MARGEERR 0.25f #define MARGEERR 0.25f
#define BLACKVALUE 0.4f #define BLACKVALUE 0.4f
#define W_WIDTH 1024 #define W_WIDTH 1024
#define UTC (0)
#define W_HEIGHT 768 #define W_HEIGHT 768
const std::string WORK_DIR(getenv("WORK_DIR")); const std::string WORK_DIR(getenv("WORK_DIR"));