Sub-surface scattering with CDRF

In this paper, Kubo, Dobashi and Morishima present a compelling case for using a curvature dependent reflectance function (CRDF) to simulate sub-surface scattering. The basic idea is that smaller objects with higher curvature exhibit more noticeable sub-surface scattering than flatter ones. Using photon mapping with spheres, the authors found a reasonable relationship between the curvature of the sphere (the inverse of the sphere’s radius) and the radiance across the sphere. With the only examples in the paper shown being fairly close to spherical, I wanted to see if I could use their technique, or a variant of it, to get a cheap sub-surface scattering effect on a more complicated mesh. Like, say, the dragon from Stanford’s 3d scanning repository.

The mathematics
First, the authors of the paper attempt to fit their data using the following CDRF:

f_r(theta, kappa)=(L_i*g)(theta)

Where L_i is the incident light energy and g(theta, sigma) is a gaussian:

g(theta, sigma)=frac{1}{sqrt{2pisigma(kappa)^2}}expfrac{-theta^2}{2sigma(kappa)^2}

As can be seen from figure 2(c) in the paper, this is not a particularly good fit though it does match the data qualitatively with a Lambert type shape at low curvature which spreads at higher curvatures.

However, a better quantitative fit is given by (thanks to Cedrick Collomb for help with this):
f_r(theta,kappa)=frac{1+kappa}{4} frac{cosleft(minleft(frac{(5 + kappa)theta}{4}, piright)right)+1}{1+left(frac{lnleft(1+1.7kapparight)theta}{1.45}right)^{10}} + 0.075(1-kappa)

Once you have this, it’s time to move on to measuring the curvature of your mesh.

Mesh curvature
There are a few different techniques out there for determining the local curvature of a mesh, but the two main techniques involve either finding an analytical formula or patch that fits the mesh around the vertex you are interested in, or determining the curvature directly from the vertex and normal information. As this was just a prototype, I went with the more performance friendly, and less work-intensive, option of determining the curvature directly from the mesh.

My first attempt was inspired by this paper where the area of each ring of faces around a vertex is compared to the area of those same faces projected onto a unit sphere. This gives a measure of the Gaussian curvature of a mesh which is an intrinsic property of any surface. When applied to a series of test meshes, the results were less than ideal. The sign of the curvature appears correct, but the magnitude depends heavily on the size of the faces, as you would imagine from the definition.

I did attempt to extend the neighborhood used to calculate the Gaussian curvature to two rings, but this had two negative effects: The local curvature was smoothed out too much in some places, and other places the technique became invalid as it relies on the sign of curvature not changing within a neighborhood.

These limitations led me to a definition of curvature that is not an intrinsic property of a surface, but depends on the space a surface is embedded in. As I can control the ambient space within my test program and ensure it remains Euclidean (side note – has anyone considered making a game set against a non-Euclidean space?) this measure is still valid for my requirements.

This technique, outlined in this paper again compares areas of faces within the neighborhood of a vertex, but as the area of the face appears in both the numerator and the denominator of the ratio, the magnitudes of curvature are more well-behaved both locally and across the mesh. My results from this technique were far more useful.

Putting it all together
So now you have an intimidating formula linking local curvature and incident light angle to outgoing radiance. What happens when you put it together?

First, here’s a baseline. The dragon with a simple Lambert BRDF:

Now replacing this with the CDRF from the original paper:

The diffuse lighting is clearly wrapping around the model more, as expected, however there are some issues. Note in particular the spine of the dragon which, being thinner, should show more transmission. However, as it has flat curvature when compared to the thicker body of the dragon, it transmits less.

To compare, here’s an image of the same mesh, with the same data, but using a more traditional depth-based technique for sub-surface scattering:

Which clearly shows the transmission effect, but where we might expect the scattering effect to be pronounced, around the details in the face, for example, we lose all detail.

While it is true that transmitted light will focus into areas of high curvature, this is an additional effect on top of how far the light has to travel within the model. So perhaps by combining these effects and using the CDRF to add a curvature dependent term to the depth-based sub-surface scattering model, we might get something better than either:

Which has all the benefits of a depth-based technique but with the added benefit of concentrating the transmission where the curvature has a high positive magnitude and darkening the transmission where the curvature is negative.

However, we can combine the curvature with the depth-based sub-surface scattering effect in other ways. We can use the curvature of the model directly to lighten and darken the transmitted light. This should add detail back in without the expense of the CDRF calculations and looks like this:

This, in combination with a Blinn-Phong BRDF and a Fresnel reflectance term, gives us something that starts to approximate jade:

While the original application of the local curvature of a mesh does not provide a good model of sub-surface scattering for more general cases, it can certainly be applied to existing techniques to add subtlety to the transmission and scattering of light through a model.

The Big Blue C

I was fine when he said it was cancer. I was still fine when we discussed different types of cancer and the prognosis for each. I was even fine when we discussed the relative merits of compassionate euthanasia. What got me was this line in the printed client instructions:

Indulge him in whatever he wants. Do not hesitate to take him to the park in the sunshine.

Outside Lands

A really quick post between bouts of caring for Eddie with short reviews of bands I saw at Outside Lands last weekend.

Gogol Bordello
Everything I’d hoped that a Gypsy Punk band would be. Thick accents, an accordion, charisma, and tonnes of energy.

My Morning Jacket
I just kept wishing it was Radiohead up there as they do the same thing only much better. Clearly talented, but painfully insincere.

A near perfect incarnation of a late 60s rock band. The covers of Teenage Wasteland and Riders on the Storm were fun, and I’m sure the drummer is a young Keith Moon.

The Devil Makes Three
Not quite Bluegrass and not quite Skiffle. A three-piece of banjo, acoustic guitar and stand-up bass who play the most infectious country grooves with smart lyrics. A perfect start to Sunday morning.

Edward Sharpe & The Magnetic Zeros
Having read the story of this band, and seeing them get set up, I was fascinated to hear what they sounded like. The stage was full of instruments and I counted at least eight musicians. The sound that many people create is incredible to hear live, and I just wish the music had been compelling enough for me to stay past the first song.

Slightly Stoopid
Drifting between reggae, punk, surf rock and hip-hop, Slightly Stoopid were another great bit of scheduling for Sunday afternoon in the sun. Laid back grooves and a fun time for all.

Social Distortion
Why, oh why, have I not been seeing these guys live every time they play anywhere near me. The quintessential punk rock played with the attitude and swagger that only comes from knowing how good you are and loving every second you’re on stage. Awesome to experience, and one of the nicest mosh pits I’ve every had the pleasure to fight my way through to get to the front.

What a guy! Makes you cry. Und I did.

Eddie is ill. This should not be a surprise; he is, after all, fifteen years old which is a fair stretch for a dog. What is a surprise is the suddenness with which his illness has affected him.

We always knew about the  swollen liver, the heart murmour, the chronic ear infection, and the hardening retinas, but when he stopped eating and started being visibly ill every day, it was clear something else had gone wrong. After a spate of blood tests, it seems he has liver/gall bladder disease, pancreatitis, and cholangiohepatitis. If that sounds scary, well it is.

Continue reading

Droid Love part 2

Part 1 is here.

It took a little more than an hour to end up with this. It was so much fun to get all the details right on R2, but I’m not sure I like it as much now that it’s complete. I think when I ink it, I will simplify him a bit and try to get back to a more cartoony feel.

Speaking of inking, I haven’t inked anything before, and I’m not sure if I should go with pen and paper or switch to digital. I guess I’ll try both and see what works best for me. If anyone has any hints or tips for inking, I’d love to read them.

Droid Love part 1

Katie Cook, the expert in all things in the intersection of the sets Star Wars and Adorable, asked via Twitter for ideas for one of her mini paintings. Side note, I picked up one of her mini paintings of Yoda at SDCC and loooove it; if you get the chance to get one, do so. And the “Fuck You Box” book. Anyway, I suggested R2-D2 falling in love with a flip-top garbage can, and immediately realised that I wanted to draw it myself.¬†Now, to put this into perspective, I haven’t drawn anything for something like twenty years so this was a giant step into the unknown for me.

First, I needed to plan what I was going to draw:

Ground-breaking stuff, right? Watch out, Caravaggio, I’m coming for your crown.

I needed to get my idea down on paper, and this was the quickest, dirtiest sketch I could do. Actually, I quite like it and was tempted to leave it at this stage. But I didn’t, and I’ll post the next step another time.