Readings on vector class optimization

Now that Revision has passed, we feel tempted to grab the ax and happily chop into parts of our code base we wanted to change but couldn’t really since we had other priorities. One tempting part is the linear algebra one: vector, quaternion and matrix data structures. Lets say vector for a start. Not that it’s really necessary, but the transformations are the most time consuming parts after the rendering itself, and the problem itself is somewhat interesting.

After a little googling, I basically found three approaches to this problem:

Every here and there, people seem to think of SSE instructions as a silver bullet and propose various examples of code, snippets or full implementations. The idea being to use dedicated processor instructions to apply operations on four components at a time instead of one after another.

Quite on the opposite, Fabian Giesen argued some years ago that it was not such a good idea. A quick look at the recently publicly released Farbrausch codebase shows they indeed used purely conventional C++ code for it.

At last this quite dated article (with regards to hardware evolution) by Tomas Arce takes a completely orthogonal approach, consisting of using C++ templates to evaluate a full expression component after component, thus avoiding wasting time moving and copying things around.

I am curious to implement and compare them on nowadays hardware.


Update: this is 2016 and the topic was brought back recently when someone wrote the article How to write a math library in 2016.

The point of the article is that the old advice to not bother with SSE and stick with floats doesn’t apply anymore, and it goes on to show results and sample code. This sparked a few discussions on Twitter, with opinions voiced to put it mildly.

It seemed the consensus was still against the use of SSE for the following reasons:

  • Implementation is tedious.
  • For 3 dimensional vector, which is the most common case, there is a 25% waste.
  • For 4 dimensional vectors, like homogeneous coordinates and RGBA, it doesn’t work so well either since the fourth component is treated differently than the other ones.
  • Even if the implementation detail is hidden behind a nice interface, the alignment requirements will leak and become constraints to the rest of the code.
  • Compilers like clang are smart enough to generate SSE code from usual float operations.

Toward physically based rendering, screenshot after screenshot

Here are the screenshots I made for the talk I previously mentioned. They show how the rendering evolves through the choice of shading. The setup consist of a close yellowish punctual light on the up right, and a distant red-ish punctual light on the back left, as well as a dim blue ambient. The objects only differ by the specular exponent, which jumps by a times two factor from one object to the next one, left to right.

One light, Lambert diffuse only.

Two lights, Lambert diffuse only, with variance shadow map.

Two lights, Lambert diffuse only, with albedo.

Two lights, diffuse and Phong specular. Notice the color on the left.

One light, Phong specular only. Notice the discontinuity on the left.

Two lights, diffuse and Blinn-Phong specular.

One light, Blinn-Phong specular only. Notice the absence of discontinuity.

Two lights, diffuse and normalized Phong specular. Notice the highlight intensity.

Two lights, diffuse and normalized Blinn-Phong specular.

Two lights, diffuse and normalized Blinn-Phong specular, Fresnel term with Schlick

Two lights, Heidrich-Seidel anisotropic specular.

Next steps: getting used to the Fresnel version, experimenting with the exponent as a texture lookup, and normalizing the Heidrich-Seibel specular.

Back from Revision

This article is a crosspost from Ctrl-Alt-Test.fr.

I don’t know if this is going to become some sort of tradition for us, but as a matter of fact, we attended all Easter parties since the creation of our group. This year was no exception, and we had a really great time at Revision.

Revision is the kind of party that is just big enough so even though at some point you think “Ok, I’ve met pretty much every one I wanted”, when you get home you realize how many people you wanted to meet and did not. It’s also the kind of party that is so massively awesome that when you get back to your normal life, you experience some sort of post-party depression, on top of the exhaustion, and you have to get prepared for when it strikes.

Sidrip Alliance performing at Revision

So we’ve been there, and this year we presented the result of the last months of work in the PC 64k competition. The discussion of the concept started back in May 2011, and we seriously started working on it maybe around August.

While Revision was approaching, rumors were getting stronger about who would enter the competition, how serious they were about it, and how likely they’d finish in time. It became very clear that the competition was going to be very interesting, but even though, it completely outran expectations. It even got mentioned on Slashdot!

Our intro, F – Felix’s workshop, ended up at the 2nd place, after Approximate‘s gorgeous hypno-strawberries, Gaia Machina. The feedback has been very cheerful, during the competition as well as thereafter. Also, as if it was not enough, to our surprise, our previous intro, D – Four, has been nominated for two Scene.org Awards: Most Original Concept and Public Choice. Do I need to state we’re pretty happy with so many good news? :) Thank you all!

Now a week has passed already, we’re back at our daily lives, slowly recovering, and already thinking of what we’re going to do next. :) Until then, here is a capture of our intro:

Introduction to light shading for real-time rendering

I am finally back in Tokyo after two intense weeks in Europe, during which I did things as various as being a perfect tourist in four capitals (stolen bag experience included) or attending the world biggest demoparty, getting nominated with the rest of my group for some awards, ranking 2nd in a competition and getting slashdotted for that. :)

As previously advertised, I presented at Revision a talk on light shading. A video was recorded for the streaming and has been made available online pretty much immediately, thanks to the work of the Revision team:

Unfortunately, the last minutes are missing. I was basically comparing the Fresnel version with the manually tweaked version, and explaining that while the former might not look perfect yet, it was an out of the box result, while the latter required me to introduce some fudge factor I had to tweak. Regarding references, I couldn’t list them all so I just mentioned the most significant ones (the first part of this talk is strongly inspired by Naty Hoffmann’s course introduction) and referred to here for the rest. At last I mentioned an evaluation sheet for whoever cared to give some feedback.

Performance wise, when seeing the video I feel embarrassed. The flow is far from what I was aiming, some explanations are not crystal clear as I wanted them to be, and you can notice I was confused a couple of times by the surrounding noise (hey, did I mention it’s a party?). But on the other hand various people told me it was a good seminar so even though there is much room for improvement, it’s not that bad of a start I guess.

Anyway, you can download a quick export of the party version of the slides. When I have some time I will try to get a better looking export (without text and images cropped out), and fix a couple of slides.