Jump to content
  • Advertisement


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


Simple Depth Software Render

This topic is 5931 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

ok I need a simple software render that renders depth values into an array, all I need is the depth no depth testing just record them, ok so I went about thinking about it and Well I thought I just need to have a world matrix (for rotatoins and stuff) and then a projective matrix and I will only draw triangles to it. Ok I can do that So Then I have 3 points on the screen and the depth for each one, well there is only one problem how do I go about filling in the triangle or lines? Im rather stumped, I thought of finding points at certain intervals on the triangle but That may or may not turn out correctly it might miss a pixel or it may have way to many points per pixel. Which would go slower then I would like. How is this done? A tutorial, expenation, or demonstration would be most appretiated. thank you. NOTE: Themini software render that I am trying to write is not to be used alone is mainly my way of accessing a limited amount of data about an object when its displayed, and will be used to aid me in a particular effect im trying to do in opengl. if anyone wondered why anyone would make a depth only renderer.

Share this post

Link to post
Share on other sites
You need to lookup ''scanline rasterizer''. The basic idea is to trace edges of the triangle down (or up) the screen, determining the intersections with each line of pixels. Then you just fill in between the endpoints of each line (it being a triangle or any convex polygon, each scanline will only be intersected twice).

It might be very hard if you are trying to get an exact match of an OpenGL implementation because the exact rasterization process isn''t specified so each implementation could give slightly different results.

(A quick Google turned up http://www.cs.unc.edu/~mcmillan/comp136/Lecture9/triangles.html, might give you a start)

Share this post

Link to post
Share on other sites
Thanks that help a lot, but one thing still excapes my understanding how could I interpolate the depth values between all 3 points could some one provide a some information about this topic?


Share this post

Link to post
Share on other sites
At the lowest level you want to linearly interpolate the values.

For each edge you trace vertically, simply interpolate between the two values at the edges endpoints and store those in the scanline structure. Then interpolate between the stored values in the scanline structure, a little example might help:

// This structure represents a single scanline. Each
// member is going to be linearly interpolated. The [2] arrays
// represent each end of the span. The routines set the
// spans so that x[0] < x[1]

struct Span
int x[2];
float red[2];
float green[2];
float blue[2];
float value[2];

Span scanlines[SCREEN_HEIGHT];

// 1. trace each edge of the triangle, store the

// 2. for each scanline, interpolate between the [0] and [1] values of each member. (just shown for the red member)

float spanWidth = scanline.x[1] - scanline[i].x[0];
float dred = (scanline[i].red[1] - scanline[i].red[0])/spanWidth;

float red = scanline[i].red[0];

for(int x=scanline[i].x[0]; x < scanline[i].x[1]; x++)
red += dred;


Just use goraud shading forumulas except with the depth values and it will correctly interpolate across your triangle.

That's almost right, however straight depth values do not linearly interpolate in screen space. You actually need to interpolate 1.0/z and then convert that value at each pixel back into the z value. Of course thats only if you care about accuracy, just interpolating z will work in most cases for a simple depth buffer, but won't be accurate.

EDIT: gah

[edited by - JuNC on September 14, 2002 6:53:42 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!