Fix loading of dds normal maps.
Fix computation of angular deviation.
This commit is contained in:
parent
fbfc9c2bc1
commit
6cee7e2892
@ -834,10 +834,10 @@ void DirectDrawSurface::readBlockImage(Image * img)
|
||||
|
||||
static Color32 buildNormal(uint8 x, uint8 y)
|
||||
{
|
||||
float nx = 2 * (x / 255) - 1;
|
||||
float ny = 2 * (x / 255) - 1;
|
||||
float nx = 2 * (x / 255.0f) - 1;
|
||||
float ny = 2 * (x / 255.0f) - 1;
|
||||
float nz = sqrtf(1 - nx*nx - ny*ny);
|
||||
uint8 z = clamp(int(255 * (nz + 1) / 2), 0, 255);
|
||||
uint8 z = clamp(int(255.0f * (nz + 1) / 2.0f), 0, 255);
|
||||
|
||||
return Color32(x, y, z);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include <nvimage/DirectDrawSurface.h>
|
||||
|
||||
#include <nvmath/Color.h>
|
||||
#include <nvmath/Vector.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@ -113,13 +114,14 @@ struct NormalError
|
||||
|
||||
void addSample(nv::Color32 o, nv::Color32 c)
|
||||
{
|
||||
float xo = o.r / 255.0f;
|
||||
float yo = o.g / 255.0f;
|
||||
float zo = o.b / 255.0f;
|
||||
float xc = c.r / 255.0f;
|
||||
float yc = c.g / 255.0f;
|
||||
float zc = c.b / 255.0f;
|
||||
ade += acosf(xo * xc + yo * yc + zo * zc);
|
||||
nv::Vector3 vo = nv::Vector3(o.r, o.g, o.b);
|
||||
nv::Vector3 vc = nv::Vector3(c.r, c.g, c.b);
|
||||
|
||||
vo = nv::normalize(2 * (vo / 255.0f) - 1);
|
||||
vc = nv::normalize(2 * (vc / 255.0f) - 1);
|
||||
|
||||
ade += acosf(nv::clamp(dot(vo, vc), -1.0f, 1.0f));
|
||||
|
||||
samples++;
|
||||
}
|
||||
|
||||
@ -252,7 +254,6 @@ int main(int argc, char *argv[])
|
||||
error_normal.done();
|
||||
|
||||
|
||||
|
||||
printf("Image size compared: %dx%d\n", w, h);
|
||||
if (w != w0 || w != w1 || h != h0 || h != h1) {
|
||||
printf("--- NOTE: only the overlap between the 2 images (%d,%d) and (%d,%d) was compared\n", w0, h0, w1, h1);
|
||||
@ -262,6 +263,11 @@ int main(int argc, char *argv[])
|
||||
printf("Color:\n");
|
||||
error_total.print();
|
||||
|
||||
if (compareNormal)
|
||||
{
|
||||
error_normal.print();
|
||||
}
|
||||
|
||||
if (compareAlpha)
|
||||
{
|
||||
printf("Alpha:\n");
|
||||
|
Loading…
Reference in New Issue
Block a user