summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software/TransformUnit.cpp
diff options
context:
space:
mode:
authorTony Wasserka <neobrainx@gmail.com>2014-05-17 21:06:31 +0200
committerTony Wasserka <neobrainx@gmail.com>2014-05-17 21:06:31 +0200
commitfc34d5a1300d4870f996bb4658640b9b95b43270 (patch)
tree0b2e7fd219680b4b216b2026458a0470867444ba /Source/Core/VideoBackends/Software/TransformUnit.cpp
parent5391b2dd9c6fab009daf506d89045ab878c02081 (diff)
parent9e4eeb3b9b012265d0f9865aeaa3fecbf200d7fc (diff)
Merge pull request #360 from magumagu/lighting-rounding
Video backends: fix rounding in lighting computation.
Diffstat (limited to 'Source/Core/VideoBackends/Software/TransformUnit.cpp')
-rw-r--r--Source/Core/VideoBackends/Software/TransformUnit.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/Source/Core/VideoBackends/Software/TransformUnit.cpp b/Source/Core/VideoBackends/Software/TransformUnit.cpp
index 8e5bfe8a69..dee4abe51e 100644
--- a/Source/Core/VideoBackends/Software/TransformUnit.cpp
+++ b/Source/Core/VideoBackends/Software/TransformUnit.cpp
@@ -5,6 +5,8 @@
#include <cmath>
#include "Common/Common.h"
+#include "Common/MathUtil.h"
+
#include "VideoBackends/Software/BPMemLoader.h"
#include "VideoBackends/Software/CPMemLoader.h"
#include "VideoBackends/Software/NativeVertexFormat.h"
@@ -200,11 +202,6 @@ inline void AddScaledIntegerColor(const u8 *src, float scale, Vec3 &dst)
dst.z += src[3] * scale;
}
-inline float Clamp(float val, float a, float b)
-{
- return val<a?a:val>b?b:val;
-}
-
inline float SafeDivide(float n, float d)
{
return (d==0) ? (n>0?1:0) : n/d;
@@ -414,10 +411,15 @@ void TransformColor(const InputVertexData *src, OutputVertexData *dst)
LightColor(dst->mvPosition, dst->normal[0], i, colorchan, lightCol);
}
- float inv = 1.0f / 255.0f;
- chancolor[1] = (u8)(matcolor[1] * Clamp(lightCol.x * inv, 0.0f, 1.0f));
- chancolor[2] = (u8)(matcolor[2] * Clamp(lightCol.y * inv, 0.0f, 1.0f));
- chancolor[3] = (u8)(matcolor[3] * Clamp(lightCol.z * inv, 0.0f, 1.0f));
+ int light_x = int(lightCol.x);
+ int light_y = int(lightCol.y);
+ int light_z = int(lightCol.z);
+ MathUtil::Clamp(&light_x, 0, 255);
+ MathUtil::Clamp(&light_y, 0, 255);
+ MathUtil::Clamp(&light_z, 0, 255);
+ chancolor[1] = (matcolor[1] * (light_x + (light_x >> 7))) >> 8;
+ chancolor[2] = (matcolor[2] * (light_y + (light_y >> 7))) >> 8;
+ chancolor[3] = (matcolor[3] * (light_z + (light_z >> 7))) >> 8;
}
else
{
@@ -446,7 +448,9 @@ void TransformColor(const InputVertexData *src, OutputVertexData *dst)
LightAlpha(dst->mvPosition, dst->normal[0], i, alphachan, lightCol);
}
- chancolor[0] = (u8)(matcolor[0] * Clamp(lightCol / 255.0f, 0.0f, 1.0f));
+ int light_a = int(lightCol);
+ MathUtil::Clamp(&light_a, 0, 255);
+ chancolor[0] = (matcolor[0] * (light_a + (light_a >> 7))) >> 8;
}
else
{