-
Notifications
You must be signed in to change notification settings - Fork 20
Material
The appearence of virtual objects, the appearance of the surface, is defined by its material and the lighting in the scene. The material is a set of parameters that define the way to represent the geometry surface.
The basic color parameters are:
- diffuse, essentially the basic color of the material (RGB from 0.0 to 1.0)
- ambient, a color offset not changed by lighting
- specular, the color of specular reflections on a surface
- emissive, TODO
- transparency, a single value from 0.0 (fully transparent) to 1.0 (fully opaque)
Transparency can further be controlled with:
- enableTransparency()
- clearTransparency() - very useful when dealing with transparency glitches ;)
A material can have multiple passes. This means that different sets of material properties can be stacked. An object with that material will be rendered with each pass after the other.
Use addPass() to add a new pass, the new pass will be the active one right away. To switch between passes use setPass(i). Every call on the material will affect the currently active pass.
Sometimes it is necessary to disable depth testing, for example for HUDs or visualizing abstract data.
You can disable depth testing with setDepthTest('GL_ALWAYS')
To change point size and line with use setPointSize( int ) and setLineWidth( int ).
To set the mag and min filtering mode use setMagMinFilter( mag, min ). Typical values are for example:
setMagMinFilter( GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR ) # Texturing uses tri-linear interpolation with mipmaps
setMagMinFilter( GL_LINEAR, GL_LINEAR ) # Texturing uses no mipmapping
setMagMinFilter( GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST ) # Texturing uses no interpolation
The stencil buffer allows to interact between materials during rendering. For example to create outlines or highlight intersections. To use the stencil buffer call
setStencilBuffer(doClear, value, mask, func, opFail, opZFail, opPass)
The first flag tells the rendering to clear the entire buffer to 0 before starting to render the material. The value and mask are used for the test, the mask is ANDed with the value as well as the stored buffer value. The test function can be GL_NEVER, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL, GL_EQUAL, GL_NOTEQUAL, or GL_ALWAYS. opFail is the action taken when stencil test fails, opZFail when stencil test passes but depth test fails, and opPass if both tests pass. The possible actions are: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_INCR_WRAP, GL_DECR, GL_DECR_WRAP, and GL_INVERT.
Use setSortKey
or add additional passes to control the order in witch the materials are rendered.
Set shader parameters using setShaderParameter(name, value)
.
The value can be an integer, float, or 2D/3D/4D vector.
Once a name has been associated with a type you will not be able to change it, so avoid inconsistent calls, using a name with different variable types.
PolyVR can generate a QR code on texture, setQRCode( message, fg color, bg color, padding )