Hair not rendered with custom lens

On 06/05/2015 at 02:33, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R15+ 
Language(s) :     C++  ;

Hi, I'm having an important problem with my custom lens plugin: Hair is simply not rendered.
And strange distortion problems occur with Sketch & Toon and XParticles. What else do I need
to do other than calculating a ray position and direction in VideoPostData::CreateRay()?

Thanks in advance!

On 06/05/2015 at 11:32, xxxxxxxx wrote:

Unfortunately the SDK does not have a custom lens example plugin. I filled Ray::p, Ray::v, Ray::pp and
Ray::vv from VideoPostData::CreateRay(). But with the VideoPost plugin enabled, Hair doesn't render and
Sketch & Toon does not render correctly (eg. Edges are either not visible or strangely distorted).

On 08/05/2015 at 08:35, xxxxxxxx wrote:

Did you try to set pp and vv equal to p and v resp.? Do you still get such distortions then?
Do you have ior set as well or is it 1.0 by default?

I think you are right, an sdk example would be quite useful.

On 08/05/2015 at 09:27, xxxxxxxx wrote:

"I filled Ray::p, Ray::v, Ray::pp and

show some code, specially for pp and vv.

On 09/05/2015 at 00:07, xxxxxxxx wrote:

Hey Guys, thanks for chiming in!

Originally posted by xxxxxxxx

Did you try to set pp and vv equal to p and v resp.? Do you still get such distortions then? 
Do you have ior set as well or is it 1.0 by default?

I think you are right, an sdk example would be quite useful.

No I only tried just not  setting pp and vv at all. I'm going to try that, thanks!
Currently, my code looks like this:

/// ---------------------------------------------------------------------------
/// ---------------------------------------------------------------------------
void LensVideoPost::CreateRay(Ray* ray, Float x, Float y)
  if (!this->rdata || !this->lens) return;
  **ray- >ior = 1.0;**
  Float lx, ly;
  this->rdata->CalcLens(x, y, lx, ly);
  this->lens->CreateRay(*this->rdata, lx, ly, ray->p, ray->v);
  this->rdata->CalcLens(x + 1, y, lx, ly);
  this->lens->CreateRay(*this->rdata, lx, ly, ray->pp[0], ray->vv[0]);
  this->rdata->CalcLens(x, y + 1, lx, ly);
  this->lens->CreateRay(*this->rdata, lx, ly, ray->pp[1], ray->vv[1]);
  this->rdata->CalcLens(x + 1, y + 1, lx, ly);
  this->lens->CreateRay(*this->rdata, lx, ly, ray->pp[2], ray->vv[2]);
 **  #else**
 **  for (Int32 i = 0; i  < 3; ++i) {**
 **    ray->pp[i] = ray->p;**
 **    ray->vv[i] = ray->v;**
 **  }**

Edit:  Added the (bold) #else part and setting ior to 1.0. Unfortunately it didn't change the results 😞
Of course tested with LENSVIDEOPOST_MULTIRAY not defined.

The documentation says

The square is one screen pixel wide in X and Y direction.

This is why I offset x and y by 1 for pp[0], 1 and 2 respectively.

On 09/05/2015 at 09:12, xxxxxxxx wrote:

well, from this code I can't tell pretty much where is the problem, but 2 things are required:

1- definition of "this->lens->CreateRay"
2- don't use (x,y) , (x + 1, y) , (x, y + 1), (x + 1, y + 1). try to use instead (x - 0.5, y - 0.5) , (x + 0.5, y - 0.5), (x - 0.5, y + 0.5), (x + 0.5, y + 0.5)
this is for a personal reason "MipMAP should work on surrounding pixels, not 1 corner".

On 11/05/2015 at 09:56, xxxxxxxx wrote:


Sketch & Toon and Hair are 2D post effects and don't necessarily have something to do with the renderer. And custom lenses are seldom used. So I guess that these post effects simply don't support custom lenses and this is a limitation.

Best wishes,

On 15/05/2015 at 04:28, xxxxxxxx wrote:

But if these post effects are affected (distorted) by the custom ray doesn't this imply that they are somehow using the ray? If they wouldn't it wouldn't have an effect on them right?

I would be very interested to know how this interfers (for future reference).

