Archived

This topic is now archived and is closed to further replies.

Software 3D Engine

This topic is 4947 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing a software renderer as a little summer project, and I want to emulate some of the NeHe demos. I wanted to do a colored triangle like opengl can do with a different color at each vertex and smooth blending across the shape. I was able to do this using barycentric space and triangles and it looked pretty cool. The Screeny Now the question is: is there a better way to do this than what I'm doing? If not, what are some things to look out for to cause the tearing I'm seeing? Thanks a bunch! -------------------------------------------------------- Life would be so much easier if we could just get the source code. [edited by - Venerable Vampire on May 29, 2004 12:25:17 PM]

Share this post


Link to post
Share on other sites
I can''t honestly say that I have a lot of experience iwth a software engine, but typically when you have tearing like that, it means that you''re rendering a new position of the triangle in the middle of a moniter update. One way (and probably the simplist) to fix this is with vsync. Since stuff in this forum is supposed to be non-API specific, and the only way I know how to do it is through D3D device setup, I''m afraid I can''t give you any more details. That''s probably what you''ll want to do, though.

Share this post


Link to post
Share on other sites
The common way to interpolate a color accross a triangle for smooth blending is Gouraud shading, which only requires a few add operations for each pixel. Interpolate R,G,B linearly accross each edge of the triangle to get the color at the left and right edges, then for each scanline, interpolate linearly between the two. (That is, find the "slopes" dR/dx, dG/dx, ... and then just add onto the original R,G,B values as you move accross the line). Take a look at http://freespace.virgin.net/hugo.elias/graphics/x_main.htm or http://exaflop.org/.

Share this post


Link to post
Share on other sites
When rasterizing triangles of the type shown in your screenshot they are split into two triangles. That tear is just caused by a bug in the code of whoever wrote it. The programmer appears to be bounding both triangles to be ''less'' than the split line so there appears to be two scan lines missing from the final triangle.

Share this post


Link to post
Share on other sites
Well thanks everyone, I''ll look into the shading techniques.
And haro, I''m hurt... talking about me like I''m not here ("the programmer", sheesh)

--------------------------------------------------------
Life would be so much easier if we could just get the source code.

Share this post


Link to post
Share on other sites
quote:
Original post by Venerable Vampire
Well thanks everyone, I''ll look into the shading techniques.
And haro, I''m hurt... talking about me like I''m not here ("the programmer", sheesh)



Haha.. no offense. I had assumed that the first place you would have looked for the cause of the artifact would have been in your triangle splitting code. I further assumed that since you had not done this, it was likely that you did not write the splitting code yourself. Too many assumptions adds up to ass sometimes.

Share this post


Link to post
Share on other sites
Actually I haven''t implemented triangle splitting yet. The splitting is just really weird. I''ll get around to fixing it ... eventually

--------------------------------------------------------
Life would be so much easier if we could just get the source code.

Share this post


Link to post
Share on other sites
What??? What algorithm are you using to rasterize the triangles if you''re not splitting? This seems extremely unusual, especially considering that, that screenshot has the artifact exactly where you would split.

Share this post


Link to post
Share on other sites
I''m not sure what you mean by splitting. I''m just taking each projected edge, running it through the scan converter, and drawing the resulting scan lines. There is no need to make the 1 triangle anything other than 1 triangle. Wouldn''t splitting imply that only part of the triangle is valid, and therefore we need at least 2 triangles? Not sure if this makes sense but whatever...

--------------------------------------------------------
Life would be so much easier if we could just get the source code.

Share this post


Link to post
Share on other sites
Venerable Vampire> what he means by splitting is:

- get the top and bottom vertices...
the remaining vert then is the one between the two others.

- top vertex is called v0, middle vertex v1, and the bottom vertex v2.
- compute interpolation gradients for v0 -> v2 and v0 -> 1.
- draw the first half of the triangle (sub-triangle 1, from the top to the middle vertex), interpolating X and other stuff like color, texcoords, normals, whatever..

** here, you have a scanline missing **

- compute interpolation gradient for v1 -> v2, re-use gradient and current interpolation counter from v0 -> v2.
- draw the second half of the triangle (sub-triangle 2, from the middle to the bottom vertex)



and you can throw away part1 or part2 if v0.y == v1.y or v1.y == v2.y

haro> dunno.. he probably uses an edge list. and that missing scanline bug also appears in edge lists, it's just that he stops along the v0->v1 line too early, and probably only has one value filled in the edge list at that Y where the missing scanline is...


EDIT: btw, the edge list is more general than the triangle split where you draw everything in one go, it can handle tris, quads, n-gons, and with some modifications even non convex / hollowed polys, but the split method is usually faster.

[edited by - sBibi on May 30, 2004 7:16:48 PM]

Share this post


Link to post
Share on other sites