Skip to content
Snippets Groups Projects
Commit f79f5d2d authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Tidy code

parent fa62a068
No related branches found
No related tags found
1 merge request!151Implements #216 triangle renderer
......@@ -49,6 +49,8 @@ __device__ void drawLine(TextureObject<int> &depth_out, int y, int x1, int x2, f
}
}
/* See: https://github.com/bcrusco/CUDA-Rasterizer */
/**
* Calculate the signed area of a given triangle.
*/
......@@ -57,7 +59,6 @@ __device__ static inline
return 0.5f * (float(c.x - a.x) * float(b.y - a.y) - float(b.x - a.x) * float(c.y - a.y));
}
// CHECKITOUT
/**
* Helper function for calculating barycentric coordinates.
*/
......@@ -66,7 +67,6 @@ __device__ static inline
return calculateSignedArea(a,b,c) / calculateSignedArea(tri[0], tri[1], tri[2]);
}
// CHECKITOUT
/**
* Calculate barycentric coordinates.
* TODO: Update to handle triangles coming in and not the array
......@@ -79,7 +79,6 @@ __device__ static
return make_float3(alpha, beta, gamma);
}
// CHECKITOUT
/**
* Check if a barycentric coordinate is within the boundaries of a triangle.
*/
......@@ -136,78 +135,21 @@ float getZAtCoordinate(const float3 &barycentricCoord, const float (&tri)[3]) {
const int maxX = max(v[0].x, max(v[1].x, v[2].x));
const int maxY = max(v[0].y, max(v[1].y, v[2].y));
// Remove really large triangles
if ((maxX - minX) * (maxY - minY) > 200) return;
//int incx = ((maxX - minX) / 20) + 1;
//int incy = ((maxY - minY) / 20) + 1;
float2 vs0 = make_float2(v[0].x, v[0].y);
float2 vs1 = make_float2(v[1].x, v[1].y);
float2 vs2 = make_float2(v[2].x, v[2].y);
for (int sy=minY; sy <= maxY; ++sy) {
for (int sx=minX; sx <= maxX; ++sx) {
if (sx >= params.camera.width || sx < 0 || sy >= params.camera.height || sy < 0) continue;
//float2 q = make_float2(sx, sy);
//float s = det(q - vs0, vs1) / det(vs0, vs1); //cross(q, vs2) / cross(vs1, vs2);
//float t = det(vs0, q - vs1) / det(vs0, vs1); //cross(vs1, q) / cross(vs1, vs2);
float3 baryCentricCoordinate = calculateBarycentricCoordinate(v, make_short2(sx, sy));
if (isBarycentricCoordInBounds(baryCentricCoordinate)) {
//if (s >= 0 && t >= 0 && ss+t <= 1) {
//if (insideTriangle(vs0,vs1,vs2, make_float2(sx,sy))) {
/*float dist1 = length2(sx - s[0].x, sy - s[0].y);
float dist2 = length2(sx - s[1].x, sy - s[1].y);
float dist3 = length2(sx - s[2].x, sy - s[2].y);
float maxlen = max(dist1, max(dist2, dist3));
if (maxlen > 0.0f) {
dist1 = 1.0f - dist1 / maxlen;
dist2 = 1.0f - dist2 / maxlen;
dist3 = 1.0f - dist3 / maxlen;
}
float new_depth = (maxlen == 0.0f) ? d[0] : (d[0]*dist1 + d[1]*dist2 + d[2]*dist3) / (dist1+dist2+dist3);
//if (new_depth < params.camera.minDepth || new_depth > params.camera.maxDepth) continue;*/
//float new_depth = d[0]; //(A > 0) ? (B > 0) ? 6.0f : 5.0f : (B > 0) ? 4.0f : 3.0f;
float new_depth = getZAtCoordinate(baryCentricCoordinate, d);
atomicMin(&depth_out(sx,sy), int(new_depth*1000.0f));
}
}
}
// OLD
/*const int dx = (A) ? -1 : 1;
const int dy = (B) ? -1 : 1;
s[1].x = (A) ? s[0].x - s[1].x : s[1].x - s[0].x;
s[1].y -= s[0].y;
s[2].x -= s[0].x;
s[2].y = (B) ? s[0].y - s[2].y : s[2].y - s[0].y;
//if (s[1].y < 0 || s[2].x < 0) return;
s[1].x = min(s[1].x,20);
s[2].y = min(s[2].y,20);
for (int sx=0; sx < s[1].x+1; ++sx) {
for (int sy=0; sy < min(s[1].x - sx, s[2].y)+1; ++sy) {
//if (sx > s[2].y-sy) continue;
if (dx*sx+s[0].x >= params.camera.width || dy*sy+s[0].y >= params.camera.height) continue;
float dist1 = length2(sx,sy);
float dist2 = length2(s[1].x-sx, s[1].y-sy);
float dist3 = length2(s[2].x-sx, s[2].y-sy);
float new_depth = (dist1+dist2+dist3 == 0.0f) ? d[0] : (d[0]*dist1 + d[1]*dist2 + d[2] * dist3) / (dist1+dist2+dist3);
//if (new_depth < params.camera.minDepth || new_depth > params.camera.maxDepth) continue;
atomicMin(&depth_out(dx*sx+s[0].x,dy*sy+s[0].y), int(new_depth*1000.0f));
}
}*/
}
void ftl::cuda::triangle_render1(TextureObject<float> &depth_in, TextureObject<int> &depth_out, TextureObject<short2> &screen, const SplatParams &params, cudaStream_t stream) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment