Merge pull request #3387 from bd-pmorais:pmorais/renderer-live-mat-texid
PiperOrigin-RevId: 949427127 Change-Id: I607af41aefdefd6d22602889e6982d64df8b380b
This commit is contained in:
@@ -241,6 +241,10 @@ static void setMaterial(const mjModel* m, mjvGeom* geom, int matid, const float*
|
||||
// set texture
|
||||
if (flags[mjVIS_TEXTURE] && matid >= 0) {
|
||||
geom->matid = matid;
|
||||
geom->texid = m->mat_texid[matid*mjNTEXROLE + mjTEXROLE_RGB];
|
||||
geom->texuniform = m->mat_texuniform[matid];
|
||||
geom->texrepeat[0] = m->mat_texrepeat[2*matid];
|
||||
geom->texrepeat[1] = m->mat_texrepeat[2*matid+1];
|
||||
}
|
||||
|
||||
// scale alpha for dynamic geoms only
|
||||
@@ -379,6 +383,10 @@ void mjv_initGeom(mjvGeom* geom, int type, const mjtNum* size,
|
||||
// set defaults that cannot be assigned via this function
|
||||
geom->dataid = -1;
|
||||
geom->matid = -1;
|
||||
geom->texid = -1;
|
||||
geom->texuniform = 0;
|
||||
geom->texrepeat[0] = 0;
|
||||
geom->texrepeat[1] = 0;
|
||||
geom->texcoord = 0;
|
||||
geom->emission = 0;
|
||||
geom->specular = 0.5;
|
||||
|
||||
@@ -174,6 +174,9 @@ static void UpdateGeomMaterial(mjrfRenderable* renderable, const mjvGeom& geom,
|
||||
material.roughness_texture = get_texture(mjTEXROLE_ROUGHNESS);
|
||||
material.occlusion_texture = get_texture(mjTEXROLE_OCCLUSION);
|
||||
}
|
||||
if (geom.texid >= 0) {
|
||||
material.color_texture = model_objs->GetTexture(geom.texid);
|
||||
}
|
||||
|
||||
material.reflectance = geom.reflectance;
|
||||
material.emissive = geom.emission;
|
||||
@@ -200,14 +203,21 @@ static void UpdateGeomMaterial(mjrfRenderable* renderable, const mjvGeom& geom,
|
||||
// the programmatic UVs.
|
||||
|
||||
if (material.color_texture) {
|
||||
const bool tex_uniform = model->mat_texuniform[geom.matid];
|
||||
bool tex_uniform;
|
||||
float tex_repeat[2];
|
||||
if (geom.texid >= 0) {
|
||||
tex_uniform = geom.texuniform;
|
||||
tex_repeat[0] = geom.texrepeat[0];
|
||||
tex_repeat[1] = geom.texrepeat[1];
|
||||
} else {
|
||||
tex_uniform = model->mat_texuniform[geom.matid];
|
||||
tex_repeat[0] = model->mat_texrepeat[(geom.matid * 2) + 0];
|
||||
tex_repeat[1] = model->mat_texrepeat[(geom.matid * 2) + 1];
|
||||
}
|
||||
if (mjrf_getTextureSamplerType(material.color_texture) == mjTEXTURE_2D) {
|
||||
// For 2D textures, `tex_repeat` specifies how many times the texture
|
||||
// image is repeated. The `tex_uniform` flag determines if the repetition
|
||||
// is applied at in object space (false) or in world space (true).
|
||||
float tex_repeat[2];
|
||||
tex_repeat[0] = model->mat_texrepeat[(geom.matid * 2) + 0];
|
||||
tex_repeat[1] = model->mat_texrepeat[(geom.matid * 2) + 1];
|
||||
material.uv_scale[0] = tex_repeat[0];
|
||||
material.uv_scale[1] = tex_repeat[1];
|
||||
|
||||
|
||||
@@ -61,10 +61,19 @@ enum {
|
||||
// enable/disable texture mapping
|
||||
static void settexture(int type, int state, const mjrContext* con, const mjvGeom* geom) {
|
||||
float plane[4], scl[2];
|
||||
int texid = -1;
|
||||
int texid = -1, texuniform = 0;
|
||||
float texrepeat[2] = {0, 0};
|
||||
if (geom) {
|
||||
if (geom->matid >= 0) {
|
||||
if (geom->texid >= 0) {
|
||||
texid = geom->texid;
|
||||
texuniform = geom->texuniform;
|
||||
texrepeat[0] = geom->texrepeat[0];
|
||||
texrepeat[1] = geom->texrepeat[1];
|
||||
} else if (geom->matid >= 0) {
|
||||
texid = con->mat_texid[mjNTEXROLE * geom->matid + mjTEXROLE_RGB];
|
||||
texuniform = con->mat_texuniform[geom->matid];
|
||||
texrepeat[0] = con->mat_texrepeat[geom->matid*2];
|
||||
texrepeat[1] = con->mat_texrepeat[geom->matid*2+1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +128,8 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
|
||||
glBindTexture(GL_TEXTURE_2D, con->texture[texid]);
|
||||
|
||||
// determine scaling, adjust for pre-scaled geoms
|
||||
scl[0] = con->mat_texrepeat[geom->matid*2];
|
||||
scl[1] = con->mat_texrepeat[geom->matid*2+1];
|
||||
scl[0] = texrepeat[0];
|
||||
scl[1] = texrepeat[1];
|
||||
if (geom->dataid >= 0) {
|
||||
if (geom->size[0] > 0) {
|
||||
scl[0] = scl[0] / mju_max(mjMINVAL, geom->size[0]);
|
||||
@@ -132,7 +141,7 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
|
||||
}
|
||||
|
||||
// uniform: repeat relative to spatial units rather than object
|
||||
if (con->mat_texuniform[geom->matid]) {
|
||||
if (texuniform) {
|
||||
if (geom->size[0] > 0) {
|
||||
scl[0] = scl[0] * geom->size[0];
|
||||
}
|
||||
@@ -171,11 +180,11 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom
|
||||
|
||||
// set mapping : cube
|
||||
if (type == mjtexREGULAR) {
|
||||
mjr_setf4(plane, con->mat_texuniform[geom->matid] ? geom->size[0] : 1, 0, 0, 0);
|
||||
mjr_setf4(plane, texuniform ? geom->size[0] : 1, 0, 0, 0);
|
||||
glTexGenfv(GL_S, GL_OBJECT_PLANE, plane);
|
||||
mjr_setf4(plane, 0, con->mat_texuniform[geom->matid] ? geom->size[1] : 1, 0, 0);
|
||||
mjr_setf4(plane, 0, texuniform ? geom->size[1] : 1, 0, 0);
|
||||
glTexGenfv(GL_T, GL_OBJECT_PLANE, plane);
|
||||
mjr_setf4(plane, 0, 0, con->mat_texuniform[geom->matid] ? geom->size[2] : 1, 0);
|
||||
mjr_setf4(plane, 0, 0, texuniform ? geom->size[2] : 1, 0);
|
||||
glTexGenfv(GL_R, GL_OBJECT_PLANE, plane);
|
||||
}
|
||||
|
||||
@@ -1317,7 +1326,7 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
||||
if (con->textureType[i] == mjTEXTURE_SKYBOX) {
|
||||
// save first skybox texture id in tempgeom
|
||||
memset(&tempgeom, 0, sizeof(mjvGeom));
|
||||
tempgeom.matid = mjMAXMATERIAL - 1;
|
||||
tempgeom.texid = i;
|
||||
|
||||
// modify settings
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
Reference in New Issue
Block a user