Set material properties for geometry appearance.

rgl.material(
color        = "white",
alpha        = 1.0,
lit          = TRUE,
ambient      = "black",
specular     = "white",
emission     = "black",
shininess    = 50.0,
smooth       = TRUE,
texture      = NULL,
textype      = "rgb",
texmipmap    = FALSE,
texminfilter = "linear",
texmagfilter = "linear",
texenvmap    = FALSE,
front        = "fill",
back         = "fill",
size         = 3.0,
lwd          = 1.0,
fog          = TRUE,
point_antialias = FALSE,
line_antialias = FALSE,
depth_test   = "less",
polygon_offset = c(0.0, 0.0),
margin       = "",
floating     = FALSE,
...
)
material3d(...)

## Arguments

color vector of R color characters. Represents the diffuse component in case of lighting calculation (lit = TRUE), otherwise it describes the solid color characteristics. logical, specifying if lighting calculation should take place on geometry properties for lighting calculation. ambient, specular, emission are R color character string values; shininess represents a numerical. vector of alpha values between 0.0 (fully transparent) .. 1.0 (opaque). logical, specifying whether Gouraud shading (smooth) or flat shading should be used. path to a texture image file. Supported formats: png. specifies what is defined with the pixmap "alpha"alpha values "luminance"luminance "luminance.alpha"luminance and alpha "rgb"color "rgba"color and alpha texture Logical, specifies if the texture should be mipmapped. specifies the magnification filtering type (sorted by ascending quality): "nearest"texel nearest to the center of the pixel "linear"weighted linear average of a 2x2 array of texels specifies the minification filtering type (sorted by ascending quality): "nearest"texel nearest to the center of the pixel "linear"weighted linear average of a 2x2 array of texels "nearest.mipmap.nearest"low quality mipmapping "nearest.mipmap.linear"medium quality mipmapping "linear.mipmap.nearest"medium quality mipmapping "linear.mipmap.linear"high quality mipmapping logical, specifies if auto-generated texture coordinates for environment-mapping should be performed on geometry. Determines the polygon mode for the specified side: "filled"filled polygon "lines"wireframed polygon "points"point polygon "culled"culled (hidden) polygon numeric, specifying the size of points in pixels numeric, specifying the line width in pixels logical, specifying if fog effect should be applied on the corresponding shape. Fog type is set in bg3d. logical, specifying if points should be round and lines should be antialiased, but see Note below. logical, specifying whether the object's depth should be stored. Determines which depth test is used to see if this object is visible, depending on its apparent depth in the scene compared to the stored depth. Possible values are "never", "less" (the default), "equal", "lequal" (less than or equal), "greater", "notequal", "gequal" (greater than or equal), "always". If non-zero, offsets are added to the recorded depth of filled polygons. See Details below. Used mainly for text to draw annotations in the margins, but supported by most kinds of objects: see mtext3d. Any of the arguments above can be passed to material3d; see Details below. rgl.material will ignore others.

## Details

Values can be queried by specifying their names in a character vector, e.g. material3d("color"). There is one read-only property that can be queried but not set:

isTransparent

Is the current color transparent?

Only one side at a time can be culled.

Object display colors are determined as follows:

• If lit = FALSE, an element of the color vector property is displayed without modification. See documentation for individual objects for information on which element is chosen.

• If lit = TRUE, the color is determined as follows.

1. The color is set to the emission property of the object.

2. For each defined light, the following are added:

• the product of the ambient color of the light and the ambient color of the object is added.

• the color of the object is multiplied by the diffuse color of the light and by a constant depending on the angle between the surface and the direction to the light, and added.

• the specular color of the object is multiplied by the specular color of the light and a constant depending on the shininess of the object and the direction to the light, and added. The shininess property mainly determines the size of the shiny highlight; adjust one or both of the specular colors to change its brightness.

The polygon_offset property is a two element vector giving the factor and units values to use in a glPolygonOffset() call in OpenGL. If only one value is given, it is used for both elements. The units value is added to the depth of all pixels in a filled polygon, and the factor value is multiplied by an estimate of the slope of the polygon and then added to the depth. Positive values “push” polygons back slightly for the purpose of depth testing, to allow points, lines or other polygons to be drawn on the surface without being obscured due to rounding error. Negative values pull the object forward. A typical value to use is 1 (which is automatically expanded to c(1,1)). If values are too large, objects which should be behind the polygon will show through, and if values are too small, the objects on the surface will be partially obscured. Experimentation may be needed to get it right. The first example in ?persp3d uses this property to add grid lines to a surface.

