# Tag Info

13

If you are doing a perspective image and your model has implicit intersections then, if you use "linear Z", those intersections will appear in the wrong places. For example, consider a simple ground plane with a line of telephone poles, receding into the distance, which pierce the ground (and continue below). The implicit intersections will be determined ...

8

This is likely more complicated than you would prefer, but: Compute the medial axis, which immediately yields the largest disks that fit inside the polygon: their centers are vertices (degree $\ge 3$) of the axis (see the figure below). Chin, Francis, Jack Snoeyink, and Cao An Wang. "Finding the medial axis of a simple polygon in linear time." Discrete &...

8

Funnily enough, I asked this exact question on Math.SE a couple years ago: Maximum number of vertices in intersection of triangle with box. The answer is 9 vertices, because each of the 6 planes of the box can cut off one corner of the polygon, replacing one vertex with two. So 3 vertices + 6 added vertices due to clipping = 9 total.

8

The space after clip space is normalized device coordinate space, which is obtained by dividing clip.xyz by clip.w. If W is zero... oops. Oh sure, you could put a conditional test to see if W is zero or very close to zero. Or you can just do the clipping math in clip space and never have to worry about it. No post-clipping vertex can have a W of zero, ...

6

Using Z/W for the depth buffer goes deeper than just clipping against the near and far planes. As Simon alluded to, this has to do with interpolation between the vertices of a triangle, during rasterization. Z/W is the unique option that allows NDC depth values to be correctly calculated for points in the interior of the triangle, by simply linearly ...

5

The near clipping plane in rasterizing setups with perspective projection is there to avoid a divide by 0 and bound the possible depths for orthogonal projection. With a bit of extra math you can make the depth stored in the depth buffer linear again. However you still need the guard against the divide by 0. In raytracing the near plane can be at 0 no ...

4

"Go not to the CG Elves for counsel for they will say both no and yes". Yes and No. As noted in another post, these issues don't exist with ray tracing but I'll assume you are interested in standard rasterisation. It's possible to dispose of near clipping by using homogeneous rendering but that can introduce additional cost. (e.g more expensive ...

4

Hint: The three coordinates can be handled independently. For instance in $x$, you need to solve $$x_0 + t (x_1-x_0) = 0$$ and $$x_0 + t (x_1-x_0) = x_{max}$$

4

The near clipping plane is a fundamental feature of projective rasterization. To borrow a diagram from Eric Lengyel's Projection Matrix Tricks presentation: The displayed region of clip space (that you can think of rasterization as happening in) is a box which has a "near" face. This is associated with the near clip plane. But we can push the far clip plane ...

3

The GS is responsible for assigning a particular primitive to a particular layer. The GS is also responsible for writing values for gl_ClipDistance for a particular primitive. So the GS is perfectly capable of doing both of those things: assigning a primitive to a layer and doing the clip-plane computations for that layer. And if you need to "deactivate&...

3

Maybe it helps to draw out the steps of the algorithm. Here is an example for TBLR The red is the worst case: clip top, clip bottom, clip left, clip right. Four steps! The green is the best case: clip top, clip bottom, done. Two steps. The blue is a middle case: clip top, clip bottom, clip left, done. Three steps.

3

One good reason to do clipping in homogeneous space is that the perspective division loses the distinction between regions behind the camera and in front of the camera. Points in front of the camera have $w > 0$, and behind the camera $w < 0$. After dividing by $w$, points behind the camera get mapped (with a sign flip) to the same $x, y, z$ NDC space ...

3

The outcodes just represent four boolean flags as a bitfield. Codewise it is easier to move a bitfield around than four booleans. Functionality-wise it becomes very easy to check if any bits are set (just check if zero), and combining outcodes is as simple as a bitwise OR. On a side-note: Since bit-operations are fast, it is not a performance issue that the ...

3

Since this is a homework question, I'll give hints rather than a numerical answer. Clipping a convex polygon Think about how many times the polygon can cross each edge of the rectangle. In general, a polygon can cross one of the edges of the rectangle an arbitrarily large number of times. How is this number reduced if the polygon is convex? This will give ...

2

The $t$ parameter represents the distance from the ray's origin point to the intersection point, as a multiple of the ray's direction vector. It is positive for intersections "in front" of the origin, negative for those "behind" the origin as judged by the direction vector. In raytracing we always discard any intersections with $t < 0$, because we don't ...

2

3D clipping is usually done in clipspace coordinates, that means the perspective matrix is used for sending the primitives to clipspace before doing the actual perspective projection. You can visualize the clipspace as a view frustum but with the shape of a box. So it is very fast to clip primitives against a AABB. The math is a little involved, but is all ...

2

I think it depends on what your goal is and what kind of initial data you are provided with. I don't think that dividing by the forth coordinate solves a clipping task. What it does is switching of the coordinates of your objects from 3D projective (four components) to 3D Euclidean (three components). I would say, the basic component you need is a procedure ...

2

The diagram on the Wikipedia entry for Cohen-Sutherland Clipping explains it pretty well: left central right top 1001 1000 1010 central 0001 0000 0010 bottom 0101 0100 0110 So in your example, p1 would be left, central, so its code would be 0001. p2 would be central, bottom, so 0100 p3 would be central, central, so ...

2

Points in front of the camera have $w > 0$ strictly, by definition. I would say that if clipping is giving you points with $w = 0$ then something is going wrong. Consider the left/right/top/bottom clip planes. There is no way that a triangle can span from part of the visible frustum, to the $w = 0$ camera plane or behind it, without also crossing outside ...

1

First, regarding the specific problem of bits of the geometry being lost to the near and far planes, this can be solved by using depth clamping instead of depth clipping. This disables clipping against the near and far planes, in favor of clamping the output depth values to [0, 1]. (Geometry behind the camera will still be clipped though.) Given this, ...

1

A vertex consists of not just the position, but all of the values passed from the vertex processing stage to the rasterizer. So if a vertex gets clipped, the new vertices generated in that process must generate new values for those vertex processing outputs. It does this using the same math that it uses to generate the new vertex position.

1

Clipping could be done in normalised device coordinates as all primitives with z-coordinates outside -1 to 1 are outside the clipping planes. However, there is no reason not to do it in clip coordinates by considering z-coordinates from -w to w. Theoretically it possible. However it seems there is performance increase when doing the clipping in clip ...

1

It sounds like what you need is a scissor test. It's specifically designed for clipping against an unrotated rectangle, and should be faster than messing about with the stencil buffer.

1

Sounds like you’re looking for a way to do a Boolean union operation. There’s a couple of algorithms linked from that article that should do the trick.

1

Quick idea: render platforms color to screen quad render mesh and platforms to screen quad, but as a mask. For example mesh is white, rest is black. in another pass sample these textures and if mask is white, color it with sample from first texture. Render to screen.

1

Taken from Wikipedia's article on Cohen-Sutherland: Both endpoints are in different regions: in case of this nontrivial situation the algorithm finds one of the two points that is outside the viewport region (there will be at least one point outside). The intersection of the outpoint and extended viewport border is then calculated (i.e. with the ...

1

Rather than making one spatial subdivision structure do double duty in representing both the voxels and the triangles, I would suggest creating a separate BVH for the mesh. You can find many articles and papers about BVH-building algorithms on the web. It's likely to be a more efficiently queryable representation of the mesh than the octree would be. Given ...

Only top voted, non community-wiki answers of a minimum length are eligible