Panda3D
Public Member Functions | Static Public Member Functions

ProjectionScreen Class Reference

A ProjectionScreen implements a simple system for projective texturing. More...

List of all members.

Public Member Functions

 ProjectionScreen (string name)
 ProjectionScreen ()
GeomNode generateScreen (NodePath const projector, string screen_name, int num_x_verts, int num_y_verts, float distance, float fill_ratio)
 Synthesizes a polygon mesh based on the projection area of the indicated projector.
VBase4 const getFrameColor ()
 Returns the color the screen will be painted at the portions outside of the lens' frustum.
bool getInvertUvs ()
 Returns whether this screen is compensating for a graphics driver inverting the framebuffer image.
NodePath const getProjector ()
 Returns the NodePath to the LensNode that is to serve as the projector for this screen, or empty if no projector is associated.
string getTexcoordName ()
 Returns the name of the texture coordinates that will be generated by this particular ProjectionScreen, as set by set_texcoord_name().
VBase4 const getVignetteColor ()
 Returns the color the screen will be painted at the portions outside of the lens' frustum.
bool getVignetteOn ()
 Returns true if vertex-based vignetting is on, false otherwise.
PandaNode makeFlatMesh (NodePath const this_np, NodePath const camera)
 Generates a deep copy of the hierarchy at the ProjectionScreen node and below, with vertices flattened into two dimensions as if they were seen by the indicated camera node.
 recompute ()
 Recomputes all the UV's for geometry below the ProjectionScreen node, as if the texture were projected from the associated projector.
 regenerateScreen (NodePath const projector, string screen_name, int num_x_verts, int num_y_verts, float distance, float fill_ratio)
 Removes all the children from the ProjectionScreen node, and adds the newly generated child returned by generate_screen().
 setFrameColor (VBase4 const frame_color)
 Specifies the color the screen will be painted at the portions outside of the lens' frustum; i.e.
 setInvertUvs (bool invert_uvs)
 Some OpenGL graphics drivers are known to invert the framebuffer image when they copy it to texture.
 setProjector (NodePath const projector)
 Specifies the LensNode that is to serve as the projector for this screen.
 setTexcoordName (string texcoord_name)
 Specifies the name of the texture coordinates that are generated by this particular ProjectionScreen.
 setVignetteColor (VBase4 const vignette_color)
 Specifies the color the screen will be painted at the portions outside of the lens' frustum; i.e.
 setVignetteOn (bool vignette_on)
 Specifies whether vertex-based vignetting should be on.

Static Public Member Functions

static TypeHandle getClassType ()

Detailed Description

A ProjectionScreen implements a simple system for projective texturing.

The ProjectionScreen node is the parent of a hierarchy of geometry that is considered a "screen"; the ProjectionScreen will automatically recompute all the UV's (for a particular texture stage) on its subordinate geometry according to the relative position and lens parameters of the indicated LensNode.

All this does is recompute UV's; the caller is responsible for applying the appropriate texture(s) to the geometry.

This does not take advantage of any hardware-assisted projective texturing; all of the UV's are computed in the CPU. (Use NodePath.project_texture() to enable hardware-assisted projective texturing.) However, the ProjectionScreen interface does support any kind of lens, linear or nonlinear, that might be defined using the Lens interface, including fisheye and cylindrical lenses.


Constructor & Destructor Documentation

ProjectionScreen ( string  name)

Member Function Documentation

GeomNode generateScreen ( NodePath const  projector,
string  screen_name,
int  num_x_verts,
int  num_y_verts,
float  distance,
float  fill_ratio 
)

Synthesizes a polygon mesh based on the projection area of the indicated projector.

This generates and returns a new GeomNode but does not automatically parent it to the ProjectionScreen node; see regenerate_screen().

The specified projector need not be the same as the projector given to the ProjectionScreen with set_projector() (although this is often what you want).

num_x_verts and num_y_verts specify the number of vertices to make in the grid across the horizontal and vertical dimension of the projector, respectively; distance represents the approximate distance of the screen from the lens center.

