 Sometimes, this is called distortion shading. I find it kind of unusual to use the word shading for a calculation that just does a stretching because shading does not have the propagation of light, but because this can be done in a style that looks like a GPU operation and it is in the rendering pipeline people often call it distortion shading. If I were naming things I would not call it that because it does not look like shading to me. So, um so distortion shading for high field of view um optical systems. So, what do you do in that case? Remember that I said. So, for example, if you um take a look at most head mouse or displays that have a high field of view lens. This exists for example, in the in the Oculus Rift DK 2 lenses that are in the lab. If you put the lens down on a piece of graph paper, if you unscrew the lens cup and you put it down on a piece of graph paper with perfect grid lines, the grid lines will look um distorted inward like this. I am exaggerating a bit, but they will look distorted inward like that. So, if you want to compensate for it you apply a distortion shader and it will be producing what is called a barrel distortion. I believe I mentioned this before. So, it will be performing a kind of stretching outward radially. So, when it stretches outward it will cancel off the pin cushion distortions. So, that hopefully what we are straight lines here and perfect grids here will remain perfect grids after performing this cancellation after performing this distortion. So, how does this work? Suppose the image is square for a particular eye and then. So, it is square for a particular eye and then I um let us see here. I then express pixel locations in polar coordinates. So, I have theta and I have the distance r right radius let us say outward from the center. So, the reason why I am doing this is because I am going to exploit radial symmetry of the lenses. So, I am going to assume that the lenses are radially symmetric. It should be a spherical lens and I am trying to compensate for this spherical aberration distortion. And so, what I do is um I perform a transformation as follows. I take every pixel convert it to r theta coordinates and then I perform a transformation that maps that to some function of r and keeps the theta the same. And so, again this is radially symmetric and the particular function that I perform f of r is assumed to be some general form. I am going to give a general form it is just standard formula that comes from optical engineering textbooks um. And so, it is based on the theory of optics and how spherical um the spherical shape of a lens is not perfect for maintaining the um the the same focal depth as you get out to the periphery. So, this is um standard formula for that has coefficient c 1 times r squared plus coefficient c 2 times r to the fourth plus coefficient c 3 times r to the sixth. And if you want you can generate more terms by using even powers of the radius. There are no odd powers it is just a way the geometry works out in optical engineering which I am certainly not going to go through um and ends up being a some sort of nightmare of algebra let us say to derive that um. So, odd powers not needed not needed this is a theory of optics you can look in optical engineering textbooks or tutorials for that if you like um. So, basically what you do is you choose c 1, c 2 and c 3 um select c 1, c 2 and c 3 and then you keep these fixed forever right. So, you keep these fixed this is some kind of radial distortion function it performs some kind of stretching that cancels off this barrel distortion. How do you select these um well one way to do it is you get someone who is very good at looking at grid patterns in in virtual reality. So, you render what is supposed to be a perfect grid pattern should look exactly like you are standing in front of a wall that has graph paper on it. And then um if you do not apply this function then it should look distorted like this in a pin cushion way. After you apply this function you can adjust these 3 coefficients c 1, c 2 and c 3 so that it looks like a perfect grid um. It sounds somewhat straight forward it is actually very hard to select these 3 parameters and um it generally leads to lots of arguments and discussion about what are the right values um. It is actually very hard even if you design a perfect let us say laser rig and you study and measure exactly the optical properties of your lens at the periphery and then work to scientifically calculate exactly what these values should be they still might not match human perception. It is very very hard to get these right and one of the difficulties is that when you put the lens up in front of your eyes remember that as your eyes look out of the side of the lens you are pointing your fovea to the side of the lens then the pupil is translating away from the center of the of the lens. And so that means that the distortion is already changing again in some different ways on what can be compensated for here because this is making the assumption that you are looking through the center of the lens. So, if you go into the lab you put on the headset and you try to use your vestibular ocular reflex um pick one of the um the demo apps such as wind lens right. It is very clean you know beautiful looking pictures come up to a wall or a corner of a building or tree let us say and move your head back and forth you should be able to see this optical distortion even though it is compensated here it still cannot account for the part where um as you use your vestibular ocular reflex your pupil is not looking through the center of the lens anymore and there will be some distortions that are not compensated. And you could try to change these coefficients to compensate for that, but then it will be messed up when you do some other motion. So, it seems to be a somewhat of an unwinnable scenario if you have optics that have spherical distortion, but this is the simple compensation as done. So, this is just applied as a last step across the image after we are done rendering. Questions about that? Yeah. Does the value of C 1 C 2 C 2 depends on lens? Yes that is right. So, it does. So, if you are to change the lenses you need to calculate new values for this. Yeah, but beyond that once you have the physical setup done it should be fine. Um there is other subtleties like if the lens does not fit over the center of your eyes because you have different interpupillary distance some other setting of values here may be better for you. But again because your pupils can translate back and forth across the lenses anyway it turns out none of the values are absolutely perfect. So, doing this distortion shading is better than not doing it, but it is still not perfect and that is why I encourage you to go and look and see if you can still see lens distortions. You know take a look at a vertical line move your head back and forth and do this vestibular ocular reflex motion and see if it looks like the line is warping as you move it should you know you should train yourself to look for that problem.