Move headlight pos/dir computation from mjr_render to mjv_updateScene.
PiperOrigin-RevId: 586630110 Change-Id: Ia44ea944016ccfe081682375cdb975342695d826
This commit is contained in:
committed by
Copybara-Service
parent
822b03446c
commit
b39cca725a
@@ -241,12 +241,12 @@ int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt
|
|||||||
// add all categories
|
// add all categories
|
||||||
mjv_addGeoms(&m, &d, opt, pert, catmask, scn);
|
mjv_addGeoms(&m, &d, opt, pert, catmask, scn);
|
||||||
|
|
||||||
// add lights
|
|
||||||
mjv_makeLights(&m, &d, scn);
|
|
||||||
|
|
||||||
// update camera
|
// update camera
|
||||||
mjv_updateCamera(&m, &d, cam, scn);
|
mjv_updateCamera(&m, &d, cam, scn);
|
||||||
|
|
||||||
|
// add lights
|
||||||
|
mjv_makeLights(&m, &d, scn);
|
||||||
|
|
||||||
// update flexes
|
// update flexes
|
||||||
if (opt->flags[mjVIS_FLEXVERT] || opt->flags[mjVIS_FLEXEDGE] ||
|
if (opt->flags[mjVIS_FLEXVERT] || opt->flags[mjVIS_FLEXEDGE] ||
|
||||||
opt->flags[mjVIS_FLEXFACE] || opt->flags[mjVIS_FLEXSKIN]) {
|
opt->flags[mjVIS_FLEXFACE] || opt->flags[mjVIS_FLEXSKIN]) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "engine/engine_util_misc.h"
|
#include "engine/engine_util_misc.h"
|
||||||
#include "engine/engine_util_spatial.h"
|
#include "engine/engine_util_spatial.h"
|
||||||
#include "engine/engine_vis_init.h"
|
#include "engine/engine_vis_init.h"
|
||||||
|
#include "engine/engine_vis_interact.h"
|
||||||
|
|
||||||
//----------------------------- utility functions and macros ---------------------------------------
|
//----------------------------- utility functions and macros ---------------------------------------
|
||||||
|
|
||||||
@@ -2087,6 +2088,12 @@ void mjv_makeLights(const mjModel* m, mjData* d, mjvScene* scn) {
|
|||||||
thislight->directional = 1;
|
thislight->directional = 1;
|
||||||
thislight->castshadow = 0;
|
thislight->castshadow = 0;
|
||||||
|
|
||||||
|
// compute head position and gaze direction in model space
|
||||||
|
mjtNum hpos[3], hfwd[3];
|
||||||
|
mjv_cameraInModel(hpos, hfwd, NULL, scn);
|
||||||
|
mju_n2f(thislight->pos, hpos, 3);
|
||||||
|
mju_n2f(thislight->dir, hfwd, 3);
|
||||||
|
|
||||||
// copy colors
|
// copy colors
|
||||||
f2f(thislight->ambient, m->vis.headlight.ambient, 3);
|
f2f(thislight->ambient, m->vis.headlight.ambient, 3);
|
||||||
f2f(thislight->diffuse, m->vis.headlight.diffuse, 3);
|
f2f(thislight->diffuse, m->vis.headlight.diffuse, 3);
|
||||||
@@ -2723,12 +2730,12 @@ void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt,
|
|||||||
// add all categories
|
// add all categories
|
||||||
mjv_addGeoms(m, d, opt, pert, catmask, scn);
|
mjv_addGeoms(m, d, opt, pert, catmask, scn);
|
||||||
|
|
||||||
// add lights
|
|
||||||
mjv_makeLights(m, d, scn);
|
|
||||||
|
|
||||||
// update camera
|
// update camera
|
||||||
mjv_updateCamera(m, d, cam, scn);
|
mjv_updateCamera(m, d, cam, scn);
|
||||||
|
|
||||||
|
// add lights
|
||||||
|
mjv_makeLights(m, d, scn);
|
||||||
|
|
||||||
// update flexes
|
// update flexes
|
||||||
if (opt->flags[mjVIS_FLEXVERT] || opt->flags[mjVIS_FLEXEDGE] ||
|
if (opt->flags[mjVIS_FLEXVERT] || opt->flags[mjVIS_FLEXEDGE] ||
|
||||||
opt->flags[mjVIS_FLEXFACE] || opt->flags[mjVIS_FLEXSKIN]) {
|
opt->flags[mjVIS_FLEXFACE] || opt->flags[mjVIS_FLEXSKIN]) {
|
||||||
|
|||||||
+8
-17
@@ -613,7 +613,7 @@ static void initGL3(const mjvScene* scn, const mjrContext* con) {
|
|||||||
|
|
||||||
|
|
||||||
// init lights
|
// init lights
|
||||||
static void initLights(mjvScene* scn, const float* headpos, const float* gazedir) {
|
static void initLights(mjvScene* scn) {
|
||||||
// create some ambient light if no ligths are present
|
// create some ambient light if no ligths are present
|
||||||
float global = scn->nlight ? 0 : 0.3f;
|
float global = scn->nlight ? 0 : 0.3f;
|
||||||
float rgba_global[4] = {global, global, global, 1};
|
float rgba_global[4] = {global, global, global, 1};
|
||||||
@@ -623,14 +623,6 @@ static void initLights(mjvScene* scn, const float* headpos, const float* gazedir
|
|||||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
|
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
|
||||||
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
|
||||||
|
|
||||||
// headlight: set pos and dir
|
|
||||||
if (scn->lights[0].headlight) {
|
|
||||||
for (int i=0; i < 3; i++) {
|
|
||||||
scn->lights[0].pos[i] = headpos[i];
|
|
||||||
scn->lights[0].dir[i] = gazedir[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set light properties
|
// set light properties
|
||||||
for (int i=0; i < scn->nlight; i++) {
|
for (int i=0; i < scn->nlight; i++) {
|
||||||
// colors
|
// colors
|
||||||
@@ -762,8 +754,8 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
|||||||
int stereo, nt, ngeom = scn->ngeom, nlight = mjMIN(mjMAXLIGHT, scn->nlight);
|
int stereo, nt, ngeom = scn->ngeom, nlight = mjMIN(mjMAXLIGHT, scn->nlight);
|
||||||
unsigned int drawbuffer;
|
unsigned int drawbuffer;
|
||||||
mjvGLCamera cam;
|
mjvGLCamera cam;
|
||||||
mjtNum hpos[3], hfwd[3];
|
mjtNum hpos[3];
|
||||||
float temp[4], headpos[3], forward[3], skyboxdst;
|
float temp[4], headpos[3], skyboxdst;
|
||||||
float camProject[16], camView[16], lightProject[16], lightView[16];
|
float camProject[16], camView[16], lightProject[16], lightView[16];
|
||||||
double clipplane[4];
|
double clipplane[4];
|
||||||
float biasMatrix[16] = {
|
float biasMatrix[16] = {
|
||||||
@@ -827,13 +819,12 @@ void mjr_render(mjrRect viewport, mjvScene* scn, const mjrContext* con) {
|
|||||||
drawbuffer = GL_COLOR_ATTACHMENT0;
|
drawbuffer = GL_COLOR_ATTACHMENT0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute head position and gaze direction in model space
|
|
||||||
mjv_cameraInModel(hpos, hfwd, NULL, scn);
|
|
||||||
mju_n2f(headpos, hpos, 3);
|
|
||||||
mju_n2f(forward, hfwd, 3);
|
|
||||||
|
|
||||||
// init lights
|
// init lights
|
||||||
initLights(scn, headpos, forward);
|
initLights(scn);
|
||||||
|
|
||||||
|
// compute head position in model space
|
||||||
|
mjv_cameraInModel(hpos, NULL, NULL, scn);
|
||||||
|
mju_n2f(headpos, hpos, 3);
|
||||||
|
|
||||||
// make list of transparent geoms
|
// make list of transparent geoms
|
||||||
nt = 0;
|
nt = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user