# How to cylindrically deform an image by shader?

I want to create a Shader inside of the Blender Shader editor that distorts the image cylinderically which would look something like this:

I tried to do this in blender but I failed...what did I do wrong?

These are the nodes I used:

I tried to use this .hlsl code as a reference.

• I think it would be more practical just to render the image literally UV mapped onto a cylinder, and then reuse that render here. Oct 11 at 1:45
• I'm wondering why you're using a shader at all? Cycles will do different panoramic renders in the camera. Oct 11 at 1:45
• Hello and welcome. Please use a title that reflects the content of the question. It should be succinct, unique and identifying, and summarize what the issue is so that users can at a glance broadly understand what your post is about before opening it. Use the edit link below your post and avoid any emojis salutations or extraneous text not essential to the question. Remember, your title is the first thing potential visitors will see, and will weight heavily on their decision to open your question, which will directly affect the number of answers you might get. Oct 11 at 9:12

## 1 Answer

Your HLSL yields the transformation: y -> y*(1+(intensity*abs(x))), where x and y are measured from the center of the image. This can make quite a sharp transition across x = 0. You can relieve that with some kind of mapping of x.

Here, the transform is elaborated to y -> y*(stretch+(intensity*(abs(x)^shape))). shape can smooth out the transition, adding an adjustable power of x to y.

If you want the HLSL function as posted, set shape and stretch to 1.

(Image not packed in the .blend).

You may want to investigate the compositor's Lens Distortion node, depending on where you need this effect in your workflow.

• +1, reminds me on a question about Blenders polynomial lens distortion model I had light years ago... still a mystery to me. If you're interessted and have the time, I'd appreciate an answer: computergraphics.stackexchange.com/questions/8260/…. Can re-ask the question here and add a bounty, just let me know. Oct 11 at 12:34
• @brockmann I'll have a look! Are you looking for an HLSL answer? Because I'm no great shakes at that.. Oct 11 at 12:43
• It's a bit cumbersome to set up: blender.stackexchange.com/a/181071/31447 Just added a blend file for convenience. Does this help? If you need anything else, please just let me know. Oct 11 at 17:12
• @brockmann Cheers! I'll have a go when I can. It may not be today.. but your Q has been around for a while :) Oct 11 at 17:14
• Yeah, it is supposed to be fun... no hassle. If you have the time I'd appraciate an answer. Oct 11 at 17:19