material3d is an alternate interface to the material properties, modelled after par3d: rather than setting defaults for parameters that are not specified, they will be left unchanged. material3d may also be used to query the material properties; see the examples below.

The current implementation does not return parameters for textures.

The material member of the r3dDefaults list may be used to set default values for material properties.

The ... parameter to rgl.material is ignored.

## Value

rgl.material() is called for the side effect of setting the material properties. It returns a value invisibly which is not intended for use by the user.

Users should use material3d() to query material properties. It returns values similarly to par3d as follows: When setting properties, it returns the previous values in a named list. A named list is also returned when more than one value is queried. When a single value is queried it is returned directly.

## Note

If point_antialias is TRUE, points will be drawn as circles in WebGL; otherwise, they will be drawn as squares. Within R, the behaviour depends on your graphics hardware: for example, I see circles for both settings on my laptop.

Within R, lines tend to appear heavier with line_antialias == TRUE. There's no difference at all in WebGL.

rgl.primitive, rgl.bbox, rgl.bg, rgl.light

## Examples

save <- material3d("color")
material3d(color = "red")
material3d("color")
#> [1] "#FF0000"
material3d(color = save)

# this illustrates the effect of depth_test
x <- c(1:3); xmid <- mean(x)
y <- c(2, 1, 3); ymid <- mean(y)
z <- 1
open3d()
tests <- c("never", "less", "equal", "lequal", "greater",
"notequal", "gequal", "always")
for (i in 1:8) {
triangles3d(x, y, z + i, col = heat.colors(8)[i])
texts3d(xmid, ymid, z + i, paste(i, tests[i], sep = ". "), depth_test = tests[i])
}
highlevel()  # To trigger display

