Add metallic and roughness scalar attributes to materials.

Rename `light_radius` -> `light_bulbradius`, make the default value 0.02.

PiperOrigin-RevId: 627032170
Change-Id: I1e01e2eca028c0aefc2e7dc384e8b34abac184aa
This commit is contained in:
Yuval Tassa
2024-04-22 07:37:52 -07:00
committed by Copybara-Service
parent c2d0c5dd1b
commit caf215e342
18 changed files with 170 additions and 45 deletions
+1
View File
@@ -2091,6 +2091,7 @@ void mjv_makeLights(const mjModel* m, mjData* d, mjvScene* scn) {
memset(thislight, 0, sizeof(mjvLight));
thislight->directional = m->light_directional[i];
thislight->castshadow = m->light_castshadow[i];
thislight->bulbradius = m->light_bulbradius[i];
if (!thislight->directional) {
f2f(thislight->attenuation, m->light_attenuation+3*i, 3);
thislight->exponent = m->light_exponent[i];
+3 -1
View File
@@ -347,7 +347,6 @@ typedef struct _mjsLight { // light specification
// frame
double pos[3]; // position
double dir[3]; // direction
double radius; // radius
mjtCamLight mode; // tracking mode
mjString targetbody; // target body for targeting
@@ -355,6 +354,7 @@ typedef struct _mjsLight { // light specification
mjtByte active; // is light active
mjtByte directional; // is light directional or spot
mjtByte castshadow; // does light cast shadows
double bulbradius; // bulb radius, for soft shadows
float attenuation[3]; // OpenGL attenuation (quadratic model)
float cutoff; // OpenGL cutoff
float exponent; // OpenGL exponent
@@ -515,6 +515,8 @@ typedef struct _mjsMaterial { // material specification
float specular; // specular
float shininess; // shininess
float reflectance; // reflectance
float metallic; // metallic
float roughness; // roughness
float rgba[4]; // rgba
mjString info; // message appended to compiler errors
} mjsMaterial;
+3
View File
@@ -218,6 +218,7 @@ void mjs_defaultLight(mjsLight& light) {
// intrinsics
light.castshadow = 1;
light.bulbradius = 0.02;
light.active = 1;
light.dir[2] = -1;
light.attenuation[0] = 1;
@@ -305,6 +306,8 @@ void mjs_defaultMaterial(mjsMaterial& material) {
material.specular = 0.5;
material.shininess = 0.5;
material.reflectance = 0;
material.metallic = 1.0;
material.roughness = 1.0;
material.rgba[0] = material.rgba[1] = material.rgba[2] = material.rgba[3] = 1;
}
+3 -1
View File
@@ -2070,7 +2070,7 @@ void mjCModel::CopyTree(mjModel* m) {
m->light_active[lid] = (mjtByte)pl->active;
copyvec(m->light_pos+3*lid, pl->pos, 3);
copyvec(m->light_dir+3*lid, pl->dir, 3);
m->light_radius[lid] = pl->radius;
m->light_bulbradius[lid] = pl->bulbradius;
copyvec(m->light_attenuation+3*lid, pl->attenuation, 3);
m->light_cutoff[lid] = pl->cutoff;
m->light_exponent[lid] = pl->exponent;
@@ -2487,6 +2487,8 @@ void mjCModel::CopyObjects(mjModel* m) {
m->mat_specular[i] = pmat->specular;
m->mat_shininess[i] = pmat->shininess;
m->mat_reflectance[i] = pmat->reflectance;
m->mat_metallic[i] = pmat->metallic;
m->mat_roughness[i] = pmat->roughness;
copyvec(m->mat_rgba+4*i, pmat->rgba, 4);
}
+9 -7
View File
@@ -136,8 +136,8 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"default", "R", "1", "class"},
{"<"},
{"mesh", "?", "1", "scale"},
{"material", "?", "8", "texture", "emission", "specular", "shininess",
"reflectance", "rgba", "texrepeat", "texuniform"},
{"material", "?", "10", "texture", "emission", "specular", "shininess",
"reflectance", "metallic", "roughness", "rgba", "texrepeat", "texuniform"},
{"joint", "?", "22", "type", "group", "pos", "axis", "springdamper",
"limited", "actuatorfrclimited", "solreflimit", "solimplimit",
"solreffriction", "solimpfriction", "stiffness", "range", "actuatorfrcrange",
@@ -153,7 +153,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"camera", "?", "16", "fovy", "ipd", "resolution", "pos", "quat", "axisangle", "xyaxes",
"zaxis", "euler", "mode", "focal", "focalpixel", "principal", "principalpixel",
"sensorsize", "user"},
{"light", "?", "13", "pos", "dir", "radius", "directional", "castshadow", "active",
{"light", "?", "13", "pos", "dir", "bulbradius", "directional", "castshadow", "active",
"attenuation", "cutoff", "exponent", "ambient", "diffuse", "specular", "mode"},
{"pair", "?", "7", "condim", "friction", "solref", "solreffriction", "solimp",
"gap", "margin"},
@@ -232,8 +232,8 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
"fileright", "fileleft", "fileup", "filedown", "filefront", "fileback",
"builtin", "rgb1", "rgb2", "mark", "markrgb", "random", "width", "height",
"hflip", "vflip"},
{"material", "*", "10", "name", "class", "texture", "texrepeat", "texuniform",
"emission", "specular", "shininess", "reflectance", "rgba"},
{"material", "*", "12", "name", "class", "texture", "texrepeat", "texuniform",
"emission", "specular", "shininess", "reflectance", "metallic", "roughness", "rgba"},
{">"},
{"body", "R", "11", "name", "childclass", "pos", "quat", "mocap",
@@ -264,7 +264,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
"axisangle", "xyaxes", "zaxis", "euler", "mode", "target", "focal", "focalpixel",
"principal", "principalpixel", "sensorsize", "user"},
{"light", "*", "16", "name", "class", "directional", "castshadow", "active",
"pos", "dir", "radius", "attenuation", "cutoff", "exponent", "ambient", "diffuse",
"pos", "dir", "bulbradius", "attenuation", "cutoff", "exponent", "ambient", "diffuse",
"specular", "mode", "target"},
{"plugin", "*", "2", "plugin", "instance"},
{"<"},
@@ -1530,6 +1530,8 @@ void mjXReader::OneMaterial(XMLElement* elem, mjsMaterial* pmat) {
ReadAttr(elem, "specular", 1, &pmat->specular, text);
ReadAttr(elem, "shininess", 1, &pmat->shininess, text);
ReadAttr(elem, "reflectance", 1, &pmat->reflectance, text);
ReadAttr(elem, "metallic", 1, &pmat->metallic, text);
ReadAttr(elem, "roughness", 1, &pmat->roughness, text);
ReadAttr(elem, "rgba", 4, pmat->rgba, text);
// write error info
@@ -1783,7 +1785,7 @@ void mjXReader::OneLight(XMLElement* elem, mjsLight* plight) {
}
ReadAttr(elem, "pos", 3, plight->pos, text);
ReadAttr(elem, "dir", 3, plight->dir, text);
ReadAttr(elem, "radius", 1, &plight->radius, text);
ReadAttr(elem, "bulbradius", 1, &plight->bulbradius, text);
ReadAttr(elem, "attenuation", 3, plight->attenuation, text);
ReadAttr(elem, "cutoff", 1, &plight->cutoff, text);
ReadAttr(elem, "exponent", 1, &plight->exponent, text);
+3 -1
View File
@@ -268,6 +268,8 @@ void mjXWriter::OneMaterial(XMLElement* elem, mjCMaterial* pmat, mjCDef* def) {
WriteAttr(elem, "specular", 1, &pmat->specular, &def->material.specular);
WriteAttr(elem, "shininess", 1, &pmat->shininess, &def->material.shininess);
WriteAttr(elem, "reflectance", 1, &pmat->reflectance, &def->material.reflectance);
WriteAttr(elem, "metallic", 1, &pmat->metallic, &def->material.metallic);
WriteAttr(elem, "roughness", 1, &pmat->roughness, &def->material.roughness);
WriteAttr(elem, "rgba", 4, pmat->rgba, def->material.rgba);
}
@@ -508,7 +510,7 @@ void mjXWriter::OneLight(XMLElement* elem, mjCLight* plight, mjCDef* def) {
}
// defaults and regular
WriteAttr(elem, "radius", 1, &plight->radius, &def->light.radius);
WriteAttr(elem, "bulbradius", 1, &plight->bulbradius, &def->light.bulbradius);
WriteAttrKey(elem, "directional", bool_map, 2, plight->directional, def->light.directional);
WriteAttrKey(elem, "castshadow", bool_map, 2, plight->castshadow, def->light.castshadow);
WriteAttrKey(elem, "active", bool_map, 2, plight->active, def->light.active);