Followup to Atmospheric Scattering—Part 1

This post is the first in a series to fol­low-​up on my 2012 GPU Pro 3 arti­cle about atmos­pher­ic scat­ter­ing [11]. What I showed there was a full sin­gle-​scat­ter­ing solu­tion for a plan­e­tary atmos­phere run­ning in a pix­el shad­er, dynam­ic and in real time, with­out pre-​com­pu­ta­tion or sim­pli­fy­ing assump­tions. The key to this achieve­ment was a nov­el and effi­cient way to eval­u­ate the Chap­man func­tion [2], hence the title. In the time since then I have improved on the algo­rithm and extend­ed it to include aspects of mul­ti­ple scat­ter­ing. The lat­ter caus­es hor­i­zon­tal dif­fu­sion (twi­light sit­u­a­tions) and ver­ti­cal dif­fu­sion (deep atmos­pheres), and nei­ther can be ignored for a gen­er­al atmos­phere ren­der­er in a space game, for exam­ple.

I have writ­ten a Shader­toy that reflects the cur­rent state of affairs. It’s a mini flight sim­u­la­tor that also fea­tures clouds, and oth­er ren­der­ing good­ies. A WebGL2 capa­ble brows­er is need­ed to run it. Under Win­dows, the ANGLE/Direct3D trans­la­tor may take a long time to com­pile it (up to a minute is noth­ing unusu­al, but it runs fast after­wards). When suc­cess­ful­ly com­piled it should look like this:
Con­tin­ue read­ing

Followup: Normal Mapping Without Precomputed Tangents

This post is a fol­low-up to my 2006 ShaderX5 arti­cle [4] about nor­mal map­ping with­out a pre-com­put­ed tan­gent basis. In the time since then I have refined this tech­nique with lessons learned in real life. For those unfa­mil­iar with the top­ic, the moti­va­tion was to con­struct the tan­gent frame on the fly in the pix­el shad­er, which iron­i­cal­ly is the exact oppo­site of the moti­va­tion from [2]:

Since it is not 1997 any­more, doing the tan­gent space on-the-fly has some poten­tial ben­e­fits, such as reduced com­plex­i­ty of asset tools, per-ver­tex band­width and stor­age, attribute inter­po­la­tors, trans­form work for skinned mesh­es and last but not least, the pos­si­bil­i­ty to apply nor­mal maps to any pro­ce­du­ral­ly gen­er­at­ed tex­ture coor­di­nates or non-lin­ear defor­ma­tions. Con­tin­ue read­ing

Branchless Matrix to Quaternion Conversion

(EDIT: This arti­cle is a more in-depth write­up of an algo­rithm that I devel­oped around 2005, and first post­ed to Mar­tin Baker’s Euclid­ean Space web­site. That time was the height of the Intel Net­Burst archi­tec­ture, which was noto­ri­ous for its deep pipeline and high branch mis­pre­dic­tion penal­ty. Hence the moti­va­tion to devel­op a branch-free matrix to quater­nion con­ver­sion rou­tine. What fol­lows is the com­plete deriva­tion and analy­sis of this idea.)

The orig­i­nal rou­tine to con­vert a matrix to a quater­nion was giv­en by Ken Shoe­make [1] and is very branchy, as is tests for 4 dif­fer­ent cas­es. There is a way to elim­i­nate these branch­es and arrive at a com­plete­ly branch-free code and high­ly par­al­leliz­able code. The trade off is the intro­duc­tion of 3 addi­tion­al square roots. Jump the analy­sis sec­tion and the end of this arti­cle, or con­tin­ue fist with the math bits.

Con­tin­ue read­ing

Cloud rendering and the relativity of whiteness

Here are some philo­soph­i­cal and ren­der­ing-relat­ed ques­tions that I took home from the last vaca­tion. What’s the col­or of clouds? The stan­dard answer would be, white.
What’s the col­or of snow? Again, white. Ok, then look at the fol­low­ing pic­ture, where the snow seems con­sid­er­ably whiter. This is the case in almost all pho­tos that I took.

There is an image on Wikipedia from the same gen­er­al area on which the bright­ness dif­fer­ence between clouds vs snow is even more pro­nounced. If you look at the direct­ly lit parts of the snow and con­sid­er it white (#ffffff), then the direct­ly lit parts of the clouds are at most 50% grey (#bbbbbb). Is that an evi­dence of air pol­lu­tion? Unlike­ly! (At least not in Tyrol).

Con­tin­ue read­ing