- the first one project texture from camera to geometry.
- the second one project from camera to environment.
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];
}