8

Is it possible to create a lens shader with EEVEE/Cycles ?

I'd like to have the control over the camera position and the ray direction per sample. This allows to simulate various conventional lens distortions (which I'm not interested in) and other deforming effects. Houdini and Arnold supports a camera lens shader, someone also used it to run across the objects and bake textures.

Some other ideas include run a particle simulation, and assign each particle to a pixel in the image as if it were a camera looking from that particle. Or you can just use an ordinary object to sample the space around. You can mix perspective and orthographic in different parts of the image, blending between them, or even zoom only part of the image. This thread shows how to set it up and one possible use that this kind of level of control gives you.

https://www.sidefx.com/tutorials/lens-shaders-for-gamedev/

I insist that I'm not trying to replicate this specific effect, I'm looking for this level of control per pixel.

Duarte Farrajota Ramos
  • 59,425
  • 39
  • 130
  • 187
menoz
  • 81
  • 1
  • 1
    If I'm not mistaken OSL scripts might also allow this – Duarte Farrajota Ramos Jul 06 '20 at 17:13
  • i'll look into that thank you – menoz Jul 07 '20 at 09:06
  • 1
    i've seen the question has been marked as duplicated, it's not. I've already seen that other question and that answer doesn't allow to edit the camera position per pixelas i am asking here. – menoz Jul 07 '20 at 09:11
  • 1
    I have no Idea about OSL scripts, but else then them see this maybe: https://blender.stackexchange.com/a/126669/60759 Using baking functionality might replicate what you need in Cycles. – Martynas Žiemys Jul 07 '20 at 10:49
  • It sounds like what you may want is Ray Marching with Signed Distance Fields. This Gumroad shader implements a variant of them math described in this article. – Marty Fouts Sep 25 '21 at 21:56
  • I've had to do similar things in the past, and I ended up using a refract plane immediately in front of the camera. Not ideal, but it fit my needs at the time – sybog64 Feb 04 '23 at 03:19
  • given materials allow practically arbitrary expressions, i certainly expect for-the-most-part to be able to port any shadertoy/GLSL expressions into material expressions. for example, a world's material has inputs for the camera UV, which is likely the input of whatever projection expression we want to to program, and will render at all parts of the camera. – ThorSummoner Jan 13 '24 at 08:25
  • I'm certainly not an expert, but a good demo of applying a projection/transform to a camera might be this fish-eye demo on shadertoy. converting the series of GLSL codes into shader-nodes and linking them all up together is often how I start to try to start authoring a complex material/world/composite https://www.shadertoy.com/view/MsjGzh – ThorSummoner Jan 13 '24 at 08:33

0 Answers0