Perspective
Perspective mapping takes the world space coordinates and divides the X and Y coordinates by the Z coordinate (Figure 1). The Transformation and Coordinate Space parameters can be used to orient the texture using this projection type.The Use Rest Attribute option keeps texture maps from distorting when the geometry is animated. Contrary to the projection type name, this projection type is not the most effective for setting up a traditional camera mapped project. An OSL Projection would be more effective.
|
|
Perspective
|
Figure 1: The Perspective projection node orienting a Checks texture
In figure 2, an OSL script was used with an OSL Projection node to project a procedural marble texture from the active camera view.
|
|
OSL Projection
|
Figure 2: Using the OSL Projection node for camera projection
The OSL script used for figure 2 is listed below:
// Camera projection onto 3D scene geometry
shader CameraMap_geo(
output point uvw = 0
)
{
// Transform shading point P from world space into camera space
vector p = transform("camera", P);
float fov;
int res[2];
// Dynamically retrieve the current camera's FOV and resolution aspect ratio
getattribute("camera:fov", fov);
getattribute("camera:resolution", res);
// Map coordinates to 0-1 UV coordinate space, compensating for aspect ratio
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];
}



