Page 1 of 2

OSL camera projection node

PostPosted: Mon Feb 26, 2018 11:58 am
by calus
Here are 2 OSL projection shaders useful for camera mapping :

- the first one project texture from camera to geometry.

- the second one project from camera to environment.


cameraProj.orbx
(251.39 KiB) Downloaded 800 times



cameraMap_geometry.osl
Code: Select all
shader CameraMap_geo(
    output point uvw = 0)
{
    vector p = transform("camera", P);
    float fov;
    int res[2];
    getattribute("camera:fov", fov);
    getattribute("camera:resolution", res);
    uvw[0] = 0.5 - 0.5 * p[0] / p[2] / tan(fov / 2) ;
    uvw[1] = 0.5 - 0.5 * p[1] / p[2] / tan(fov / 2) * res[0] / res[1];
}


cameraMap_environment.osl
Code: Select all
shader CameraMap_env(
    output point uvw = 0)
{
    vector p = transform("camera", I);
    float fov;
    int res[2];
    getattribute("camera:fov", fov);
    getattribute("camera:resolution", res);
    uvw[0] = 0.5 + 0.5 * p[0] / p[2] / tan(fov / 2) ;
    uvw[1] = 0.5 - 0.5 * p[1] / p[2] / tan(fov / 2) * res[0] / res[1];
}

Re: OSL camera projection node

PostPosted: Mon Feb 26, 2018 12:46 pm
by paride4331
Hi calus,
very cool, thanks!
Paride
Gabriele

Re: OSL camera projection node

PostPosted: Sun Nov 25, 2018 5:08 pm
by calus
There was a mistake in previous shader version, I have updated the first post with scripts that should work just fine in any case now :)

Re: OSL camera projection node

PostPosted: Fri Feb 15, 2019 8:24 am
by J.C
Great scripts! Thank you for sharing :)

Re: OSL camera projection node

PostPosted: Sun Feb 17, 2019 2:54 pm
by whersmy
calus, can you post an example of when this script would come in handy?

Re: OSL camera projection node

PostPosted: Sun Feb 17, 2019 6:24 pm
by calus
whersmy wrote:calus, can you post an example of when this script would come in handy?

There's an ORBX sample in the first post, you can see how to use the OSL projection shader for environment backplate or with geometry foreground objects.
Camera projection is typically useful for VFX when you need to integrate live footage and CG elements.

Standalone and some plugins don't have this feature builtin, and in it's not easy to setup with the perspective projection node,
so in this case this OSL projection shader can be handy .

Re: OSL camera projection node

PostPosted: Sat Mar 02, 2019 4:56 pm
by Hugh69
Hi, I'm relatively new to octane (a couple of weeks) and I'm trying to do a projection of an image onto geometry so i can make a photograph (of a car park) look like it has a slight camera move. The image in live view is slightly off to the geometry I've built to catch the projection of objects in the scene (buildings, wall, antennas). I tried googling for an answer but didn't find anything that would fix it.

I'm using C4D and the octane plugin, without knowing much about octane it seems like this post might fix my problem, but I'm not sure how to apply this OSL code to my scene. Would really appreciate a walk through.

*I downloaded the orbx file and it opened in the standalone renderer but I'm still getting to terms with using the C4D plugin, and its the first time I've opened up the standalone renderer so I feel like a fish on dry land right now!

Re: OSL camera projection node

PostPosted: Mon Mar 04, 2019 7:17 am
by bepeg4d
Hi Hugh69,
about c4doctane and osl. you can start to have a look at the manual here:
http://www.aoktar.com/octane/TEXTUREOSL1.html
Both calus’s scripts are already present in the osl Script preset popup menu.
ciao Beppe

Re: OSL camera projection node

PostPosted: Thu Apr 30, 2020 11:31 pm
by ab_radd
is there any way to reference a specific camera, if you have more than 1 camera in your scene? So, could you project from a camera you are not looking through?

Re: OSL camera projection node

PostPosted: Fri Nov 20, 2020 2:23 pm
by Luther76
Hi, I have the same need as the previous post.
I need to project with a different camera than what I use for rendering.

There is a way to do that?

Thanks

Luther