|
|
@@ -21,6 +21,7 @@
|
|
|
#include <anki/collision/ConvexHullShape.h>
|
|
|
#include <anki/util/Rtti.h>
|
|
|
#include <anki/Ui.h> /// XXX
|
|
|
+#include <anki/scene/SoftwareRasterizer.h> /// XXX
|
|
|
|
|
|
namespace anki
|
|
|
{
|
|
|
@@ -82,10 +83,10 @@ Error Dbg::run(RenderingContext& ctx)
|
|
|
CommandBufferPtr& cmdb = ctx.m_commandBuffer;
|
|
|
cmdb->beginRenderPass(m_fb);
|
|
|
|
|
|
- FrustumComponent& camFr = *ctx.m_frustumComponent;
|
|
|
- SceneNode& cam = camFr.getSceneNode();
|
|
|
+ FrustumComponent& camFrc = *ctx.m_frustumComponent;
|
|
|
+ SceneNode& cam = camFrc.getSceneNode();
|
|
|
m_drawer->prepareFrame(cmdb);
|
|
|
- m_drawer->setViewProjectionMatrix(camFr.getViewProjectionMatrix());
|
|
|
+ m_drawer->setViewProjectionMatrix(camFrc.getViewProjectionMatrix());
|
|
|
m_drawer->setModelMatrix(Mat4::getIdentity());
|
|
|
// m_drawer->drawGrid();
|
|
|
|
|
|
@@ -125,7 +126,10 @@ Error Dbg::run(RenderingContext& ctx)
|
|
|
{
|
|
|
Error err = node.iterateComponentsOfType<FrustumComponent>(
|
|
|
[&](FrustumComponent& frc) -> Error {
|
|
|
- sceneDrawer.draw(frc);
|
|
|
+ if(&frc != &camFrc)
|
|
|
+ {
|
|
|
+ sceneDrawer.draw(frc);
|
|
|
+ }
|
|
|
return ErrorCode::NONE;
|
|
|
});
|
|
|
(void)err;
|
|
|
@@ -156,32 +160,125 @@ Error Dbg::run(RenderingContext& ctx)
|
|
|
|
|
|
#if 0
|
|
|
{
|
|
|
- static Bool firstTime = true;
|
|
|
- static UiInterfaceImpl* interface;
|
|
|
- static Canvas* canvas;
|
|
|
+ m_drawer->setViewProjectionMatrix(camFrc.getViewProjectionMatrix());
|
|
|
+ m_drawer->setModelMatrix(Mat4::getIdentity());
|
|
|
+ CollisionDebugDrawer cd(m_drawer);
|
|
|
+ Mat4 proj = camFrc.getProjectionMatrix();
|
|
|
|
|
|
- if(firstTime)
|
|
|
- {
|
|
|
- firstTime = false;
|
|
|
+ Array<Plane, 6> planes;
|
|
|
+ Array<Plane*, 6> pplanes = {&planes[0],
|
|
|
+ &planes[1],
|
|
|
+ &planes[2],
|
|
|
+ &planes[3],
|
|
|
+ &planes[4],
|
|
|
+ &planes[5]};
|
|
|
+ extractClipPlanes(proj, pplanes);
|
|
|
|
|
|
- auto alloc = getAllocator();
|
|
|
- interface = alloc.newInstance<UiInterfaceImpl>(alloc);
|
|
|
- ANKI_CHECK(interface->init(&getGrManager(), &getResourceManager()));
|
|
|
+ planes[5].accept(cd);
|
|
|
|
|
|
- canvas = alloc.newInstance<Canvas>(interface);
|
|
|
- canvas->setDebugDrawEnabled();
|
|
|
- }
|
|
|
+ m_drawer->setViewProjectionMatrix(camFrc.getViewProjectionMatrix());
|
|
|
+ m_drawer->setModelMatrix(Mat4::getIdentity());
|
|
|
|
|
|
- cmdb->setViewport(10, 10, 1024, 1024);
|
|
|
- canvas->update(0.1);
|
|
|
- interface->beginRendering(cmdb);
|
|
|
- canvas->paint();
|
|
|
- interface->endRendering();
|
|
|
- cmdb->setViewport(0, 0, m_r->getWidth(), m_r->getHeight());
|
|
|
+ m_drawer->setColor(Vec4(0.0, 1.0, 1.0, 1.0));
|
|
|
+ PerspectiveFrustum frc;
|
|
|
+ const PerspectiveFrustum& cfrc =
|
|
|
+ (const PerspectiveFrustum&)camFrc.getFrustum();
|
|
|
+ frc.setAll(
|
|
|
+ cfrc.getFovX(), cfrc.getFovY(), cfrc.getNear(), cfrc.getFar());
|
|
|
+ cd.visit(frc);
|
|
|
+
|
|
|
+ m_drawer->drawLine(Vec3(0.0), planes[5].getNormal().xyz() * 100.0,
|
|
|
+ Vec4(1.0));
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
#if 1
|
|
|
+ {
|
|
|
+ m_drawer->setViewProjectionMatrix(Mat4::getIdentity());
|
|
|
+ m_drawer->setModelMatrix(Mat4::getIdentity());
|
|
|
+ Mat4 proj = camFrc.getProjectionMatrix();
|
|
|
+ Mat4 view = camFrc.getViewMatrix();
|
|
|
+
|
|
|
+ Array<Vec4, 12> ltriangle = {Vec4(0.0, 2.0, 2.0, 1.0),
|
|
|
+ Vec4(4.0, 2.0, 2.0, 1.0),
|
|
|
+ Vec4(0.0, 8.0, 2.0, 1.0),
|
|
|
+
|
|
|
+ Vec4(0.0, 8.0, 2.0, 1.0),
|
|
|
+ Vec4(4.0, 2.0, 2.0, 1.0),
|
|
|
+ Vec4(4.0, 8.0, 2.0, 1.0),
|
|
|
+
|
|
|
+ Vec4(0.9, 2.0, 1.9, 1.0),
|
|
|
+ Vec4(4.9, 2.0, 1.9, 1.0),
|
|
|
+ Vec4(0.9, 8.0, 1.9, 1.0),
|
|
|
+
|
|
|
+ Vec4(0.9, 8.0, 1.9, 1.0),
|
|
|
+ Vec4(4.9, 2.0, 1.9, 1.0),
|
|
|
+ Vec4(4.9, 8.0, 1.9, 1.0)};
|
|
|
+
|
|
|
+ SoftwareRasterizer r;
|
|
|
+ r.init(getAllocator());
|
|
|
+ r.prepare(
|
|
|
+ view, proj, m_r->getTileCountXY().x(), m_r->getTileCountXY().y());
|
|
|
+ r.draw(<riangle[0][0], 12, sizeof(Vec4));
|
|
|
+
|
|
|
+ m_drawer->begin(PrimitiveTopology::TRIANGLES);
|
|
|
+ U count = 0;
|
|
|
+ for(U y = 0; y < m_r->getTileCountXY().y(); ++y)
|
|
|
+ {
|
|
|
+ for(U x = 0; x < m_r->getTileCountXY().x(); ++x)
|
|
|
+ {
|
|
|
+ F32 d = r.m_zbuffer[y * m_r->getTileCountXY().x() + x].get()
|
|
|
+ / F32(MAX_U32);
|
|
|
+
|
|
|
+ if(d < 1.0)
|
|
|
+ {
|
|
|
+ F32 zNear = camFrc.getFrustum().getNear();
|
|
|
+ F32 zFar = camFrc.getFrustum().getFar();
|
|
|
+ F32 ld =
|
|
|
+ (2.0 * zNear) / (zFar + zNear - d * (zFar - zNear));
|
|
|
+ m_drawer->setColor(Vec4(ld));
|
|
|
+
|
|
|
+ ++count;
|
|
|
+ Vec2 min(F32(x) / m_r->getTileCountXY().x(),
|
|
|
+ F32(y) / m_r->getTileCountXY().y());
|
|
|
+
|
|
|
+ Vec2 max(F32(x + 1) / m_r->getTileCountXY().x(),
|
|
|
+ F32(y + 1) / m_r->getTileCountXY().y());
|
|
|
+
|
|
|
+ min = min * 2.0 - 1.0;
|
|
|
+ max = max * 2.0 - 1.0;
|
|
|
+
|
|
|
+ m_drawer->pushBackVertex(Vec3(min.x(), min.y(), 0.0));
|
|
|
+ m_drawer->pushBackVertex(Vec3(max.x(), min.y(), 0.0));
|
|
|
+ m_drawer->pushBackVertex(Vec3(min.x(), max.y(), 0.0));
|
|
|
+
|
|
|
+ m_drawer->pushBackVertex(Vec3(min.x(), max.y(), 0.0));
|
|
|
+ m_drawer->pushBackVertex(Vec3(max.x(), min.y(), 0.0));
|
|
|
+ m_drawer->pushBackVertex(Vec3(max.x(), max.y(), 0.0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ m_drawer->end();
|
|
|
+ // printf("%u\n", count);
|
|
|
+
|
|
|
+ m_drawer->setViewProjectionMatrix(camFrc.getViewProjectionMatrix());
|
|
|
+ Vec3 offset(0.0, 0.0, 0.0);
|
|
|
+ for(U i = 0; i < ltriangle.getSize() / 3; ++i)
|
|
|
+ {
|
|
|
+ m_drawer->drawLine(ltriangle[i * 3 + 0].xyz() + offset,
|
|
|
+ ltriangle[i * 3 + 1].xyz() + offset,
|
|
|
+ Vec4(0, 0.2, 0, 1));
|
|
|
+ m_drawer->drawLine(ltriangle[i * 3 + 1].xyz() + offset,
|
|
|
+ ltriangle[i * 3 + 2].xyz() + offset,
|
|
|
+ Vec4(0.0, 0.2, 0.0, 1.0));
|
|
|
+ m_drawer->drawLine(ltriangle[i * 3 + 2].xyz() + offset,
|
|
|
+ ltriangle[i * 3 + 0].xyz() + offset,
|
|
|
+ Vec4(0.0, 0.2, 0.0, 1.0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+#if 0
|
|
|
{
|
|
|
CollisionDebugDrawer cd(m_drawer);
|
|
|
|
|
|
@@ -200,40 +297,40 @@ Error Dbg::run(RenderingContext& ctx)
|
|
|
m_drawer->setModelMatrix(Mat4::getIdentity());
|
|
|
m_drawer->drawLine(polyw[0], polyw[1], Vec4(1.0));
|
|
|
|
|
|
- Vec4 p0 = camFr.getViewMatrix() * polyw[0].xyz1();
|
|
|
+ Vec4 p0 = camFrc.getViewMatrix() * polyw[0].xyz1();
|
|
|
p0.w() = 0.0;
|
|
|
- Vec4 p1 = camFr.getViewMatrix() * polyw[1].xyz1();
|
|
|
+ Vec4 p1 = camFrc.getViewMatrix() * polyw[1].xyz1();
|
|
|
p1.w() = 0.0;
|
|
|
|
|
|
Vec4 r = p1 - p0;
|
|
|
r.normalize();
|
|
|
|
|
|
- Vec4 a = camFr.getProjectionMatrix() * p0.xyz1();
|
|
|
+ Vec4 a = camFrc.getProjectionMatrix() * p0.xyz1();
|
|
|
a /= a.w();
|
|
|
|
|
|
Vec4 i;
|
|
|
if(r.z() > 0)
|
|
|
{
|
|
|
- // Plane near(Vec4(0, 0, -1, 0), camFr.getFrustum().getNear() +
|
|
|
+ // Plane near(Vec4(0, 0, -1, 0), camFrc.getFrustum().getNear() +
|
|
|
// 0.001);
|
|
|
// Bool in = near.intersectRay(p0, r * 100000.0, i);
|
|
|
- i.z() = -camFr.getFrustum().getNear();
|
|
|
+ i.z() = -camFrc.getFrustum().getNear();
|
|
|
F32 t = (i.z() - p0.z()) / r.z();
|
|
|
i.x() = p0.x() + t * r.x();
|
|
|
i.y() = p0.y() + t * r.y();
|
|
|
|
|
|
- i = camFr.getProjectionMatrix() * i.xyz1();
|
|
|
+ i = camFrc.getProjectionMatrix() * i.xyz1();
|
|
|
i /= i.w();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- i = camFr.getProjectionMatrix() * (r * 100000.0).xyz1();
|
|
|
+ i = camFrc.getProjectionMatrix() * (r * 100000.0).xyz1();
|
|
|
i /= i.w();
|
|
|
}
|
|
|
|
|
|
/*r *= 0.01;
|
|
|
Vec4 b = polyw[0].xyz0() + r;
|
|
|
- b = camFr.getViewProjectionMatrix() * b.xyz1();
|
|
|
+ b = camFrc.getViewProjectionMatrix() * b.xyz1();
|
|
|
Vec4 d = b / b.w();*/
|
|
|
|
|
|
m_drawer->setViewProjectionMatrix(Mat4::getIdentity());
|