we are amazing.

look, i just asked google to find information on “peeing in fresh fallen snow”. i know, bear with me.

i was speaking about that a couple of posts ago, so that’s why i came up with such a sentence to look for. thing is, i hoped it would be a rare enough of a concept as to give google search a hard time giving me back any sensible information. i have no clue about the internal mechanics of the search engine, but i was naively expecting that this being an infrequent query, the answer would not be cached anywhere and that a long search process would be run, possibly giving me some random links not related to the semantics of my query at all but to pages speaking of pee alone, or snow. so yeah, i just asked google to find information on “peeing in fresh fallen snow”; and in a blink, the search engine gave me a link to a page at the urban dictionary website which has the following definition:

Urinart: Drawing a picture in freshly-fallen snow using urine

and this, my friends, blows my mind in so, so many ways.

first of all, the fact that the word urinarting has already been created is pretty awesome. secondly, that somebody invested the time to put this information online is also pretty amazing. third, that google was able to handle my weird query by crossing information with all sort of unstructured sources of information out there and that it found this definition is seriously astonishing. fourth, that it did it in no more than 0.26 seconds is ridiculously impressive. sixth, that humans have reached this state of mastery in information manipulation and management, that we do have tools to store, classify and index information in such a cheap manner that not even the most daring science fiction author would possibly have dreamed of just 20 years ago, this is freaking mind blowing.

i don’t know. when i was a kid before internet became popular at around ’95, i would often have to cycle to the public library to physically scan shelves in order to search for an outdated version of the information i was looking for. my great-grandmother, who was born in a tiny village in the mountains by the same time the light bulb was created, knew nothing about the world but what a guy in a black dress would tell her every Sunday morning in form of canticles and rituals.

so look at it with a bit of perspective. we are a ridiculously plastic species.

you know those crazy high tech cameras able to record thousands of frames per second, that cost $250,000 ?

i wonder if they are any useful beyond recording random objects being blown up in slow motion like, say, water balloons in peoples faces. seriously.

it got so boooooooring

being a man has some advantages, and some disadvantages.

among the former, there is that of, when in the mountains during winter, being able to write your name by peeing in a bunch of new fallen snow (american’s do have it easier since they have it really short. their name, i mean – just one syllable most of the times).

the joy of this realization is immense

in every early morning bart car heading to the city there’s a few young woman with a mirror in one hand, an eyeliner in the other. time is precious, and this is a great way to buy some extra 15 minutes of sleep back home. they change the eyeliner for a mascara applier and proceed with the eyelashes, there in the middle of a crowd with whom they have nothing to do. only the people that they can reach through the social network in their smart phone’s really matters to them. like the work colleagues they are about to meet in the office or the new clients they will talk to today. it’s time to go for some lipstick. some astonishingly precise moves, and they’re ready to go.

in every late night bart car heading to the city there’s a few young woman with a mirror in one hand, an eyeliner in the other. time is precious, and this is a great way to buy some extra 15 minutes of rest back home. they change the eyeliner for a mascara applier and proceed with the eyelashes, there in the middle of a crowd with whom they have nothing to do. only the people that they can reach through the social network in their smart phone’s really matters to them. like the best friends they are about to meet in the pub or the new strangers they will talk to today. it’s time to go for some lipstick. some astonishingly precise moves, and they’re ready to go.

today i saw this image below in a blog dedicated to science, and i got immediately sad, cause it reminds me that even people doing science themselves don’t always really get it – they seem to not fully understand what science is about.

the statement above is basically saying that a perfect world doesn’t have discontinuities – that things change slowly without abrupt alterations, that things that are a lot don’t become a little suddenly without ramping down gradually, that if things are here now and they will be there later it’s only because they are going to be “in between” before. basically the image is claiming that in a perfect world things are not broken but smooth.

that’s not true though, reality, the world, the things around us, everything is mostly broken and discontinuous. whoever wrote that blog post above noted it by implying that this world is indeed not perfect or ideal.

see, this is my problem – there’s nothing wrong with the world. the world it’s ideal, it’s not the imperfect thing Plato thought it was (with terrible consequences for the western culture as we know). the world is doing just fine, believe me. let me repeat it: the world is doing just fine. humans aren’t.

indeed, it is our mathematics that are not ideal. or at least, they are not up to the task of describing efficiently everything around us, discontinuities included. but surely enough, the universe is full of discontinuities at all scales (it can really get pretty fractallie sometimes), it’s not made of boring spheres and planes as Galileo wrongly claimed, nor it’s made out of derivatives, ordinary differential equation and any other human abstractions. an ideal world does not follow lim {x->c} f(x) = f(c). and this, is not a problem. it’s a gift. on the contrary, in an ideal world humans enjoy less primitive mathematics than our current, some mathematics that allow us to describe and model and manipulate discontinuities and all other beautiful features of all the things that we see around us.

basically, we humans have a problem, the universe doesn’t. thinking that an ideal world is one where the universe follows our thinking process (and not the other way around) is simply a too much of a human egocentric position. which ironically the scientific community has always proudly claimed to refrain from. thing is that science too fails to do so sometimes, for humans have this tendency of making the universe orbitate around them. even some scientist. still today. i know. sight.

walking down some dark alley i find this

you know what, i am so not calling this number

…there are quite a lot.

and in spite of the fact that they are short, you can still say quite a lot with them.

but since it can still get quite hard to say any long phrase too, and just for the sake of fun, i thought we might play this game where we only talk with them. what do you think, shall we give it a try?

well, read this text back – it’s your turn now!

next time they ask me “what’s up, dude?”

i’ll answer “it’s a direction”

how come “quite a lot” and “quite a few” mean the same thing?

it’s a pretty regular fall day, not cold, not warm, a bit cloudy, but not overcast. just a pretty regular fall day, and just that.

while in the last few meters of pedaling till my home i think i should probably go grocery shopping before they close the stores. so i climb the stairs, leave the iñicleta (my bicycle’s name), and head downstairs again. as i open the door to quit the building i notice something weird. i see some orange colors everywhere, like if there was some nearby building in fire or something. alarmed look around and i notice the it’s not any building nor car, but the sky which is orange and purple, tinting everything in deep saturated orange.

it’s pretty gorgeous in fact. amazingly beautiful. extraordinary, such vivid colors, it’s completely surreal, i’ve certainly never seen anything like this in my life.

i see lots of people looking up the sky too. there’s a rainbow. no, two rainbows! but i don’t mind, at this moment is not the sky colors nor the double rainbows, but the fact that the streets are full of people looking to the sky. people have left the shops, restaurants and cars and stop whatever they were doing in order to loop up in the sky. it’s an amazing phenomena. not only the sky, rainboes and the crazy colors of the city in orange and purple fire, but also seeing how everybody is amazed to the spectacle and we are all looking up the sky. to this fantastic surreal painting that we are part of, the double rainbow is nothing but just the perfect signature.

i love when random fact/events connect together. the connection often happens in the form of a flashback.


event #1:

i just woke up in a pretty fancy hotel in downtown LA. first thing to do in this sunny morning is to perform some exploration and try to identify a place for breakfast. so i start walking, and pass by a huge library that has this huge metallic plate with some equations on physics (or for the matter, on that gray area where physics meets chemistry).

of course i pause my walk and have a closer look to it. i cannot tell exactly what they are, i only recognize what looks to me like Heisenberg’s uncertainty principle (but i’m a bit unsure, as this is not an area of science where i am exactly comfortable). but it is clear to me that this is about quantum physics, that’s all i can tell. intuitively E seems to be some sort of force or potential to me, given how it gets substracted from itself in the last equation and how it acts as a driving/forced excitation in the third. but who knows. yet, i cannot stop looking at the third equation – it really catches my attention, as its shape feels sort of familiar. i look at it more closely, and i realize it’s a Helmholtz equation plus an external force indeed, an equation that in isolation expresses the change of the change of something as being proportional to the thing in itself (yes two changes, this is, the laplacian).

these sort of equations/behaviors are common in electrical engineering, and result in all sort of wave equations. but of course i don’t recognize the quantities in this particular wave equation at all, so i have no idea what the subject of the equation is. only that it must have be describing something in quantum physics and that since after taking changes (derivatives) of it twice still remains propotional to itself, it must be some sort of harmonic function, something that oscillates. indeed harmonics functions (which are eigenfunctions of the laplacian) result in stuff that oscillates like a pendulum, or like a wave (therefore the name of these equations). oscillation means cosinus functions (in 1D), complex exponential (in 2D) or spherical harmonics (in radial 3D). so whatever this equation is describing it is something what undulates like wave. of course at this point i cannot go further, and since i’m still hungry and the reason for this walk was to fulfill my stomach needs, i take a picture of the equations, which is my ever first picture in LA, and i continue walking. i’ll probably never see these equations again in my life.


picture taken in the entrance to a library in LA


event #2:

i’m chatting with my friend to whom i didn’t talk in the last few weeks. today she has been preparing some notes for a course for undergraduate students of chemistry, and she expresses her concern about how to best introduce the Schrodinger’s equation first as an introduction without alienating them with an abstract understanding of what it means. of course, i have no idea myself what the heck she’s talking about, but a science lover as i am, my first reaction is of course to go to Wikipedia and look for “Schrödinger equation”.

as soon as start i reading i realize how rotten my memories in physics are. i soon lose any hope to understand anything in this article, unless i would spend a couple of days diving in the subject, which i of course have no time to do. but at least i now know what she’s talking about. sort of. very superficially.

i’m about to close the page, but i poke one more page-down in the article, and there suddenly i see something that produces an instantaneous flashback. there is an equation there that i have seen before. not that i’ve been trained in equation matching and detection or anything, but this one equation, yes, i have seen it before. i quickly go to my phone, and search for the picture i took in LA a few weeks before. and…. match!!! yay, that Helmholtz equation i saw in LA was this famous Schrodinger’s equation thingy, and from the little bit i understand of this article it seems it has something to do with physics/chemistry and the study of atom. so that’s that it was that thing in LA, cool! of course at this point i cannot go further, and since we are talking about other topics already anyway, i close the Wikipedia. i’ll probably never see these equations again in my life.


event #3

weeks later my friend asks me for advice/help in realtime visualization of atomic structures, cause she believes that may probably help her fellow students understand what’s going on in three dimensional space. i receive the notes she is preparing for the students so i can see the context in which the visualization is needed.

i’m reading the notes in my morning commuting in the b.a.r.t., and my eyes bump into one of diagrams she had. “eh, wait a minute!”. i have seen these diagrams before when working with the essentials of lighting in computer graphics. or are they just some similar diagrams? they look exactly the same to me, hm. i read the preceding paragraphs, and i see two dimensional coefficients called m and l related to these diagrams, m running from -l to l. pretty much like indices to Legendre polynomials. oki, this cannot be an accident, these are spherical harmonics. like in computer graphics. like in electrical engineering.

i get an instantaneous flashback again. Legendre, Harmonics, Helmholtz, Schrödinger!! electromagnetic wave propagation, visibility encoding for computer graphics, atoms!!

i read the full notes, and indeed, it feels like a present given to me after all these years since i last studied about the s, p, d and f atom orbitals at school. now, 17 years later, i finally learn what they actually are, or more correctly, why they are the way they are! where they come from, how to solve them, how to describe them! how exciting! but of course at this point i cannot go further, and since i’m heading to work and finally made it to my station, and i’m running late, i stop reading the notes here. but this time i won’t say that i’ll probably never see these equations again in my life.

i love the tickles it produced in my spirit to close this circle today. relating things i know today to things i learnt no less than 17 years ago, as if they had been waiting for the connection to happen. learning is fascinating. and when it happens this way, even more. and all thanks to that metallic panel in doors to that library in Los Angles that one morning.

there aren’t many things more humiliating than being the hurricane reporter. your dignity gets miserably ruined forever, in front of the whole world, while you wear that ridiculous slicker and wellingtons, you fight the wind while trying to speak to the mic and your face gets slapped over and over again by your hoodie. i mean, was it really necessary to send anybody there to report the news? i can imagine the conversation that same morning in the officre:

- hey, have you met the new guy yet?
- the intern?
- yep, Mr Look At Me I’m A Professional Journalist. i think we should teach him how things really are over here.
- you know what, they told me there’s a hurricane coming tonight in Texas…

looking to the contacts in my phone seems like looking back in the past.

it brings old memories of good times through names that i had almost forgotten, names that like a thread that i can pull from, allow me to recover amazingly vivid moments, situations, experiences, places, people, moods, expectations, smells, adventures, ideas, interests, sounds and songs that would otherwise have sunk and get lost forever in an ocean of past times.

a few of these names belong to people i met 15 years ago and that i’m still in touch with, and many other names belong to people i only met for 15 minutes. sometimes even less. but regardless of that, as i scroll the contact list i take a moment to think about how i met every single one of these people, in which context. and regardless of that too, sometimes it all comes automatically in a fraction of a second, sharp and vivid, while other times i have to do an effort, like if for some reason the memory had decided to slip away, perhaps with complicity of the person the memory is about or with my own. but in the end all memories come back, one by one; and as i scroll this list down, for every of these names, i recover a bit of that myself i was once.

looking to this contacts list in the phone really seems like looking back in the past.

most of the times you start drawing with an idea in mind, with a target. sure thing there is always room for improvisation, but still, is not very often that you start from a completely white paper and proceed doodling and exploring weird ideas.

today i gave myself 30 minutes (well, basically the computer was busy for 30 minutes so i couldn’t use its CPUs anyway) to start from scratch (that includes writing a noise and a voronoi primitive functions) and see if i would hit any reasonably interesting patterns and look. i sort of did, the bottom line being that sometimes it’s worth exercising unplanned exploration and roaming unexplored territory for a prefixed short interval of time. planning too much can kill the magic sometimes!

anyway, today’s doodle:

given that the movement detector in my office most of the times does not detect me (forcing me to switch the lights by hand) and that most of the infrared tap and driers in public restrooms simply don’t detect my presence at all, i’m really scared of the incoming fingerprint detection technology for mobile phones. i’m sure i’ll be unable to make and respond calls!

it’s a sunny, warm, bright morning. or noon. or something, it doesn’t matter – one of the things i do when i wake up in such gorgeous mornings is to not care about time. that means i don’t look to the clock, i only listen to how things feel and go from there. and, things certainly feel good under this sun rays.

just a few minutes ago (oh well, hours) i opened the windows of my bedroom and let the world welcome me to this fantastic day. in return, i shared my morning with the world by playing my favorite movie soundtrack aloud and walking around my apartment doing my morning household chores with those same windows open big. at some point during the soundtrack i decided to jump to the streets and start heading to work. there had not been any particular reason for it to happen at that precise moment instead of any other. it just felt right to do it at that one moment. perhaps a specific chord in the soundtrack had triggered something in my brain and made me take the decision to go out. or it could have been just some purely internal process of my mind. who cares. thing is it felt right to do it then. that’s what matters. or well, that’s what no-matters, i’d say.

so here i am, in this sunny, warm, bright morning (or noon) walking the streets. everything i see in the world out there, everything i feel in my internal world in here, is all calm, promising, beautiful, easy. just right. i walk relaxed, hands in pockets, with a small grin in my face, and a huge one in my heart. for no other reason than the beauty of this morning (or noon?). indeed i don’t recall having to celebrate anything special today. that makes me celebrate this moment of happiness in itself, and life by extension. i think that if i can just celebrate life in its most simple and profound way, then i do have something big worth being happy for.

the sun rays in fall mornings are the sweetest of all sun rays. they delightful cares your cheek, neck and shoulders like no other sun rays of any other season do. they also bounce joyfully on the streets, facades, trees. i walk slowly so i can catch as many of these cheerful rays as i can. for some reason the streets feel pretty empty today. i like it, it almost makes me feel like this rays were reserved for me, like somebody had ordered this sunny, warm, bright morning for me.

or is it noon? i don’t know

i just realized that when Japan and the USA were fighting during second world war, that ocean between them… wasn’t exactly the most pacific of the oceans

i am distracted, as usual when in my morning train ride to the office, thinking of too many things at the same time at a too low intensity for any of them to stand out and bring me back to focus. as all these ideas gamble in front of my consciousness, my eyes do the same with the environment, jumping from one place to another, seeing too many things with a very low level of attention. one of the places where they pose for a fraction of a second is an ad that reads “train for success”. if i had read it for a longer time or i hadn’t been so distracted i’d have realized this was an ad for an arts school, but instead my brain decides to assume there must be a town called “success” cause the image i have in my mind for a few seconds is this:


