ProjectionScreen

class ProjectionScreen

Bases: PandaNode

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.

Inheritance diagram

Inheritance diagram of ProjectionScreen

explicit ProjectionScreen(std::string const &name = "")
void clear_undist_lut(void)

Removes the distortion lookup table from the projector, if specified.

PointerTo<GeomNode> generate_screen(NodePath const &projector, std::string const &screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat 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.

bool get_auto_recompute(void) const

Returns the auto_recompute flag. When this is true, the ProjectionScreen will always be recomputed if necessary before the frame is drawn; when it is false, an explicit call to recompute_if_stale() may be required.

static TypeHandle get_class_type(void)
LColor const &get_frame_color(void) const

Returns the color the screen will be painted at the portions outside of the lens’ frustum. See set_frame_color().

bool get_invert_uvs(void) const

Returns whether this screen is compensating for a graphics driver inverting the framebuffer image. See set_invert_uvs().

UpdateSeq const &get_last_screen(void) const

Returns an UpdateSeq corresponding to the last time a screen mesh was generated for the ProjectionScreen. Each time generate_screen() is called, this number is incremented; this allows other objects (like NonlinearImager) to know when they need to recompute themselves.

NodePath const &get_projector(void) const

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

bool get_texcoord_3d(void) const

See set_texcoord_3d().

std::string get_texcoord_name(void) const

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

PfmFile const &get_undist_lut(void) const

Returns the distortion lookup table provided via set_undist_lut(), if any.

LColor const &get_vignette_color(void) const

Returns the color the screen will be painted at the portions outside of the lens’ frustum. See set_vignette_color().

bool get_vignette_on(void) const

Returns true if vertex-based vignetting is on, false otherwise. See set_vignette_on().

bool has_undist_lut(void) const

Returns true if a valid distortion lookup table was provided via set_undist_lut(), false otherwise.

PointerTo<PandaNode> make_flat_mesh(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.

void recompute(void)

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.

bool recompute_if_stale(void)
bool recompute_if_stale(NodePath const &this_np)

Calls recompute() only if the relative transform between the ProjectionScreen and the projector has changed, or if any other relevant property has changed. Returns true if recomputed, false otherwise.

void regenerate_screen(NodePath const &projector, std::string const &screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat fill_ratio)

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

void set_auto_recompute(bool auto_recompute)

Sets the auto_recompute flag. When this is true, the ProjectionScreen will always be recomputed if necessary before the frame is drawn; when it is false, an explicit call to recompute_if_stale() may be required.

void set_frame_color(LColor 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().

void set_invert_uvs(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.

void set_projector(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).

void set_texcoord_3d(bool texcoord_3d)

Set this true to force 3-D texture coordinates to be created for the geometry. When this is true and the geometry has only 2-D texture coordinates, those texture coordinates are dumped in favor of 3-D coordinates. When this is false, whatever texture coordinates already exist are preserved as-is.

void set_texcoord_name(std::string const &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.

void set_undist_lut(PfmFile const &undist_lut)

Applies a distortion lookup table to the projector. This mapping warps the lens effect by passing each ray through an indirection table: the point (u,v) in the indicated lookup table stores the actual (u,v) that the lens produces.

This does not affect the operation of generate_screen().

void set_vignette_color(LColor 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().

void set_vignette_on(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.