this post was submitted on 03 Apr 2010
115 points (75% like it)
172 up votes 57 down votes

programming

- frontpage+ frontpage152,132 readers
  • Before making a self-post in /r/programming, please check the programming.reddit FAQ to see if it's there first. In fact, if you're going to make a self-post, stop and think really hard if that's really what you want to do.
  • /r/programming is not a place to run polls or ask for help. For that try /r/learnprogramming or StackOverflow.

And if you're an all-star hacker (or even just beginning) why not join the discussion /r/redditdev and steal our reddit code.

created by speza community for 4 years

comments

mhd 16 points17 points 4 days ago[-]

Whenever I see shaded, untextured 3D objects, I stare at them, waiting for techno music to set in and for a morphing torus to appear. I'm getting old.

logged_in_for_this 1 point2 points 4 days ago[-]

Help me feel wiser! Explanation?

monocasa 9 points10 points 4 days ago[-]

He's refering to (1990s?) demo scene stuff. Writing a 3D renderer on a 12MHz 386 with only a VGA card (if you're lucky!) kind of stuff. It grew into stuff like the 4k demos of today.

shifty3 0 points1 point 4 days ago[-]

Or early techno music videos. To be fair, they had textures...

mhd 0 points1 point 4 days ago[-]

For a while it was either/or in demos. The biggest cliches which I saw a few times was either a silver torus to show phong-shading and a Hellraiser cube to show texture mapping. And the torus remained popular for a while even after that, this time for environment mapping.

Also: Wow-pow-pow (tishtishtish). Wow-pow-pow. (tishtishtish)

hobbified 3 points4 points 2 days ago[-]

I am not an atomic playboy.

Netcob 3 points4 points 4 days ago[-]

Great work! I'm looking forward to going through the code and learning a few things...

When I saw the ambient occlusion mode I was baffled at first... "what, no fuzzyness, faster than gouraud, on a SW renderer??". I know, I'm gullible...

jstddvwls 2 points3 points 4 days ago[-]

Some of the stolen Parthenon art (Elgin marbles)...

Heheheheh. Nice try! Come to London to see them like everyone else!

andy_63392 1 point2 points 4 days ago[-]

I think he meant 'legally removed, restored and preserved for posterity'.

jstddvwls 0 points1 point 4 days ago[-]

I think he meant 'someone paid someone in the Greek government a few shillings, and they gladly prostituted their countries treasures so they could have a few nights on the town.'

andy_63392 0 points1 point 4 days ago[-]

