Live data from Hacker News

Simple software rasterizer in a single C++11 header file

github.com

11–20 of 23 posts

Re: Simple software rasterizer in a single C++11 header file

#12
post #8
post #5

Earlier quoted context omitted.

Header libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.

The reason Boost is headers only is you have to be a header to be generic. Implementations outside of headers have to friend / otherwise be not truly generic.

Yes, good point. You're right about that.

Re: Simple software rasterizer in a single C++11 header file

#13
post #8
post #5

Earlier quoted context omitted.

Header libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.

The reason Boost is headers only is you have to be a header to be generic. Implementations outside of headers have to friend / otherwise be not truly generic.

[deleted]

Re: Simple software rasterizer in a single C++11 header file

#14
post #9
post #3

Earlier quoted context omitted.

This loops over the triangles and converts them to screen pixels. A ray tracer loops over screen pixels and checks if there are any triangles that overlap it.

More or less this. To expand a bit - rasterization converts lines or polygons to pixels via hidden line removal techniques ( http://en.wikipedia.org/wiki/Hidden_line_removal ) and/or hidden surface techniques ( http://en.wikipedia.org/wiki/Hidden_surface_determination ) while ray tracing can mean a lot of different things, where most common and basic form is Whitted's ray tracing where final image is a grid of pixels…

Thanks for the explanation. How are multiple hops in light path handled without having the computational complexity go insane?

Re: Simple software rasterizer in a single C++11 header file

#15
post #14
post #9

Earlier quoted context omitted.

More or less this. To expand a bit - rasterization converts lines or polygons to pixels via hidden line removal techniques ( http://en.wikipedia.org/wiki/Hidden_line_removal ) and/or hidden surface techniques ( http://en.wikipedia.org/wiki/Hidden_surface_determination ) while ray tracing can mean a lot of different things, where most common and basic form is Whitted's ray tracing where final image is a grid of pixels…

Thanks for the explanation. How are multiple hops in light path handled without having the computational complexity go insane?

They aren't.....

Some popular shortcuts include:

- Cut at n hops (with n=4 or n=8 popular choices), defaulting to "ambient" light after that

- Give each material an "ambient" color, so that you don't actually need to trace every pixel back into every light source (just into e.g. spotlights)

- Solve a radiosity equation for the surface colors, and trace rays for textures/reflections.

Complete ray tracing is, indeed, insane - in fact, to get high quality pictures and avoid aliasing, most ray tracers send multiple rays through every picture and average the result.

Re: Simple software rasterizer in a single C++11 header file

#16
I recently unearthed the code I wrote at school in 1996 which implemented a 3D Gouraud-shaded renderer that managed ~1000 triangles/sec on a 33MHz 486. It's a great learning experience doing this from scratch.

Mine did Bresenham's algorithm for pixel fill rather than the winding approach used here.

Re: Simple software rasterizer in a single C++11 header file

#17
post #4

I'm not a C++11 developer, I've done a little C++ in the past. What is the pride in putting all the code in the header file? Shouldn't the declarations be there, and the definitions be pulled out into a .cpp file? Is it somehow smaller, faster, more convenient to have it all in a header file?

It's unavoidable if you use templates in the interface. It tends to make builds disastrously slow though.

Re: Simple software rasterizer in a single C++11 header file

#18
post #7

I TA'd a rendering course once and wound up assigning a homework where the students implemented their own software rasterizers in CUDA. Before that homework, a lot of students didn't really understand what a rasterizer did. Afterwards, everyone got it.

Do you have links to any resources the students found handy? I'm not very familiar with anything to do with the graphics stack other than familiarity with some of the words.

Re: Simple software rasterizer in a single C++11 header file

#19
post #18
post #7

I TA'd a rendering course once and wound up assigning a homework where the students implemented their own software rasterizers in CUDA. Before that homework, a lot of students didn't really understand what a rasterizer did. Afterwards, everyone got it.

Do you have links to any resources the students found handy? I'm not very familiar with anything to do with the graphics stack other than familiarity with some of the words.

I'm not the author of the original comment, but when I was in high school I found the Graphics Programming Black Book to be useful for understanding graphics primitives and how they can be implemented in software. It's available for free online: http://www.gamedev.net/page/resources/_/technical/graphics-p...

Maybe start with chapter 38: http://downloads.gamedev.net/pdf/gpbb/gpbb38.pdf

Re: Simple software rasterizer in a single C++11 header file

#20
post #8
post #5

Earlier quoted context omitted.

Header libraries are easier to add to your project because there are no build scripts to figure out or cross-compiling to do or whatever. A lot of Boost is header-only, for example. GLM (OpenGL Mathematics), too, is header-only. OTOH if you end up modifying a header that's included in a whole bunch of places, woe unto you.

The reason Boost is headers only is you have to be a header to be generic. Implementations outside of headers have to friend / otherwise be not truly generic.

Assuming you mean friend in the standard cpp way, that's not exactly correct.

http://stackoverflow.com/questions/495021/why-can-templates-...

Post reply on HN