I’ve been following a Eat3d tutorial on how to create a lens distortion shader, but I can’t quite figure out how to assign it in the end.
I’ve been looking at the content example for postprocess materials and tried to replicate the process… it sort of works but it shrinks my frame down for some reason. I think it has to do with the Screen Position node, but I’m not sure what to do with it. If I unhook it the results looks even more broken than this.
does anyone know how I can hook this up correctly?
yeah, that’s it. but it’s a bit lengthy.
I uploaded the shader for you, saves you a bit of time hopefully. thanks for looking into it! really appreciated.
There is still some UV stretching within the lens but the lens itself has a clear undistributed edge adding this logic to the beginning of the Material:
hi eric!
thank you very much, that sort of worked. I mean it does work, so thanks for solving the problem!
but this shader itself is not really what I was hoping I think.
is there a easy way to apply a simple barrell distortion to the camera without going super crazy on the FOV?
if you have any suggestions, that would be amazeballs.
Old question, but in case anyone pokes around this question again, the Eat3D video is a bit more complex than is what is needed if you want simple barrel distortion. Doing a little digging around because I wanted to do the same thing, I found this:
However, as I read the shader code, I noticed that it was being completely ridiculous, first it gets the angle of the UV vector, the figures out the “magnification” using the barrel distortion, then it calculates the new x and y positions using sine and cosine on the angle–which is completely redundant. In fact, you can throw away all those trig ops (well and you can’t do atan in a material anyways) and just scale the vector using the barrel power parameter. You end up with a cute little material that you can create barrel or pincushion effects with on a single parameter. Screenshots of two examples and the material to follow.
Just a couple of notes:
If you make the material, create a material instance so you can change the parameter easier without recompiling the material constantly. You can also create a dynamic material instance in blueprints with it and then modify the parameter via blueprints if you want to mess around and figure out what the right “barrel power” should be for your application (e.g., Cardboard).
The final material masks out the pixels beyond the distortion area with black. If you’re already using something like a mask to get rid of those pixels, it’s an unnecessary step (use the previous material). You could also simply move that code to pick between the normal texture coordinate (in place of black) or the calculated texture coordinate by the exact comparison and this would give you a non-distorted image in those areas (more like the image in the links above).
Finally, I noticed that my post processing didn’t work properly in the preview window, at least on my Mac. Instead, I had to build and run in a separate window and then everything looked right.
Thank you very much! Ive been looking the whole evening for a workaround until i found your answer.
Also on a side note, if you dont want the black borders on your screen, you can plug the scene texture in the A inferior to B condition. I find it nicer, but whatever, thank’s a lot!