OSL camera projection node

Post, discuss and share handy resources like textures, models and HDRI maps in this forum.
Forum rules
Please do not post any material that is copyrighted or restricted from public use in any way. OTOY NZ LTD and it's forum members are not liable for any copyright infringements on material in this forum. Please contact us if this is the case and we will remove the material in question.
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

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 925 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];
}
Last edited by calus on Sun Nov 25, 2018 5:05 pm, edited 1 time in total.
Pascal ANDRE
User avatar
paride4331
Octane Guru
Posts: 3809
Joined: Fri Sep 18, 2015 7:19 am

Hi calus,
very cool, thanks!
Paride
Gabriele
2 x Evga Titan X Hybrid / 3 x Evga RTX 2070 super Hybrid
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

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 :)
Pascal ANDRE
J.C
Licensed Customer
Posts: 1857
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Great scripts! Thank you for sharing :)
CPU – i9 13900KF, 128GB RAM, GPU – RTX 4090
System – Windows 11
My Behance portfolio, Blender plugin FB support group
User avatar
whersmy
Licensed Customer
Posts: 723
Joined: Thu Aug 30, 2012 7:40 am

calus, can you post an example of when this script would come in handy?
Octane 2022.1.1 nv535.98

x201t - gtx580 - egpu ec
Dell G5 - 16GB - dgpu GTX1060 - TB3 egpu @ 1060 / RTX 4090

Octane Render experiments - ♩ ♪ ♫ ♬
calus
Licensed Customer
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

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 .
Pascal ANDRE
Hugh69
Posts: 1
Joined: Tue Feb 19, 2019 8:02 pm

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!
User avatar
bepeg4d
Octane Guru
Posts: 10345
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy
Contact:

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
ab_radd
Licensed Customer
Posts: 1
Joined: Fri Aug 28, 2015 5:24 pm

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?
Luther76
Licensed Customer
Posts: 26
Joined: Fri Mar 24, 2017 3:49 pm

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
Post Reply

Return to “Resources and Sharing”