a train leaving to Success

one would think that the amount of oral tradition these days is reduced to a few incidental and anecdotal cases, and that since the times of Homer (the greek poet, not the Simpson), about 2800 years ago, the amount of knowledge passed along that is not documented has been reduced to a minimum, if not completely eliminated. for how in a world of infinite media, endless information, regulated education and obsessive systematized could any bit of undocumented product of culture have possibly gone unnoticed?

yet there are niches of such cultural dynamics, sort of living fossils of ancient inefficient and obsoleted human habits. but what these fossils teach us is that in human nature there’s still a powerful and authentic desire to learn. so powerful actually that i can’t be stopped and sometimes, indeed, it doesn’t need protection in any form of normalized education or structured documentation.

in particular, i’m thinking of kid’s games. no kidding (well, technically, yes kidding) – i recall tons of games that we kids used to play in our school breaks, or while in the bus to school, during out free evenings after school or during vacations. these were incredibly fun games, pretty damn well designed too, that often had a handful of interesting rules, and that as far as i can remember were never taught in school or by parents or any adults in general, nor described in any book.

instead, all of those games were learnt from playing with other kids. probably during a school break, we would see the “elders” (those two years older than us) play. we would approach them and ask about the game and how it worked. we would even naively ask them if we could play with them, which of course they would never allow to happen. but we would listen and absorb the information about the dynamics and rules, then transfer it to the rest of our own friends and class mates. one day, we would be the school elders ourselves and we would teach those games to younger generations. of course we’d never allow them play with us.

all of this, as far as i can tell from my experience, happened in a parallel world to that of adults, school, television or books. and to me this is an example of very genuine oral tradition, one that kids kept alive for centuries because it was important to them. indeed kids can’t help but play all day, and they like it so badly that even the weaknesses of a mouth to mouth system where not enough to need for a better mechanism. so yes, oral tradition in it’s purest form can still be seen.

level number 1 (the canvas)

memory, algorithm, variable, entropy, thread, bit, instruction api, recursive, register, architecture, inheritance, shader, pointer, hack, compression, compiler, function, pool, xml, factory, mutex, code, alignment, C, coherence, optimization, opcodes, assembler, stack, design, huffman, buffer.

level number 2 (the brush):

polynomials, filter, trigonometry, fourier, derivative, matrix, ramps, vector, interpolation, extrusion, exponential, bending, modulation, logarithm, determinant, quaternion, singularity, rotation, reflection, geometry, base, integral, sampling, square root, attenuation, laplacian, transformation, spectrum, limit, algebra, parabola, gradient.

level number 3 (the elements):

rock, birch, scratch, penumbra, sun, branch, foam, leaf, needles, grass, bark, ripple, highlight, lichen, pine, wind, bump, moss, root, water, shadow, flower, stem, bush.

level number 4 (the piece):

color, composition, lighting, shape, texture, grouping, framing, saturation.


When you do all these four types of thinking at the same time, you get a formulanimation – something that looks for example like a forest, but that it’s just one huge mathematical formula:

“the other side of the planet” is a really far away place

you know when you feel like staying where you are, peacefully, relaxed, safe, happy, cosy, secure… where things are easy and simple, predictable and feel just fine? basically, when you are in your comfort zone? do you also know the famous memo that says that magic happens when you leave that zone? okey, today is one of those days that i gotta follow the memo. so, here we go!

as you know i get quite a few emails everyday from fans, students, followers, admirers and random people asking about everything from how’s my piano doing to why their code doesn’t work or if i can help them with some formulas or can point them to a good book on wavelet transforms. now, when it comes to the most academic emails and questions, i noticed there is a huge inconsistency in knowledge levels among the different schools/universities in the states. i get questions from college students which are better formulated, more self-consistent and more elevated in form and especially in content that some of the questions i get from certain postdoctoral researches and phd candidates. see to believe!

on another topic, sometimes i don’t even know how to answer. “i have a live, i can’t go fix your code” or “c’mon man, do your homework and learn that other thing first” are too impolite of course. but not replying to an email is too, so in the end i have to be as diplomatic as possible. oh boy, not easy.