I think he meant the Ottoman government - Elgin was the British ambassador to the Ottoman empire. (TIL Greece didn't gain independence from the Ottomans until 1821).

jstddvwls 0 points1 point 4 days ago[-]

Yeah, that too.

Personally, I'd like to see them in-situ one day.

However, you cannot argue that the actions taken weren't for the benefit of society. I've been to where they would have been, and I've actually gone to see them.

They are pretty awesome.

They could be moved back to an amazing, world-class heritage site, in about 20 years when Greece pays off its debts, or defaults on them, or UK could pay, and get income from running and managing the site.

My ideal job would be managing collections, creating an amazing educational site for all of Europe's treasures, and allowing people to track when something will be in a local museum.

I may even apply for funding to do this. I'd love to make a special section to help kids learn about Europe's combined history back thousands of years.

I recently sold of the controlling interest in my company, so I am looking to do something like this now.

eternal512 2 points3 points 4 days ago[-]

fun stuff... having written both raster based and ray-traced renderers, I would highly recommend writing a ray-tracer, it is easy and fun.

I would recommend this book, if you're interested: Ray Tracing from the Ground Up, Kevin Suffern

friedrichsmit 2 points3 points 5 days ago[-]

Yep, C++ templates can do magic stuff. I recommend "Modern C++ design" by Alexandrescu - I am guessing you used such techniques to avoid code repetition in the renderers.

eternal512 3 points4 points 4 days ago[-]

great, another book to teach me how horrible I am at C++. (Thanks for the recommendation, it's in my amazon wish list now)

Netcob 0 points1 point 4 days ago[-]

I remember seeing the guy comment in the D language newsgroup all the time - I had no idea he was such a c++ guru...

But the book looks interesting!

you_do_realize 1 point2 points 4 days ago[-]

He used to be a C++ guy through and through but as I understand he jumped ship almost entirely to D.

fadec 1 point2 points 4 days ago[-]

Of course. The c++ book market is saturated and he needs to eat.

jurgshiler 0 points1 point 5 days ago[-]

Actually, you don't even have to use the black magic in that book - C++ templates can be used just as their name suggests, to avoid repetition.

ttsiodras [S] 4 points5 points 5 days ago[-]

Actually, I've read the book, and indeed found it to be a revelation. Still, I didn't use typelists or generic factories in this code (it is "hobby" code, after all :-). I just used C++ templates to adhere to the DRY mantra: different rendering modes had major parts used again and again - in a functional language I would have used lambdas all over the place, but in C++, all I had was templates, so...

dukey 0 points1 point 4 days ago[-]

it makes the code virtually unreadable.

filthy_atheist 3 points4 points 4 days ago[-]

Writing a rasterizer in software may be a good learning experience, but I highly disagree when you say this:

Then again, speed is a relative thing: the train object (available inside the source package, in the "3D-Objects" folder) was rendered at a meager 6fps on my Athlon XP, back in 2003. Around 2005, however, my Pentium4 desktop at work took this up to 11 fps. As of 2007, by way of Intel's Threading Building Blocks (or OpenMP) the code uses both cores of my Core2Duo to run at 23fps... And since it uses TBB/OpenMP, it will automatically make use of any additional cores... so give the CPUs a few more years... :-)

Update, November 2009: On a 4-core AMD Phenom at 3.2GHz, the train now spins at 80 frames per second... Guess I proved my point :-)

So in 6 years you get a 8x speedup using CPUs. In the same time GPUs had a performance speedup of 25x while adding a gazillion new features... not to mention that even from the beginning GPUs already had much better performance than any software solution -- unsurprisingly since that's what they are designed for. Your software solution doesn't even appear to support texturing, which is particularly inefficient to support in software.

In summary, I'm glad you enjoyed writing it, but insinuating that software rasterization is getting closer to the performance of GPUs is completely incorrect.

ssylvan 14 points15 points 4 days ago[-]

insinuating that software rasterization is getting closer to the performance of GPUs is completely incorrect.

Where did he insinuate that?

monocasa 7 points8 points 4 days ago[-]

Actually, I consider this stuff increasing in relevance as GPUs converge in capabilities with traditional processors. It won't be too terribly long it seems to me that OpenGL/DirectX drivers will just be this kind of stuff running on the GPU in software (and it already is for large chunks of the legacy fixed function pipeline). I'm glad that people are rediscovering software rasterizers so we'll be prepared for the day that it makes more sense performance wise to write this kind of thing targetting OpenCL/CUDA/SomethingElse rather than using a higher level API to do the heavy lifting.

filthy_atheist 1 point2 points 4 days ago[-]

You do have a point here. I should have worded my comment a bit better. Software rasterization on CPUs doesn't make a lot of sense from a performance standpoint. Taking advantage of the programmability of new GPUs certainly is going to become more and more common.

ttsiodras [S] 4 points5 points 4 days ago* [-]

Indeed, you have a point... To that end I have started experimenting with CUDA: I "upgraded" my Mandelbrot zoomer to a CUDA implementation (http://users.softlab.ece.ntua.gr/~ttsiod/mandelSSE.html), and got a tremendous speedup compared to my manually written SSE assembly.

I suppose the new challenge is figuring out how to "morph" an algorithm so that it can run fast in GPUs - a rasterizer for example is (currently) not a good candidate, since the absence of global cache mitigates the gains from CUDAs hundreds of threads... For now, at least, fragment shaders are far better at rasterizing than CUDA.

VVCephei 0 points1 point 4 days ago[-]

Your experiment makes me want to get a modern GPU and try some OpenCL. Are there many limitations? Is it difficult to port/morph an application for Cuda or OpenCL?

filthy_atheist 0 points1 point 4 days ago[-]

I agree with you here. CUDA/OpenCL is the way to go in the future for rendering, although traditional 3D APIs still will be useful for quite a few years.

VVCephei 0 points1 point 4 days ago[-]

ah. That is interesting. I didn't realize the performance gap has been steadily growing. I guess it is the 4GHz barrier that is causing the speedup difference: http://people.sc.fsu.edu/~burkardt/latex/ajou_2009_parallel/clockspeeds.png

Is there any significant difference in GPU programming support between ATI and nVidia cards?

filthy_atheist 5 points6 points 4 days ago[-]

I guess it is the 4GHz barrier that is causing the speedup difference

That is part of the reason but not the main one. Moore's law predicts that the number of transistors you can put cheaply in a processor roughly doubles every couple of years. Increasing the transistor count does not translate directly into performance gains for sequential processors (such as CPUs), but it does translate well into performance gains for parallel processors such as GPUs.

Is there any significant difference in GPU programming support between ATI and nVidia cards?

Nvidia still supports their legacy API called CUDA. Other than that, there's no real difference. Both ATI and NVidia support OpenCL and DirectX 11 compute shaders, which are more modern APIs for general GPU programming.

kragensitaker 1 point2 points 4 days ago[-]

That looks like a lot of fun!

q3k_org 1 point2 points 4 days ago[-]

That's fucking impressive man, good job!

codeguru3 1 point2 points 5 days ago[-]

Nice!

demoscene 1 point2 points 5 days ago[-]

Not that I don't appreciate this kind of efforts (I coded demos in my past) but why not OpenGL? Or CUDA?

ttsiodras [S] 6 points7 points 5 days ago[-]

Err... I did implement the code with OpenGL as well. Check the links in the page. CUDA is a nice thought, indeed :-)

smek2 -1 points0 points 4 days ago[-]

Can't upvote this enough.

jstddvwls -5 points-4 points 4 days ago[-]

I like the look of the ambient occlusion on Ajax. Did you look at the new ambient occlusion algorithm in the latest blender? They have an article about it.

Nice work! Sorry about the marbles, hey at least James Bond wants you to get them back!

Oh, I read your little probability exercise on the Joker lottery. I can't believe you thought the probability would change... anyway! You can download the joker results history from the OPAP website, and play around with it.

If you do play the Joker lottery, don't select as a joker one of the 5 other numbers you play - or better yet, don't pay the "stupidity tax" that is all lotteries.

What does the previous selections you have made have anything to do with the joker? The joker is still 1/20 and is 1/20 no matter how many <= 20 numbers you chose in the first 5. Choosing it differently doesn't increase your odds of winning, and doesn't constitute a stupid tax!!

1/20!! Learn to science!