OSL camera projection node

Forums: 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.

OSL camera projection node

Postby calus » Mon Feb 26, 2018 11:58 am

calus Mon Feb 26, 2018 11:58 am
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 790 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
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: OSL camera projection node

Postby paride4331 » Mon Feb 26, 2018 12:46 pm

paride4331 Mon Feb 26, 2018 12:46 pm
Hi calus,
very cool, thanks!
Paride
Gabriele
2 x Evga Titan X Hybrid / 3 x Evga RTX 2070 super Hybrid
User avatar
paride4331
Octane Guru
Octane Guru
 
Posts: 3686
Joined: Fri Sep 18, 2015 7:19 am

Re: OSL camera projection node

Postby calus » Sun Nov 25, 2018 5:08 pm

calus Sun Nov 25, 2018 5:08 pm
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
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: OSL camera projection node

Postby J.C » Fri Feb 15, 2019 8:24 am

J.C Fri Feb 15, 2019 8:24 am
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
J.C
Licensed Customer
Licensed Customer
 
Posts: 1712
Joined: Thu May 13, 2010 6:35 pm
Location: Wrocław

Re: OSL camera projection node

Postby whersmy » Sun Feb 17, 2019 2:54 pm

whersmy Sun Feb 17, 2019 2:54 pm
calus, can you post an example of when this script would come in handy?
Octane 2022.1.1 nv535.98
mac pro g5| pentium g2030 iGPU| maximus extreme V| 2x gtx590 - 8gb - SSD - win7-x64- 1500W Silverstone|
x201t - gtx580 - egpu ec
Dell G5 - 16GB - dgpu GTX1060 - TB3 egpu @ 1060 / RTX 4090

Octane Render experiments
User avatar
whersmy
Licensed Customer
Licensed Customer
 
Posts: 723
Joined: Thu Aug 30, 2012 7:40 am

Re: OSL camera projection node

Postby calus » Sun Feb 17, 2019 6:24 pm

calus Sun Feb 17, 2019 6:24 pm
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
calus
Licensed Customer
Licensed Customer
 
Posts: 1308
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Re: OSL camera projection node

Postby Hugh69 » Sat Mar 02, 2019 4:56 pm

Hugh69 Sat Mar 02, 2019 4:56 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!
Hugh69
 
Posts: 1
Joined: Tue Feb 19, 2019 8:02 pm

Re: OSL camera projection node

Postby bepeg4d » Mon Mar 04, 2019 7:17 am

bepeg4d Mon Mar 04, 2019 7:17 am
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
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9940
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: OSL camera projection node

Postby ab_radd » Thu Apr 30, 2020 11:31 pm

ab_radd Thu Apr 30, 2020 11:31 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?
ab_radd
Licensed Customer
Licensed Customer
 
Posts: 1
Joined: Fri Aug 28, 2015 5:24 pm

Re: OSL camera projection node

Postby Luther76 » Fri Nov 20, 2020 2:23 pm

Luther76 Fri Nov 20, 2020 2:23 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
Luther76
Licensed Customer
Licensed Customer
 
Posts: 25
Joined: Fri Mar 24, 2017 3:49 pm
Next

Return to Resources and Sharing


Who is online

Users browsing this forum: No registered users and 10 guests

Thu Mar 28, 2024 7:12 pm [ UTC ]