oh, speaking of fantastic things:

i cannot help but doing these

oh, i forgot to say it aloud lately – life . is . fantastic .

i noticed that i usually don’t have time to think about maths anymore, not during the day at least, and that if i do it’s more often than not while in the bathroom (especially in the shower). that’s why now i call it the mathroom.

as usual, red traffic lights are a source of experiences.

i’m relaxed waiting for the light to change, thinking on something transcendental, like why doesn’t “beautiful” spell with two l-s instead of just one.

at that moment, the right window of the car to my left opens, and the driver gives me the following gift: “Jesus loves you, man”. i look at him, laugh a bit, softly, and start pedaling as the green lights indicates the end of our ephemeral relationship.

few meters ahead, still pedaling, i wonder what motivated the man to tell me such a thing. pity or compassion towards me cause i’m cycling instead of driving? from my perspective that would be paradoxically funny. in the other hand, today i had a good day, i’m sure i’m irradiating energy all around me, so i can’t be he saw me in need of compassion. i don’t know.

anyway, where was i…?, ah, yes, “beautiful”, the issue with the missing second l.

i like it when it’s cold. it makes me feel alive. and it also reminds me of other places, other myselves, some that i was, some that i fear i left behind. it’s so difficult to be all the yourselves you’ve ever been, to even remember them all. but this cold and gentle breeze of today helps me brings many of those myselves back, if only as memories.

if i close my eyes and dive a little bit into what i feel, images come to my mind. i’m getting out of a magnificent and ancient building after a dance performance show. it’s dark, and beautiful. the orange lamps lit the cobbles, which are old as only cobbles and some trees can get to be. i wear my scarf and my long winter coat. i like the feel of its weight in my shoulders. it sort of grounds me to the earth, here, it makes me feel attached to this place. the yellow glow of all the libraries, candy shops, coffees, restaurants and fashion shops make these streets look magical, and the city a huge christmas tree. noise, music and smells. “bonjour monsieur!, est ce que vous voulez des marrons chauds?“. it’s the perfect time to buy chestnut or doughs, and walk around inspect the window of all those shops from which i’ll never be able to afford buying. i like getting lost within these streets and alleys.

i open my eyes again. i have mixed feelings. i like what i see around me, but i also like what i see when i close them. i plug the headphones, play Tiersen’s “Le Moulin“, smile gently, and i keep walking.

what else can i do

you love words.

words are everything for you. you say them with great care. not only you like their meaning, their origins and their sound, but also you like giving them all a chance to shine, or i’d say, an opportunity. you bring them to your lips in the right moment, in the perfect context. you master them, you are indeed more agile than most people are when it comes to picking the right word, that one word that has many synonyms yet it carries some special subtle difference in its meaning that makes it worth being brought to that one sentence. you won’t stop utilizing them, nor just saying them. you love words so much.

i love silence. sometimes i wish that after a long silence, one of those conspirational silences we have, we were allowed to say only one word, one each of us. we should make a deal, or a game. only one word after a long silence. i wouldn’t matter if we had carefully selected that word during our silence, or it just had naturally came to us in a fraction of a second right before we would finally decided to break the silence. thing is i always thought, that would give silence a voice, a meaning. for how can a silence feel special if random words, sentences and topics would follow it? no – the only way for silence to shine is to honor its presence by saying a meaningful word after it.

picking the right word is important. picking the right silence is too. not all silences last the same, not all feel the same. they have a rhythm, a meaning, a color. they are a chance to listen differently.

gratefully, you love silences too. you look down when you are in silence, as if you were inspecting inside yourself. your black hair falls vertically and covers part of your face. i look at you, i don’t know if you notice it, or if you pretend you don’t. i still stare at you, relaxed, i can do this endlessly. finally, you glance at me, smile, and say something. not one single word as i wish you did, but quite a few.

i smile back. i love words too.

i sometimes realize that no matter how much people work on something, there will always be some who don’t really “understand” what they are doing. this can happen to professionals too, which often use well known facts or tricks without knowing how they really work, and without actually questioning why they work in the first place. some, however, keep asking and trying to understand fully what they do. i have put some examples of such well known but rarely understood tricks here in this blog before. today i got to answer a question about another one of those tricks. here i won’t show why it works, but how it works. you do the rest of the homework.

