| @@ -70,16 +70,17 @@ void Debug::DrawBox(vec3 a, vec3 b, vec4 color) | |||||
| void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) | void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) | ||||
| { | { | ||||
| mat4 view_proj = proj * view; | |||||
| mat4 const view_proj = proj * view; | |||||
| //Pos to center | |||||
| //Pos to center | |||||
| vec3 p0 = (inverse(view) * vec4(vec3::zero, 1.f)).xyz; | vec3 p0 = (inverse(view) * vec4(vec3::zero, 1.f)).xyz; | ||||
| //Near plane | //Near plane | ||||
| vec4 p[4] = { inverse(view_proj) * vec4(-1.f, 1.f, -1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f, 1.f, -1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f,-1.f, -1.f, 1.f), | |||||
| inverse(view_proj) * vec4(-1.f,-1.f, -1.f, 1.f) }; | |||||
| mat4 const inv_view_proj = inverse(view_proj); | |||||
| vec4 p[4] = { inv_view_proj * vec4(-1.f, 1.f, -1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f, 1.f, -1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f,-1.f, -1.f, 1.f), | |||||
| inv_view_proj * vec4(-1.f,-1.f, -1.f, 1.f) }; | |||||
| for (int i = 0; i < 4; i++) | for (int i = 0; i < 4; i++) | ||||
| p[i] = p[i] / p[i].w; | p[i] = p[i] / p[i].w; | ||||
| @@ -93,14 +94,15 @@ void Debug::DrawViewProj(mat4 view, mat4 proj, vec4 color) | |||||
| void Debug::DrawViewProj(mat4 view_proj, vec4 color) | void Debug::DrawViewProj(mat4 view_proj, vec4 color) | ||||
| { | { | ||||
| //Near plane | //Near plane | ||||
| vec4 p[8] = { inverse(view_proj) * vec4(-1.f, 1.f, 1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f, 1.f, 1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f,-1.f, 1.f, 1.f), | |||||
| inverse(view_proj) * vec4(-1.f,-1.f, 1.f, 1.f), | |||||
| inverse(view_proj) * vec4(-1.f, 1.f,-1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f, 1.f,-1.f, 1.f), | |||||
| inverse(view_proj) * vec4( 1.f,-1.f,-1.f, 1.f), | |||||
| inverse(view_proj) * vec4(-1.f,-1.f,-1.f, 1.f) | |||||
| mat4 const inv_view_proj = inverse(view_proj); | |||||
| vec4 p[8] = { inv_view_proj * vec4(-1.f, 1.f, 1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f, 1.f, 1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f,-1.f, 1.f, 1.f), | |||||
| inv_view_proj * vec4(-1.f,-1.f, 1.f, 1.f), | |||||
| inv_view_proj * vec4(-1.f, 1.f,-1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f, 1.f,-1.f, 1.f), | |||||
| inv_view_proj * vec4( 1.f,-1.f,-1.f, 1.f), | |||||
| inv_view_proj * vec4(-1.f,-1.f,-1.f, 1.f) | |||||
| }; | }; | ||||
| for (int i = 0; i < 8; i++) | for (int i = 0; i < 8; i++) | ||||
| p[i] = p[i] / p[i].w; | p[i] = p[i] / p[i].w; | ||||
| @@ -17,6 +17,21 @@ | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| /* | |||||
| * Hardcoded constants for colours | |||||
| */ | |||||
| vec4 const Color::black = vec4(0, 0, 0, 1); | |||||
| vec4 const Color::red = vec4(1, 0, 0, 1); | |||||
| vec4 const Color::green = vec4(0, 1, 0, 1); | |||||
| vec4 const Color::yellow = vec4(1, 1, 0, 1); | |||||
| vec4 const Color::blue = vec4(0, 0, 1, 1); | |||||
| vec4 const Color::magenta = vec4(1, 0, 1, 1); | |||||
| vec4 const Color::cyan = vec4(0, 1, 1, 1); | |||||
| vec4 const Color::white = vec4(1, 1, 1, 1); | |||||
| /* | |||||
| * Conversion from colours to hexadecimal | |||||
| */ | |||||
| String Color::HexString4Bpp(vec3 c) | String Color::HexString4Bpp(vec3 c) | ||||
| { | { | ||||
| uvec3 c2 = (uvec3)(clamp(c, 0.f, 1.f) * 255.999f); | uvec3 c2 = (uvec3)(clamp(c, 0.f, 1.f) * 255.999f); | ||||
| @@ -14,6 +14,7 @@ | |||||
| #include <lol/base/array.h> | #include <lol/base/array.h> | ||||
| #include <lol/debug/lines.h> | #include <lol/debug/lines.h> | ||||
| #include <lol/image/color.h> | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -32,7 +33,7 @@ void DrawInner(TREE *tree, Array<TBB, vec4> &boxes, | |||||
| Array<TE *, int, vec4> &elements, | Array<TE *, int, vec4> &elements, | ||||
| Array<int, TBB> &leaves, int children, vec4 color) | Array<int, TBB> &leaves, int children, vec4 color) | ||||
| { | { | ||||
| boxes.Push(tree->GetAABB(), vec4(1.f)); | |||||
| boxes.Push(tree->GetAABB(), Color::white); | |||||
| leaves.Push(0, boxes.Last().m1); | leaves.Push(0, boxes.Last().m1); | ||||
| while (leaves.Count() > 0) | while (leaves.Count() > 0) | ||||
| { | { | ||||
| @@ -49,7 +50,7 @@ void DrawInner(TREE *tree, Array<TBB, vec4> &boxes, | |||||
| } | } | ||||
| } | } | ||||
| if (!done) | if (!done) | ||||
| elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, vec4(1, 0, 0, 1)); | |||||
| elements.Push(tree->GetElements()[tree->GetTree()[leaves[0].m1].m_elements[j]].m_element, 1, Color::red); | |||||
| } | } | ||||
| for (int i = 0; i < children; i++) | for (int i = 0; i < children; i++) | ||||
| @@ -16,6 +16,7 @@ | |||||
| #include <lol/base/array.h> | #include <lol/base/array.h> | ||||
| #include <lol/debug/lines.h> | #include <lol/debug/lines.h> | ||||
| #include <lol/image/color.h> | |||||
| namespace lol | namespace lol | ||||
| { | { | ||||
| @@ -34,8 +35,8 @@ void Draw(PortalDoor<TE>& port, vec4 color) | |||||
| // Draw normal | // Draw normal | ||||
| vec3 p = port.m_center + port.m_up * port.m_size.y * .5f; | vec3 p = port.m_center + port.m_up * port.m_size.y * .5f; | ||||
| Debug::DrawLine(p, p + port.m_normal, vec4(1, 0, 0, 1)); | |||||
| Debug::DrawLine(p, p + port.m_up, vec4(0, 1, 0, 1)); | |||||
| Debug::DrawLine(p, p + port.m_normal, Color::red); | |||||
| Debug::DrawLine(p, p + port.m_up, Color::green); | |||||
| // Draw door | // Draw door | ||||
| for (int l = 0; l < 4; l++) | for (int l = 0; l < 4; l++) | ||||
| Debug::DrawLine(points[l], points[(l + 1) % 4], color); | Debug::DrawLine(points[l], points[(l + 1) % 4], color); | ||||
| @@ -308,17 +309,17 @@ public: | |||||
| for (int i = 0; i < visible_rooms[j]->m_doors.Count(); i++) | for (int i = 0; i < visible_rooms[j]->m_doors.Count(); i++) | ||||
| { | { | ||||
| PortalDoor<TE>* port = visible_rooms[j]->m_doors[i]; | PortalDoor<TE>* port = visible_rooms[j]->m_doors[i]; | ||||
| Debug::Draw(*port, vec4(0, 1, 1, 1)); | |||||
| Debug::Draw(*port, Color::cyan); | |||||
| tmp += vec4(port->m_center, 1.f); | tmp += vec4(port->m_center, 1.f); | ||||
| } | } | ||||
| tmp /= tmp.w; | tmp /= tmp.w; | ||||
| Debug::DrawBox(tmp.xyz - vec3(1.f), tmp.xyz + vec3(1.f), vec4(1, 1, 0, 1)); | |||||
| Debug::DrawBox(tmp.xyz - vec3(1.f), tmp.xyz + vec3(1.f), Color::yellow); | |||||
| } | } | ||||
| for (int i = 0; i < ignore_doors.Count(); i++) | for (int i = 0; i < ignore_doors.Count(); i++) | ||||
| { | { | ||||
| PortalDoor<TE>* port = ignore_doors[i]; | PortalDoor<TE>* port = ignore_doors[i]; | ||||
| Debug::Draw(*port, vec4(1, 0, 1, 1)); | |||||
| Debug::DrawViewProj(port->m_view, port->m_proj, vec4(1, 0, 1, 1)); | |||||
| Debug::Draw(*port, Color::magenta); | |||||
| Debug::DrawViewProj(port->m_view, port->m_proj, Color::magenta); | |||||
| } | } | ||||
| #endif //LOL_BUILD_DEBUG | #endif //LOL_BUILD_DEBUG | ||||
| } | } | ||||
| @@ -230,14 +230,14 @@ public: | |||||
| * Note: XYZ values are normalised using a D65 illuminant if | * Note: XYZ values are normalised using a D65 illuminant if | ||||
| * no white value is provided. | * no white value is provided. | ||||
| */ | */ | ||||
| static vec3 CIEXYZToCIELab(vec3 src, vec3 white) | |||||
| static vec3 CIEXYZToCIELab(vec3 src, vec3 white_value) | |||||
| { | { | ||||
| float const a = (6.0 * 6.0 * 6.0) / (29 * 29 * 29); | float const a = (6.0 * 6.0 * 6.0) / (29 * 29 * 29); | ||||
| float const b = (29.0 * 29.0) / (3 * 6 * 6); | float const b = (29.0 * 29.0) / (3 * 6 * 6); | ||||
| float const c = 4.0 / 29; | float const c = 4.0 / 29; | ||||
| float const d = 1.0 / 3; | float const d = 1.0 / 3; | ||||
| src /= white; | |||||
| src /= white_value; | |||||
| vec3 f = b * src + vec3(c); | vec3 f = b * src + vec3(c); | ||||
| if (src.x > a) | if (src.x > a) | ||||
| @@ -257,9 +257,9 @@ public: | |||||
| return CIEXYZToCIELab(src, vec3(95.047f, 100.f, 108.883f)); | return CIEXYZToCIELab(src, vec3(95.047f, 100.f, 108.883f)); | ||||
| } | } | ||||
| static vec4 CIEXYZToCIELab(vec4 src, vec4 white) | |||||
| static vec4 CIEXYZToCIELab(vec4 src, vec4 white_value) | |||||
| { | { | ||||
| return vec4(CIEXYZToCIELab(src.rgb, white.rgb), src.a); | |||||
| return vec4(CIEXYZToCIELab(src.rgb, white_value.rgb), src.a); | |||||
| } | } | ||||
| static vec4 CIEXYZToCIELab(vec4 src) | static vec4 CIEXYZToCIELab(vec4 src) | ||||
| @@ -285,6 +285,11 @@ public: | |||||
| static String HexString4Bpp(vec4 c); | static String HexString4Bpp(vec4 c); | ||||
| static String HexString8Bpp(vec3 c); | static String HexString8Bpp(vec3 c); | ||||
| static String HexString8Bpp(vec4 c); | static String HexString8Bpp(vec4 c); | ||||
| /* | |||||
| * Some predefined colours | |||||
| */ | |||||
| static const vec4 black, red, green, yellow, blue, magenta, cyan, white; | |||||
| }; | }; | ||||
| } /* namespace lol */ | } /* namespace lol */ | ||||