Skip to content

Commit

Permalink
debug light positioning, add failsafes on buffer setup
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Apr 23, 2024
1 parent 83a6723 commit 0612dca
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/ar/include/visp3/ar/vpPanda3DBaseRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class VISP_EXPORT vpPanda3DBaseRenderer
void setAbortOnPandaError(bool abort);
void setForcedInvertTextures(bool invert);

static vpPoint vispPointToPanda(const vpPoint &point);
static vpColVector vispPointToPanda(const vpColVector &point);

void printStructure();

Expand Down
26 changes: 22 additions & 4 deletions modules/ar/include/visp3/ar/vpPanda3DLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,44 @@ class VISP_EXPORT vpPanda3DPointLight : public vpPanda3DLight
* @param name name of the light
* @param color color of the light
* @param position Position in the scene of the light. Uses ViSP coordinates.
* @param attenuation Attenuation components of the light as a function of distance.
* Should be a vector of size 3 where the first component is the constant intensity factor (no falloff),
* the second is a linear falloff coefficient, and the last one is the quadratic falloff component.
* To follow the inverse square law, set this value vector to [0, 0, 1]
* To have no falloff, set it to [1, 0, 0].
*/
vpPanda3DPointLight(const std::string &name, const vpRGBf &color, const vpColVector &position) : vpPanda3DLight(name, color), m_position(position)
vpPanda3DPointLight(const std::string &name, const vpRGBf &color, const vpColVector &position, const vpColVector &attenuation)
: vpPanda3DLight(name, color), m_attenuation(attenuation)
{
if (position.size() != 3) {
throw vpException(vpException::dimensionError, "Point light position must be a 3 dimensional vector");
}
m_position.resize(4, false);
m_position.insert(0, position);
m_position[3] = 1.0;
if (attenuation.size() != 3) {
throw vpException(vpException::dimensionError, "Point light attenuation components must be a 3 dimensional vector");
}
}

void addToScene(NodePath &scene) const vp_override
{
PT(PointLight) light = new PointLight(m_name);
light->set_color(LColor(m_color.R, m_color.G, m_color.B, 1));
light->set_attenuation(LVecBase3(m_attenuation[0], m_attenuation[1], m_attenuation[2]));
NodePath np = scene.attach_new_node(light);
vpPoint posPanda = vpPanda3DBaseRenderer::vispPointToPanda(m_position);
np.set_pos(posPanda.get_X(), posPanda.get_Y(), posPanda.get_Z());
vpColVector posPanda = vpPanda3DBaseRenderer::vispPointToPanda(m_position);
np.set_pos(posPanda[0], posPanda[1], posPanda[2]);
std::cout << "posPanda = " << posPanda << std::endl;
std::cout << np.get_pos() << std::endl;
std::cout << scene.get_mat() << std::endl;
std::cout << np.get_mat(scene) << std::endl;
scene.set_light(np);
}

private:
const vpPoint m_position;
vpColVector m_position; //! Position of the light, in homogeneous coordinates
vpColVector m_attenuation; //! Attenuation components: [constant, linear, quadratic]
};