On 18/05/2015 at 04:23, xxxxxxxx wrote:

Sorry for the late reply.
Thanks for your answer Sebastian. That is very unfortunate (and makes my client unhappy as well).

@Katachi: I agree, this would be my logic as well. Also, they support all built-in Camera modes. I can
hardly imagine they are handling each of them seperately on their own without relying on an already
computed ray.


On 22/05/2015 at 02:13, xxxxxxxx wrote:


I spoke with the developers.

The "built-in Camera modes" have nothing to do with custom lenses. These cameras are just different projection matrices and post effects that do perform world-to-screen transformations use these matrices (using functions like WS()). So a post effect cannot use or pay attention to a custom lens. This is a limitation.

An example is the "Cylindrical Lens" which is a custom lens. This custom lens also won't work with these post effects.

Best wishes,

On 22/05/2015 at 02:30, xxxxxxxx wrote:

there is an ugly work around Niklas.

render the image with standard camera, now the whole image is a texture, put it on a plane,  and render this plane with your custom lens.

On 07/12/2015 at 18:24, xxxxxxxx wrote:

This post makes me sad 😞

Ain't this the same problem with glow?
I remember trying the R17 Demo when it came out, glow seemed to be working with custom lenses.
Anybody tested custom lenses with hair or sketch & toon on R17?

If the problem is the world-to-screen transformations, video posts that provide custom lenses could calculate the missing matrices overriding a (new) virtual WS().

On 11/03/2016 at 16:14, xxxxxxxx wrote:

Originally posted by xxxxxxxx

If the problem is the world-to-screen transformations, video posts that provide custom lenses could calculate the missing matrices overriding a (new) virtual WS().


On 14/03/2016 at 03:06, xxxxxxxx wrote:


can you elaborate on that? If you think about it you will realize that a custom lens that creates rays for given screen space coordinate and a function like WS() that converts a world space coordinate into a screen space coordinate are two different things.

WS() is just a function. That means for every given input value there must be a single return value. So if you hand over a certain world space coordinate you can only get one screen space coordinate.

But custom lenses don't work this way. They define rays. And the position where these rays intersect with the scene depends on the ray and the the scene geometry. So one can easily create a custom lens that creates rays in a way that two rays (for two different screen space coordinates) will hit the same surface point (world space coordinate).

So WS() is not a "inverse function" for a custom lens and there cannot be such a thing. So I'm afraid there will be no solution for this anytime soon.

Best wishes,

On 15/03/2016 at 17:05, xxxxxxxx wrote:

I understand, the Custom lens plugin is limited to creating rays only, and there's no safe way to get the world to screen coordinate with it.

What I'm asking is a new feature. A new virtual function on VideoPostData.
If you give me a virtual WS() with the world coordinate, I can provide the screen coordinate.
If that's the only problem, we can solve it.

I constantly need to remind people that my plugin will not render sketch & toon. They usually get frustrated and it sounds like I'm not doing my best.
At least, since I read this post, I don't say the word "incompatible" anymore. I say "it's a Cinema 4D limitation".
But either way is bad, because it limits artistic freedom.

On 16/03/2016 at 02:55, xxxxxxxx wrote:


I added your idea to our internal database. But the problem remains that a custom lens is part of a video post while WS() is part of a BaseView. These are two different things that have nothing to do with each other.

Best wishes,

On 16/03/2016 at 05:27, xxxxxxxx wrote:

Thanks Sebastian!
I'm sure Maxon will find a way to make it work!
If there's anything I could do to help in this process, just call.

On 10/06/2016 at 05:44, xxxxxxxx wrote:


Any news on that subject?

I'm being asked for chargebacks because of that.
One user said: "So I can't use hair? Sorry, your plugin is useless for me."


On 13/06/2016 at 05:02, xxxxxxxx wrote:

Hi Roger,

I'm afraid Sebastian and you might be talking past each other.
Unfortunately this is a technical constraint currently, that can not be fixed easily. So you shouldn't expect any news on this soon. Terribly sorry.

On 26/12/2016 at 14:14, xxxxxxxx wrote:


Here I bring it on again... any news?

Camera plugins like mine look amateur because of that limitation.
I'm tired of pasting my default answer saying it's a known problem but Maxon won't fix it.

Is there at least an internal ticket for that?