so, the situation is this. you need some linear eye space z values or some eye space 3d point from a regular hardware zbuffer to implement your effect. like depth of field or ssao. say you couldn’t indeed afford rendering nor storing an extra linear eyespace zbuffer in your gbuffers or forwards engine, so you are going to try to recover those eye space z values and points directly from the regular hardware 24 bit zbuffer.

good graphics programmer as you are, you will tell me to read from the zbuffer, transform back the point to eye space with the inverse of the projection matrix, and then do a division by w. that’s the correct answer, indeed. furthermore, perhaps you even understand why this works. or perhaps you have learnt this by heart… cause, why does the division by w happen after the transformation. furthermore, why a division? shouldn’t we be undoing a perspective division??

thing is, if you think about it, despite it works, the process doesn’t really make that much sense at first glance. bear with me, and let’s go through the regular rasterization/rendering process:

we start with an arbitrary point p in eye space with coordinates (x,y,z), and a projection matrix M, which implements a regular perspective projection conditioning,

first thing we do in our (vertex, tesselation or geometry) shader is to transform p by M to get our point in clip space:

perhaps you are wondering now why on earth should we use an actual expensive matrix multiplication when you can transform your point with a single fma() instruction. if you are making that question to yourself, it simply means you are not into 4 or 1 kilobyte intro coding.

anyway, at this stage the hardware can do polygon clipping against the (-w,-w,-w,+w,+w,+w) frustum cube. once that’s done, and before the rasterization can proceed, the perspective division happens. that’s the one responsible for making the far distant polygons look smaller than those near by (the projection matrix isn’t). note how indeed the w component has been conveniently set to the eye linear z (signed) distance. after the perspective division, we get our point p in ndc space, ranging from -1 to 1 (hence the name normalized device coordinates):

indeed the x and y components follow a simple proportion rule with eye z that produces the intended perspective effect of pinhole cameras. in the other hand, the z component encodes an inverse distance shape, which compresses more eye z values near the camera and less far from it. again, how convenient, huh.

so far so good, all old news. now the real deal, proceeding backwards:

we start from a pixel in our zbuffer, which has coordinates 0 to 1. you sample the zbuffer, and store it in z, such that we build a point (u,v,zbuffer(u,v)), which we rescale and bias it to map into the -1..1, meaning we got our 3D point already in ndc space. sweet, and easy.

to get to clip space, you would have to undo the perspective division now. and that’s where the problem arises, cause we don’t have w at this stage. the original pre-perspective division w has never been stored in the hardware’s zbuffer, so just don’t have enought information to proceed. panic.

the trick we all use, which most people don’t seem to understand of even question why it works, is to proceed as if nothing: just transform back directly by using inverse projection matrix into some sort of weird space, and performing a perspective (un)division afterwards… what? i know! why on earth would that works at all, right? ok, see this:

let’s assume that w was just 1, and so effectively build a fake clip space point with (-1+2u, -1+2v, -1+2zbuffer(u,v), 1 ). this must match the point we had rasterized to the zbuffer before:

now, if we transform it the with inverse projection matrix…

…without first performing any perspective (un)division, we get p in some sort of weird space

now the “magic happens”: we can divide the whole vector by its w component (negative one over z), to get

which is nothing but our original point p in eye space! ta-daaaaaa, magic!

we all hate our own voice. but when you cannot avoid having to listen to it, then the sooner you get used to it the better. i suppose. so, i’ll try to add narration to the coming live coding video, if only for that

another polysemic word in english is “table”.

my guess is that the source of the polysemy has something to do with the more than probable french origins of this word. i suppose the french people never felt the need to split the word “tabula“, which means “board” in latin (“tabla” in spanish) into a two different words, one for board and one for table, as other latin languages did. and i assume the english probably inherited this.

it also seems to me that most of the latin words in english are coming actually from france, not from spain. it probably makes sense given their geographical proximity (and affairs!).

anyway, if that was so, that would explain why this image i just composited actually makes a joke. provided you are a geek or have good memory and remember how studying chemistry looks like during (high?)school.