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 41 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
--------------------
Maya 2018.5, Windows 7, 128 GB RAM
4x GTX 1070, driver 417.35
--------------------

--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
--------------------
calus
Licensed Customer
Licensed Customer
 
Posts: 1198
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
Win 7 / i7 5930 - 32gb / 1 x quadro K620 / 2 x Evga Titan X Hybrid
User avatar
paride4331
Octane Guru
Octane Guru
 
Posts: 2110
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
--------------------
Maya 2018.5, Windows 7, 128 GB RAM
4x GTX 1070, driver 417.35
--------------------

--------------------
Join MAYA OCTANE USERS Skype discussion here :
https://join.skype.com/LXEQaqqfN15w
--------------------
calus
Licensed Customer
Licensed Customer
 
Posts: 1198
Joined: Sat May 22, 2010 9:31 am
Location: Paris

Return to Resources and Sharing


Who is online

Users browsing this forum: No registered users and 1 guest

Sat Jan 19, 2019 2:01 am [ UTC ]