vpSetMaterial(3)
π NAME π
okay so welcome to vpSetMaterial(3), straight outta the Library Functions Manual πβ¨ β this one sets material properties. that's the whole vibe. let's go bestie π«Ά
πΈ SYNOPSIS πΈ
#include <volpack.h>
vpResult
vpSetMaterial(vpc, material, property, surface_side, r, g, b)
vpContext *vpc;
int material;
int property;
int surface_side;
double r, g, b;
π ARGUMENTS π
vpcβ the VolPack context you got fromvpCreateContext. your lil home base πmaterialβ a constant that says which material number you're talking about:VP_MATERIAL0,VP_MATERIAL1, ...,VP_MATERIAL5β¨propertyβ a constant naming exactly one material property:VP_AMBIENT,VP_DIFFUSE,VP_SPECULARorVP_SHINYNESSπsurface_sideβ a constant saying which side of the material surface these properties apply to:VP_EXTERIOR,VP_INTERIORorVP_BOTH_SIDESπ¦r,g,bβ the RGB components of the color tied to that property. forVP_SHINYNESS,gandbdo not get used at all β they're just sitting there. iconic but unemployed π
π DESCRIPTION π
vpSetMaterial is how you set the properties of a material type, no cap. every voxel can be a whole mixture of several different material types, which is the tea described over in vpSetLookupShader(3). each material type gets its own color and its own light reflection properties. those properties get fed in as parameters to the Phong shading equation, which computes the color of the material given a set of light sources and a viewing direction β see vpShadeTable(3) π
to initialize the material parameters, you call vpSetMaterial for each property of each material type you're gonna use. the total number of materials is specified as an argument to vpSetLookupShader. first material = the constant VP_MATERIAL0, second = VP_MATERIAL1, and so on, forever, in order π§
VP_AMBIENTβ the RGB ambient light coefficients of the material. this term is the intensity of background light that the material reflects. each of the RGB components is the coefficient for the corresponding light basis function. the coefficient values should be in the range0.0-1.0. Default:0.1VP_DIFFUSEβ the RGB diffuse light coefficients of the material. this term is the fraction of incident light intensity that gets reflected diffusely (think dull, matte energy β the opposite of a glossy mirror moment). the coefficient values should be in the range0.0-1.0. Default:0.4VP_SPECULARβ the RGB specular light coefficients of the material. this term is the fraction of incident light intensity reflected specularly (shiny, mirror-like, main character glow β¨). the coefficient values should be in the range0.0-1.0. Default:0.5VP_SHINYNESSβ a single exponent that modifies the spread of specular highlights. the higher the number, the smaller and more intense those highlights get. the exponent is specified with therargument and can have any value; the generally-useful range is1.0to100.0. thegandbarguments are ignored for this property. Default:10.0
the surface_side argument says which side of the material surface the properties apply to. by default, the "interior" side of a voxel is the side pointing in the direction of the surface normal. during rendering, if the normal points closer to the direction of the viewer than the opposite of the normal, then the viewer is looking at the exterior side of the voxel rather than the interior. you can give the two surface sides totally different material parameters by calling vpSetMaterial separately for each side. the option VP_BOTH_SIDES lets you set the same property for both sides in just one function call β efficient queen π
. and yes, it's possible to reverse the definition of interior and exterior sides by calling vpEnable with the VP_REVERSE_SURFACE_SIDES option π
voxels get shaded using this equation, periodt:
I = A + L * (D * n_dot_l + S * pow(n_dot_h, E))
and here's what each lil letter means:
Iβ intensity for one color channelAβ ambient intensity coefficientDβ diffuse reflection coefficientSβ specular reflection coefficientEβ shinynessLβ light intensityn_dot_lβ dot product of normal and light vectorsn_dot_hβ dot product of normal and highlight vectors
this equation is evaluated separately for each color channel. and if multiple light sources are enabled, an additional term identical to the second term above gets added for each light source (with different values for L, n_dot_l and n_dot_h corresponding to that particular light source). more lights, more terms, more math, we love to see it π₯
π STATE VARIABLES π
you can retrieve info about the current material properties with these state variable codes (see vpGeti(3)): VP_MATERIAL_COUNT, VP_REVERSE_SURFACE_SIDES π
π ERRORS π
the normal return value is VP_OK. the following error return values are possible, and yes they're giving bad news:
VPERROR_BAD_VALUEβ either the material number or the RGB components are invalid πVPERROR_BAD_OPTIONβ either thesurface_sideorpropertyarguments are invalid π
π¦ SEE ALSO π¦
VolPack(3), vpCreateContext(3), vpSetLookupShader(3), vpShadeTable(3), vpGetMaterial(3)
that's the whole page, bestie β brought to you by VolPack, closing out on vpSetMaterial(3) ππβ¨ slay, go set some materials π«Ά
π¦ where this page comes from
- fedora 43: volpack 1.0c7-35.fc43 Β· BSD-3-Clause
- fedora 43: volpack 1.0c7-35.fc43 Β· BSD-3-Clause
- fedora 44: volpack 1.0c7-36.fc44 Β· BSD-3-Clause
- fedora 44: volpack 1.0c7-36.fc44 Β· BSD-3-Clause
- Copyright (c) 1995-2008, Stanford University
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms