aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-02 01:52:56 -0400
committerAndy Belle-Isle <drumsetmonkey@gmail.com>2019-09-02 01:52:56 -0400
commit062a7e2baad74f49f2548793a25f0cf5e4ae6f86 (patch)
tree151ad921a5982b83a16b8049d77f9af6cc76573b
parentb52920a35eb69d1a258c737e3114fbe5cfe9aca5 (diff)
Fixed flipped texture normals being displayed properly in shaders
-rw-r--r--Shaders/world.frag3
-rw-r--r--src/render.cpp10
2 files changed, 12 insertions, 1 deletions
diff --git a/Shaders/world.frag b/Shaders/world.frag
index 85941f2..881127b 100644
--- a/Shaders/world.frag
+++ b/Shaders/world.frag
@@ -17,6 +17,7 @@ uniform vec3 LightPos[32];
uniform vec4 LightColor[32];
uniform int LightNum;
uniform vec4 AmbientLight;
+uniform int Flipped;
void main()
{
@@ -33,6 +34,8 @@ void main()
for (int i = 0; i < LightNum; i++) {
vec3 LightDir = vec3(LightPos[i].xy - fragCoord.xy, LightPos[i].z);
+ if (Flipped == 1)
+ LightDir.x = -LightDir.x;
float D = length(LightDir);
diff --git a/src/render.cpp b/src/render.cpp
index 65b8441..7ae2fd7 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -45,6 +45,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
GLuint q = worldShader.getUniform("textu");
GLuint n = worldShader.getUniform("normu");
GLuint b = worldShader.getUniform("AmbientLight");
+ GLuint f = worldShader.getUniform("Flipped");
/***********
* SETUP *
@@ -119,7 +120,7 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
*************/
entities.each<Render, Position>(
- [this, a, q, t, n](entityx::Entity, Render &r, Position &p) {
+ [this, a, q, t, n, f](entityx::Entity, Render &r, Position &p) {
if (!r.visible)
return;
@@ -144,6 +145,8 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
(float)p.x-w, (float)p.y+h, 00.0f, 0.0f, 0.0f,
};
+ bool flipped = false;
+
// TODO flip nicely (aka model transformations)
if (r.flipX) {
std::swap(tri_data[3], tri_data[8]);
@@ -151,8 +154,12 @@ void RenderSystem::update([[maybe_unused]] entityx::EntityManager& entities,
std::swap(tri_data[23], tri_data[28]);
tri_data[18] = tri_data[23];
+
+ flipped = true;
}
+ glUniform1i(f, flipped ? 1 : 0);
+
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, r.texture.tex);
glUniform1i(q, 0);
@@ -244,6 +251,7 @@ int RenderSystem::init(void)
worldShader.addUniform("LightColor");
worldShader.addUniform("LightNum");
worldShader.addUniform("AmbientLight");
+ worldShader.addUniform("Flipped");
glEnableVertexAttribArray(worldShader.getAttribute("vertex"));
glUseProgram(worldShader.getProgram());