FAQ  •  Register  •  Login

Software Rendering Face (of a Cube)

Moderator: Inside3D Admins

<<

Baker

User avatar

Posts: 3182

Joined: Tue Mar 14, 2006 5:15 am

Post Sun Feb 12, 2012 9:44 pm

Software Rendering Face (of a Cube)

In vague terms, is anyone able to explain in a rough manner how, say, WinQuake renders a totally unclipped surface?

I've looked through the source of WinQuake and tried to follow the code and it is rather unclear to me at this point.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
<<

mankrip

User avatar

Posts: 500

Joined: Fri Jul 04, 2008 3:02 am

Post Sun Feb 12, 2012 11:40 pm

Re: Software Rendering Face (of a Cube)

I never understood it fully, but from what I know the BSP renderer generates a list of spans based on the surface's edges, UV maps the vertexes of the surface's edges to the surface cache, and draws the spans, using perspective correction.

There's always some clipping, because the surfaces aren't unlimited. Surfaces are always clipped on their edges, and the engine also checks their edges against other surface's edges to see if they needed to be clipped even more, eliminating any overdraw.

The MDL renderer works a bit differently. It only draws triangles, so all surfaces will always have three edges, making it unable to compare those edges against other triangle's edges, which is why it can't avoid overdraw and must use a Z buffer for depth testing. It also calculates gouraud shading (which takes the neighboring triangles into account), reads the texture unmodified from memory instead of using a lightmapped surface cache, and draws it without perspective correction.
Thinking with slipgates.
=-=-=-=-=-=-=-=-=-=
Makaqu engine blog / website.
<<

mh

User avatar

Posts: 2172

Joined: Sat Jan 12, 2008 1:38 am

Post Mon Feb 13, 2012 12:25 am

Re: Software Rendering Face (of a Cube)

Maybe some of the stuff that Mike Abrash wrote at the time would be helpful? http://www.bluesnews.com/abrash/contents.shtml
Like the fifth day of playing 24-hour Scrabble when you don't want to use any letters because each one means a world to you because you're so deranged.
<<

leileilol

User avatar

Posts: 2399

Joined: Fri Oct 15, 2004 3:23 am

Post Mon Feb 13, 2012 12:26 am

Re: Software Rendering Face (of a Cube)

mankrip wrote:The MDL renderer works a bit differently. It only draws triangles,

You are forgetting the mode where it's a point cloud pretty much (the distant rendering of models).
<<

mankrip

User avatar

Posts: 500

Joined: Fri Jul 04, 2008 3:02 am

Post Mon Feb 13, 2012 1:10 am

Re: Software Rendering Face (of a Cube)

I remember listening to Michael Abrash talking about it in a video, but I've never noticed it in the code. It must be in some of those parts of the code I don't understand yet.

There's also triangle subdivision for the MDLs, but I haven't mentioned it because afaik it's only used for clipping triangles against the edges of the screen.
Thinking with slipgates.
=-=-=-=-=-=-=-=-=-=
Makaqu engine blog / website.
<<

Baker

User avatar

Posts: 3182

Joined: Tue Mar 14, 2006 5:15 am

Post Mon Feb 13, 2012 2:01 am

Re: Software Rendering Face (of a Cube)

mh wrote:Maybe some of the stuff that Mike Abrash wrote at the time would be helpful? http://www.bluesnews.com/abrash/contents.shtml


I'll have to read that. I was looking for something like that, but could not find.

mankrip wrote:I never understood it fully, but from what I know the BSP renderer generates a list of spans based on the surface's edges, UV maps the vertexes of the surface's edges to the surface cache, and draws the spans, using perspective correction.

There's always some clipping, because the surfaces aren't unlimited. Surfaces are always clipped on their edges, and the engine also checks their edges against other surface's edges to see if they needed to be clipped even more, eliminating any overdraw.

The MDL renderer works a bit differently. It only draws triangles, so all surfaces will always have three edges, making it unable to compare those edges against other triangle's edges, which is why it can't avoid overdraw and must use a Z buffer for depth testing. It also calculates gouraud shading (which takes the neighboring triangles into account), reads the texture unmodified from memory instead of using a lightmapped surface cache, and draws it without perspective correction.


Well, I see this is a bit more complex than I thought. :D

Maybe I should start with taking a look a glProject (like some open source one) to see where a pixel in XYZ space is in XY space and then read the Abrash stuff. I saw that edges stuff in the code and started getting confused. And frankly at this point, I'm not sure what a span is. But I do want to know.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
<<

andrewj

Posts: 132

Joined: Mon Aug 30, 2010 3:29 pm

Location: Tasmania

Post Mon Feb 13, 2012 4:21 am

Re: Software Rendering Face (of a Cube)

A span is a horizontal row of pixels.

Edges are the edges of faces, and the edges get projected on to the screen, and if you ignore clipping and overlapping for the moment then rendering the polygon is just a matter of iterating the Y coordinate from the highest Y to the lowest, and at each Y (screen row) draw a span from the current left edge to the current right edge.

Clipping vertically is just a matter of limiting the Y range to the screen.

Clipping horizontally is just limiting the current span to the screen (skipping the span if it is completely off the screen).

The edge list is a way of sorting the polygons into drawing order (closest ones overriding further ones), using the projected edges of the polygons. I couldn't say exactly how it works though.
<<

Spike

Posts: 2070

Joined: Fri Nov 05, 2004 3:12 am

Location: UK

Post Mon Feb 13, 2012 6:43 am

Re: Software Rendering Face (of a Cube)

gluProject - projects a 3d world coord into a 4d screenspace coord...
yeah, that 2d screen is best represented with 4 dimensions.

to go from model space to screen space, you first need to transform by the modelview matrix (aka: world and view matricies) to put it in world space. this is the matrix(matricies) that specify the position of the view and the model. d3d keeps them separate while gl combines them.
after that, you need to transform by the projection matrix. This transforms the worldspace coord into viewspace. This coord system is your basic 4d coord system as specified by the output of a vertex program. Its coords are actually 'xw yw zw w', so multiply the first two elements by the viewport size, divide the first 3 by w and you get your xyz pixel/depth coords (homogeneous coordinates - allows the various matricies to all be multiplied together which keeps things fast and with proper perspective).

Once you have your 3 points, you can interpolate between them. find which is the highest vertex, and which is the lowest (y coord), find which side the middle coord is on, and interpolate down the triangle to the middle and then to the bottom vertex. for each y coord, find the interpolated position of the top-bottom edge and iterate over every single pixel across the horizontal span until you find the other side.

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.
Icons provided by Aha Soft