The fill_ratio parameter specifies the fraction of the image to cover. If it is 1.0, the entire image is shown full-size; if it is 0.9, 10% of the image around the edges is not part of the grid (and the grid is drawn smaller by the same 10%). This is intended to work around graphics drivers that tend to show dark edges or other unsatisfactory artifacts around the edges of textures: render the texture larger than necessary by a certain fraction, and make the screen smaller by the inverse fraction.

static TypeHandle getClassType ( ) [static]
VBase4 const getFrameColor ( )

Returns the color the screen will be painted at the portions outside of the lens' frustum.

See set_frame_color().

bool getInvertUvs ( )

Returns whether this screen is compensating for a graphics driver inverting the framebuffer image.

See set_invert_uvs().

NodePath const getProjector ( )

Returns the NodePath to the LensNode that is to serve as the projector for this screen, or empty if no projector is associated.

string getTexcoordName ( )

Returns the name of the texture coordinates that will be generated by this particular ProjectionScreen, as set by set_texcoord_name().

VBase4 const getVignetteColor ( )

Returns the color the screen will be painted at the portions outside of the lens' frustum.

See set_vignette_color().

bool getVignetteOn ( )

Returns true if vertex-based vignetting is on, false otherwise.

See set_vignette_on().

PandaNode makeFlatMesh ( NodePath const  this_np,
NodePath const  camera 
)

Generates a deep copy of the hierarchy at the ProjectionScreen node and below, with vertices flattened into two dimensions as if they were seen by the indicated camera node.

This is useful for rendering an image as seen through a non-linear lens. The resulting mesh will have vertices in the range [-1, 1] in both x and y, and may be then rendered with an ordinary orthographic lens, to generate the effect of seeing the image through the specified non-linear lens.

The returned node has no parent; it is up to the caller to parent it somewhere or store it so that it does not get dereferenced and deleted.

recompute ( )

Recomputes all the UV's for geometry below the ProjectionScreen node, as if the texture were projected from the associated projector.

This function is normally called automatically whenever the relevant properties change, so it should not normally need to be called directly by the user. However, it does no harm to call this if there is any doubt.

regenerateScreen ( NodePath const  projector,
string  screen_name,
int  num_x_verts,
int  num_y_verts,
float  distance,
float  fill_ratio 
)

Removes all the children from the ProjectionScreen node, and adds the newly generated child returned by generate_screen().

setFrameColor ( VBase4 const  frame_color)

Specifies the color the screen will be painted at the portions outside of the lens' frustum; i.e.

where the lens can't see it or illuminate it. This color is only used if the vignette_on flag is true; see set_vignette_on().

setInvertUvs ( bool  invert_uvs)

Some OpenGL graphics drivers are known to invert the framebuffer image when they copy it to texture.

(This is arguably a problem with the OpenGL spec, which seems to be unclear about the proper ordering of pixels in this operation.)

In any case, set this true to compensate for this effect by inverting the UV's of the projection screen. The default is taken from the Configrc variable project-invert-uvs.

setProjector ( NodePath const  projector)

Specifies the LensNode that is to serve as the projector for this screen.

The relative position of the LensNode to the ProjectionScreen, as well as the properties of the lens associated with the LensNode, determines the UV's that will be assigned to the geometry within the ProjectionScreen.

The NodePath must refer to a LensNode (or a Camera).

setTexcoordName ( string  texcoord_name)

Specifies the name of the texture coordinates that are generated by this particular ProjectionScreen.

This can be used in the presence of multitexturing to compute the UV's for just a subset of all of the active stages of the multitexture pipeline.

setVignetteColor ( VBase4 const  vignette_color)

Specifies the color the screen will be painted at the portions outside of the lens' frustum; i.e.

where the lens can't see it or illuminate it. This color is only used if the vignette_on flag is true; see set_vignette_on().

setVignetteOn ( bool  vignette_on)

Specifies whether vertex-based vignetting should be on.

When this is enabled, vertex color will be set on the screen vertices to color the screen two distinct colors, usually white and black, for the parts of the screen in front of and outside the lens' frustum, respectively. When this is not enabled, the screen color will be left alone.

This effect generally looks terrible, but it does at least make the boundaries of the lens clear.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties