Fix rendering of reflection for transparent geoms.
PiperOrigin-RevId: 462589429 Change-Id: Ibda2d2b83cb43804644fecfe3a1e2a8496f3de56
This commit is contained in:
committed by
Copybara-Service
parent
b849023069
commit
95b6327bb5
+47
-14
@@ -450,6 +450,27 @@ static void renderGeom(const mjvGeom* geom, int mode, const float* headpos,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void renderGeomReflection(int id, float reflectance, float headpos[3],
|
||||||
|
mjvScene* scn, const mjrContext* con) {
|
||||||
|
float old_rgb[3];
|
||||||
|
|
||||||
|
// save rgb, modulate rgb by this->reflectance
|
||||||
|
for (int k=0; k<3; k++) {
|
||||||
|
old_rgb[k] = scn->geoms[id].rgba[k];
|
||||||
|
scn->geoms[id].rgba[k] *= reflectance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// render
|
||||||
|
renderGeom(scn->geoms+id, mjrRND_NORMAL, headpos, scn, con);
|
||||||
|
|
||||||
|
// restore rgb
|
||||||
|
for (int k=0; k<3; k++) {
|
||||||
|
scn->geoms[id].rgba[k] = old_rgb[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------- high-level 3D rendering --------------------------------------------
|
//----------------------------- high-level 3D rendering --------------------------------------------
|
||||||
|
|
||||||
// init, with or without special effects
|
// init, with or without special effects
|
||||||
@@ -890,23 +911,35 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
|||||||
glEnable(GL_LIGHT0+j);
|
glEnable(GL_LIGHT0+j);
|
||||||
}
|
}
|
||||||
|
|
||||||
// render reflected scene except for thisgeom
|
// render reflected non-transparent geoms, except for thisgeom
|
||||||
for (int j=0; j<ngeom; j++)
|
for (int j=0; j<ngeom; j++) {
|
||||||
if (i!=j) {
|
if (!scn->geoms[j].transparent && i!=j) {
|
||||||
// save rgb, modulate rgb by this->reflectance
|
renderGeomReflection(j, thisgeom->reflectance, headpos, scn, con);
|
||||||
for (int k=0; k<3; k++) {
|
}
|
||||||
temp[k] = scn->geoms[j].rgba[k];
|
}
|
||||||
scn->geoms[j].rgba[k] *= thisgeom->reflectance;
|
|
||||||
}
|
|
||||||
|
|
||||||
// render
|
// render reflected transparent geoms, except for thisgeom
|
||||||
renderGeom(scn->geoms+j, mjrRND_NORMAL, headpos, scn, con);
|
glDepthMask(GL_FALSE);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
// restore rgb
|
if (scn->flags[mjRND_ADDITIVE]) {
|
||||||
for (int k=0; k<3; k++) {
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||||
scn->geoms[j].rgba[k] = temp[k];
|
} else {
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
|
for (int j=0; j<nt; j++) {
|
||||||
|
if (i!=scn->geomorder[j]) {
|
||||||
|
renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!scn->flags[mjRND_ADDITIVE]) {
|
||||||
|
for (int j=nt-1; j>=0; j--) {
|
||||||
|
if (i!=scn->geomorder[j]) {
|
||||||
|
renderGeomReflection(scn->geomorder[j], thisgeom->reflectance, headpos, scn, con);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
// disable lights
|
// disable lights
|
||||||
for (int j=0; j<nlight; j++) {
|
for (int j=0; j<nlight; j++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user