2

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

enter image description here

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

enter image description here

These are the nodes I used:

enter image description here

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

enter image description here

vklidu
  • 36,165
  • 1
  • 61
  • 135
shadwne
  • 21
  • 3
  • 1
    I think it would be more practical just to render the image literally UV mapped onto a cylinder, and then reuse that render here. – TheLabCat Oct 11 '21 at 01:45
  • 1
    I'm wondering why you're using a shader at all? Cycles will do different panoramic renders in the camera. – Ron Jensen Oct 11 '21 at 01:45
  • 1
    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. – Duarte Farrajota Ramos Oct 11 '21 at 09:12

1 Answers1

7

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.

enter image description here

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

enter image description here

(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.

Robin Betts
  • 76,260
  • 8
  • 77
  • 190
  • +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: https://computergraphics.stackexchange.com/questions/8260/how-to-match-blenders-polynomial-lens-distortion-model-with-glsl. Can re-ask the question here and add a bounty, just let me know. – brockmann Oct 11 '21 at 12:34
  • @brockmann I'll have a look! Are you looking for an HLSL answer? Because I'm no great shakes at that.. – Robin Betts Oct 11 '21 at 12:43
  • Awesome! Can implement that to GLSL at some later point... main issue was the math, wasn't accurate enough for whatever reason. – brockmann Oct 11 '21 at 13:01
  • @brockmann .. not immediately sure how to produce your test Blender image to calibrate against, and be sure we're looking at the right thing..? – Robin Betts Oct 11 '21 at 16:55
  • 1
    It's a bit cumbersome to set up: https://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. – brockmann Oct 11 '21 at 17:12
  • 1
    @brockmann Cheers! I'll have a go when I can. It may not be today.. but your Q has been around for a while :) – Robin Betts Oct 11 '21 at 17:14
  • 1
    Yeah, it is supposed to be fun... no hassle. If you have the time I'd appraciate an answer. – brockmann Oct 11 '21 at 17:19