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.

Re: OSL camera projection node

Postby bepeg4d » Mon Nov 23, 2020 8:51 am

bepeg4d Mon Nov 23, 2020 8:51 am
Hi Luther,
if you are using c4doctane, please have a look at this Xpresso example, where you can change the reference Camera:
viewtopic.php?f=87&t=63808

ciao Beppe
User avatar
bepeg4d
Octane Guru
Octane Guru
 
Posts: 9939
Joined: Wed Jun 02, 2010 6:02 am
Location: Italy

Re: OSL camera projection node

Postby Luther76 » Mon Nov 23, 2020 2:19 pm

Luther76 Mon Nov 23, 2020 2:19 pm
Ciao Beppe,
thanks for your reply. Actually I use houdini, but I have used c4d for a long time. I'll try to see your link, maybe it's useful.

Thanks.

Paolo
Luther76
Licensed Customer
Licensed Customer
 
Posts: 25
Joined: Fri Mar 24, 2017 3:49 pm

Re: OSL camera projection node

Postby flupper » Tue Apr 13, 2021 11:31 am

flupper Tue Apr 13, 2021 11:31 am
I am using Octane for Blender and I am trying to solve the following problem:
In Blender I need a backplate image (a jpg, not an environment image) in the Octane preview in the viewport to exactly match the Blender render border while in active camera view (numpad 0). In Blender Cycles you can simply do this by using window coordinates from the the texture coordinate node, using those to display an image in the world nodes (so without any object). But in Octane I could not find any other way to do that then using OSL. I adapted the example script from the beginning of the thread a little and came up with the following:

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

This gets the aspect correct for a 4k image (due to the 2160/3840 value) disregarding the aspect of the viewport. However, this backplate setup does not zoom in/out when manually zooming in/out in the viewport. What would need to be changed/added in the OSL script to make this work? Or is there a simpler way to get a backplate in the world/environment nodes in Octane?
flupper
 
Posts: 2
Joined: Sun Mar 08, 2020 10:06 am

Re: OSL camera projection node

Postby flupper » Wed Apr 14, 2021 7:43 am

flupper Wed Apr 14, 2021 7:43 am
Only a couple of hours after my post above I finally found the proper solution for a flat backplate image in Blender Octane:
There is the Camera node (below Input in the Add menu). The Camera node has an "Octane Front Projection" output which when connected to the projection input of an image node does exactly what I was looking for in the World nodes.
A very simple and effective solution, but quite hard to find on the web unfortunately.
flupper
 
Posts: 2
Joined: Sun Mar 08, 2020 10:06 am

Re: OSL camera projection node

Postby GurneyHM » Sat Oct 23, 2021 4:13 am

GurneyHM Sat Oct 23, 2021 4:13 am
Hi You guys - thanks for this script.

I used it in the OSL Projection node in Blender. It works but I get odd results. Any help? I have a camera called 'Camera.001' so I changed that in the script. It projects, but i not aligned correctly.

Thanks in advance!

My Node:

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


Results:
GurneyHM
 
Posts: 2
Joined: Tue Jun 29, 2021 2:03 pm

Re: OSL camera projection node

Postby GurneyHM » Mon Oct 25, 2021 3:59 am

GurneyHM Mon Oct 25, 2021 3:59 am
Hey all - really hoping for some help here.

I'm using Octane for Blender, and I am unable to get this to work.

Am I correct in assuming this first method is to project textures onto geometry? An that the textures projected will be fixed to that geometry at render time?

Code: Select all
shader CameraMap_geo(
    output point uvw = 0)
{
    vector p = transform("Camera.001", 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];
}
GurneyHM
 
Posts: 2
Joined: Tue Jun 29, 2021 2:03 pm
Previous

Return to Resources and Sharing


Who is online

Users browsing this forum: No registered users and 7 guests

Tue Mar 19, 2024 1:59 pm [ UTC ]