{"x":{"material":{"color":"#000000","alpha":1,"lit":true,"ambient":"#000000","specular":"#FFFFFF","emission":"#000000","shininess":50,"smooth":true,"front":"filled","back":"filled","size":3,"lwd":1,"fog":true,"point_antialias":false,"line_antialias":false,"texture":null,"textype":"rgb","texmipmap":false,"texminfilter":"linear","texmagfilter":"linear","texenvmap":false,"depth_mask":true,"depth_test":"less","isTransparent":false,"polygon_offset":[0,0],"margin":"","floating":false},"rootSubscene":643,"objects":{"649":{"id":649,"type":"triangles","material":{},"vertices":[[1,2,2],[2,1,2],[3,3,2]],"colors":[[1,0,0,1]],"centers":[[2,2,2]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"650":{"id":650,"type":"text","material":{"lit":false,"depth_test":"never"},"vertices":[[2,2,2]],"colors":[[0,0,0,1]],"texts":[["1. never"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,2]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"651":{"id":651,"type":"triangles","material":{},"vertices":[[1,2,3],[2,1,3],[3,3,3]],"colors":[[1,0.200000002980232,0,1]],"centers":[[2,2,3]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"652":{"id":652,"type":"text","material":{"lit":false},"vertices":[[2,2,3]],"colors":[[0,0,0,1]],"texts":[["2. less"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,3]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"653":{"id":653,"type":"triangles","material":{},"vertices":[[1,2,4],[2,1,4],[3,3,4]],"colors":[[1,0.400000005960464,0,1]],"centers":[[2,2,4]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"654":{"id":654,"type":"text","material":{"lit":false,"depth_test":"equal"},"vertices":[[2,2,4]],"colors":[[0,0,0,1]],"texts":[["3. equal"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,4]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"655":{"id":655,"type":"triangles","material":{},"vertices":[[1,2,5],[2,1,5],[3,3,5]],"colors":[[1,0.600000023841858,0,1]],"centers":[[2,2,5]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"656":{"id":656,"type":"text","material":{"lit":false,"depth_test":"lequal"},"vertices":[[2,2,5]],"colors":[[0,0,0,1]],"texts":[["4. lequal"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,5]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"657":{"id":657,"type":"triangles","material":{},"vertices":[[1,2,6],[2,1,6],[3,3,6]],"colors":[[1,0.800000011920929,0,1]],"centers":[[2,2,6]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"658":{"id":658,"type":"text","material":{"lit":false,"depth_test":"greater"},"vertices":[[2,2,6]],"colors":[[0,0,0,1]],"texts":[["5. greater"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,6]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"659":{"id":659,"type":"triangles","material":{},"vertices":[[1,2,7],[2,1,7],[3,3,7]],"colors":[[1,1,0,1]],"centers":[[2,2,7]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"660":{"id":660,"type":"text","material":{"lit":false,"depth_test":"notequal"},"vertices":[[2,2,7]],"colors":[[0,0,0,1]],"texts":[["6. notequal"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,7]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"661":{"id":661,"type":"triangles","material":{},"vertices":[[1,2,8],[2,1,8],[3,3,8]],"colors":[[1,1,0.250980406999588,1]],"centers":[[2,2,8]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"662":{"id":662,"type":"text","material":{"lit":false,"depth_test":"gequal"},"vertices":[[2,2,8]],"colors":[[0,0,0,1]],"texts":[["7. gequal"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,8]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"663":{"id":663,"type":"triangles","material":{},"vertices":[[1,2,9],[2,1,9],[3,3,9]],"colors":[[1,1,0.749019622802734,1]],"centers":[[2,2,9]],"normals":[[0,-0,1],[0,-0,1],[0,-0,1]],"ignoreExtent":false,"flags":32771},"664":{"id":664,"type":"text","material":{"lit":false,"depth_test":"always"},"vertices":[[2,2,9]],"colors":[[0,0,0,1]],"texts":[["8. always"]],"cex":[[1]],"adj":[[0.5,0.5,0.5]],"centers":[[2,2,9]],"family":[["sans"]],"font":[[1]],"ignoreExtent":false,"flags":33808},"647":{"id":647,"type":"light","vertices":[[0,0,1]],"colors":[[1,1,1,1],[1,1,1,1],[1,1,1,1]],"viewpoint":true,"finite":false},"646":{"id":646,"type":"background","material":{},"colors":[[0.298039227724075,0.298039227724075,0.298039227724075,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"648":{"id":648,"type":"background","material":{"lit":false,"back":"lines"},"colors":[[1,1,1,1]],"centers":[[0,0,0]],"sphere":false,"fogtype":"none","fogscale":1,"flags":32768},"643":{"id":643,"type":"subscene","par3d":{"antialias":8,"FOV":30,"ignoreExtent":false,"listeners":643,"mouseMode":{"none":"none","left":"trackball","right":"zoom","middle":"fov","wheel":"pull"},"observer":[0,0,14.5851602554321],"modelMatrix":[[1,0,0,-2],[0,0.342020153999329,0.939692616462708,-5.85234928131104],[0,-0.939692616462708,0.342020153999329,-14.5868854522705],[0,0,0,1]],"projMatrix":[[3.73205089569092,0,0,0],[0,3.73205089569092,0,0],[0,0,-3.86370396614075,-52.577823638916],[0,0,-1,0]],"skipRedraw":false,"userMatrix":[[1,0,0,0],[0,0.342020143325668,0.939692620785909,0],[0,-0.939692620785909,0.342020143325668,0],[0,0,0,1]],"userProjection":[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],"scale":[1,1,1],"viewport":{"x":0,"y":0,"width":1,"height":1},"zoom":1,"bbox":[1,3,1,3,2,9],"windowRect":[0,0,256,256],"family":"sans","font":1,"cex":1,"useFreeType":true,"fontname":"NULL","maxClipPlanes":2147483647,"glVersion":"NA","activeSubscene":0},"embeddings":{"viewport":"replace","projection":"replace","model":"replace","mouse":"replace"},"objects":[648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,647],"subscenes":[],"flags":34067}},"crosstalk":{"key":[],"group":[],"id":[],"options":[]},"width":480,"height":480,"context":{"shiny":false,"rmarkdown":null},"players":[],"webGLoptions":{"preserveDrawingBuffer":true}},"evals":[],"jsHooks":[]}