/**
Expand Down
7 changes: 5 additions & 2 deletions modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ void vpPanda3DBaseRenderer::setForcedInvertTextures(bool invert)
}
}

vpPoint vpPanda3DBaseRenderer::vispPointToPanda(const vpPoint &point)
vpColVector vpPanda3DBaseRenderer::vispPointToPanda(const vpColVector &point)
{
return PANDA_T_VISP * point;
vpColVector pandaPos = PANDA_T_VISP * point;
std::cout <<"PANDA POS = " << pandaPos << std::endl;
pandaPos /= pandaPos[3];
return pandaPos;
}

void vpPanda3DBaseRenderer::printStructure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ void vpPanda3DGeometryRenderer::setupScene()

void vpPanda3DGeometryRenderer::setupRenderTarget()
{
if (m_window == nullptr) {
throw vpException(vpException::fatalError, "Cannot setup render target when window is null");
}
FrameBufferProperties fbp;
fbp.set_rgb_color(true);
fbp.set_float_depth(false);
Expand Down Expand Up @@ -160,6 +163,9 @@ void vpPanda3DGeometryRenderer::setupRenderTarget()
m_normalDepthBuffer->set_clear_color(LColor(0.f));
m_normalDepthBuffer->set_clear_color_active(true);
DisplayRegion *region = m_normalDepthBuffer->make_display_region();
if (region == nullptr) {
throw vpException(vpException::fatalError, "Could not create display region");
}
region->set_camera(m_cameraPath);
region->set_clear_color(LColor(0.f));
}
Expand Down
9 changes: 8 additions & 1 deletion modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ void vpPanda3DRGBRenderer::setupScene()
{
vpPanda3DBaseRenderer::setupScene();
setLightableScene(m_renderRoot);
//m_renderRoot.set_shader_auto();
m_renderRoot.set_shader_auto();
}

void vpPanda3DRGBRenderer::setupRenderTarget()
{
if (m_window == nullptr) {
throw vpException(vpException::fatalError, "Cannot setup render target when window is null");
}
FrameBufferProperties fbp;
fbp.set_rgb_color(true);
fbp.set_float_depth(false);
fbp.set_float_color(false);
fbp.set_depth_bits(16);
fbp.set_rgba_bits(8, 8, 8, 8);


WindowProperties win_prop;
win_prop.set_size(m_renderParameters.getImageWidth(), m_renderParameters.getImageHeight());

Expand All @@ -86,6 +90,9 @@ void vpPanda3DRGBRenderer::setupRenderTarget()
m_colorBuffer->set_clear_color(LColor(0.f));
m_colorBuffer->set_clear_color_active(true);
DisplayRegion *region = m_colorBuffer->make_display_region();
if (region == nullptr) {
throw vpException(vpException::fatalError, "Could not create display region");
}
region->set_camera(m_cameraPath);
region->set_clear_color(LColor(0.f));
}
Expand Down
7 changes: 3 additions & 4 deletions tutorial/ar/tutorial-panda3d-renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main(int argc, const char **argv)
else {
modelPath = "data/deformed_sphere.bam";
}
vpPanda3DRenderParameters renderParams(vpCameraParameters(300, 300, 160, 120), 240, 320, 0.01, 1.0);
vpPanda3DRenderParameters renderParams(vpCameraParameters(300, 300, 160, 120), 240, 320, 0.01, 10.0);
vpPanda3DRendererSet renderer(renderParams);
renderer.setRenderParameters(renderParams);

Expand Down Expand Up @@ -106,10 +106,9 @@ int main(int argc, const char **argv)

renderer.addNodeToScene(object);

// rgbRenderer->getRenderRoot().set_shader_auto(100);
vpPanda3DAmbientLight alight("Ambient", vpRGBf(0.2));
renderer.addLight(alight);
vpPanda3DPointLight plight("Point", vpRGBf(2.0), vpColVector({ 0.0, -0.3, -0.0 }));
vpPanda3DPointLight plight("Point", vpRGBf(200.0), vpColVector({ 0.0, 0.0, -5.0 }), vpColVector({ 1.0, 0.0, 0.0 }));
renderer.addLight(plight);

rgbRenderer->printStructure();
Expand Down Expand Up @@ -150,7 +149,7 @@ int main(int argc, const char **argv)
float near = 0, far = 0;
const double beforeComputeBB = vpTime::measureTimeMs();
rgbRenderer->computeNearAndFarPlanesFromNode(objectName, near, far);
renderParams.setClippingDistance(near, far);
// renderParams.setClippingDistance(near, far);
renderer.setRenderParameters(renderParams);
std::cout << "Update clipping plane took " << vpTime::measureTimeMs() - beforeComputeBB << std::endl;

Expand Down

0 comments on commit 0612dca

Please sign in to comment.