Page 2 of 2

Re: OSL camera projection node

PostPosted: Mon Nov 23, 2020 8:51 am
by bepeg4d
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

Re: OSL camera projection node

PostPosted: Mon Nov 23, 2020 2:19 pm
by Luther76
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

Re: OSL camera projection node

PostPosted: Tue Apr 13, 2021 11:31 am
by flupper
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?

Re: OSL camera projection node

PostPosted: Wed Apr 14, 2021 7:43 am
by flupper
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.

Re: OSL camera projection node

PostPosted: Sat Oct 23, 2021 4:13 am
by GurneyHM
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:

Re: OSL camera projection node

PostPosted: Mon Oct 25, 2021 3:59 am
by GurneyHM
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];
}