java - Omit off-screen triangles -
i creating simple little software 3d engine. right polygon doesn't render if of vertexes outside of frustum, that's fine , until close polygon , vertexes off screen middle still inside frustum omits anyways. try render anyways need optimizations first 1 thought of.
here gif & code of problem if didn't understand trying across.
boolean v1inside = v1.isinsideviewfrustum(); boolean v2inside = v2.isinsideviewfrustum(); boolean v3inside = v3.isinsideviewfrustum(); if (v1inside && v2inside && v3inside) { rasterizetriangle(v1, v2, v3); return; } if (!(v1inside || v2inside || v3inside)) { return; }
you can implement conservative approach frustum culling, gives false positives (instead of false negative). typical approach reject triangle, if vertices fall on wrong side of frustum plane.
b | b | c --+-------+------- c d | | e | | ---+-------+------- d f | g | h
here in 2d case, there 4 clipping planes: a, b, c, d. approach rejects triangle above line/plane 'c', below line 'd', left of line 'a' or right of line 'b', not rejecting e.g. case of vertices in segments b, g , h.
this kind of culling easy implement after perspective projection, giving simple equations: e.g. x0,x1,x2 < -1, or using planar equations of frustum:
dot_product(vertex, plane) < constant_i.
Comments
Post a Comment