Skip to content

Commit

Permalink
Start work on RGB shader
Browse files Browse the repository at this point in the history
  • Loading branch information
SamFlt committed Apr 26, 2024
1 parent 36713ca commit d16a322
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
3 changes: 3 additions & 0 deletions modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp
private:
Texture *m_colorTexture;
GraphicsOutput *m_colorBuffer;
static const char* COOK_TORRANCE_VERT;
static const char* COOK_TORRANCE_FRAG;


};

Expand Down
2 changes: 1 addition & 1 deletion modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void vpPanda3DBaseRenderer::initFramework()
setupScene();
setupCamera();
setupRenderTarget();
m_window->get_display_region_3d()->set_camera(m_cameraPath);
//m_window->get_display_region_3d()->set_camera(m_cameraPath);
}


Expand Down
16 changes: 8 additions & 8 deletions modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ void vpPanda3DGeometryRenderer::getRender(vpImage<vpRGBf> &normals, vpImage<floa
// if (expectedSize != actualSize) {
// throw vpException(vpException::fatalError, "Expected %d bytes, but got %d bytes", expectedSize, actualSize);
// }
std::stringstream ss;
ss << "Texture info:" << std::endl;
ss << "Has ram image: " << m_normalDepthTexture->has_ram_image() << std::endl;
ss << "Size (H x W): " << m_normalDepthTexture->get_y_size() << " x " << m_normalDepthTexture->get_x_size() << std::endl;
ss << "Number of channels: " << m_normalDepthTexture->get_num_components() << std::endl;
ss << "Bytes per channel: " << m_normalDepthTexture->get_component_width() << std::endl;
ss << "Channel type: " << m_normalDepthTexture->get_component_type() << std::endl;
std::cout << ss.str() << std::endl;
// std::stringstream ss;
// ss << "Texture info:" << std::endl;
// ss << "Has ram image: " << m_normalDepthTexture->has_ram_image() << std::endl;
// ss << "Size (H x W): " << m_normalDepthTexture->get_y_size() << " x " << m_normalDepthTexture->get_x_size() << std::endl;
// ss << "Number of channels: " << m_normalDepthTexture->get_num_components() << std::endl;
// ss << "Bytes per channel: " << m_normalDepthTexture->get_component_width() << std::endl;
// ss << "Channel type: " << m_normalDepthTexture->get_component_type() << std::endl;
// std::cout << ss.str() << std::endl;

if (m_normalDepthTexture->get_component_type() == Texture::T_float) {
float *data = (float *)(&(m_normalDepthTexture->get_ram_image().front()));
Expand Down
64 changes: 64 additions & 0 deletions modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,65 @@

#if defined(VISP_HAVE_PANDA3D)

const char *vpPanda3DRGBRenderer::COOK_TORRANCE_VERT = R"shader(
#version 330
in vec3 p3d_Normal;
in vec4 p3d_Vertex;
out vec3 oNormal;
uniform mat3 p3d_NormalMatrix;
uniform mat4 p3d_ModelViewMatrix;
uniform mat4 p3d_ModelViewProjectionMatrix;
void main()
{
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
// View space is Z-up right handed, flip z and y
oNormal = p3d_NormalMatrix * normalize(p3d_Normal);
oNormal.yz = oNormal.zy;
oNormal.y = -oNormal.y;
vec4 cs_position = p3d_ModelViewMatrix * p3d_Vertex;
}
)shader";

const char *vpPanda3DRGBRenderer::COOK_TORRANCE_FRAG = R"shader(
#version 330
in vec3 oNormal;
out vec4 p3d_FragData;
uniform struct {
vec4 ambient;
} p3d_LightModel;
uniform struct p3d_LightSourceParameters {
// Primary light color.
vec4 color;
// View-space position. If w=0, this is a directional light, with the xyz
// being -direction.
vec4 position;
// constant, linear, quadratic attenuation in one vector
vec3 attenuation;
} p3d_LightSource[4];
void main()
{
vec3 n = normalize(oNormal);
p3d_FragData = p3d_LightModel.ambient * vec4(1.f, 0.f, 0.f,0.f);
for(int i = 0; i < p3d_LightSource.length(); ++i) {
vec3 aFac = p3d_LightSource[i].attenuation;
float attenuation = 1.f / (aFac[0] + aFac[1] * dist, aFac[2] * dist * dist);
//p3d_FragData += p3d_LightSource[i].color;
}
}
)shader";


void vpPanda3DRGBRenderer::getRender(vpImage<vpRGBa> &I) const
{
I.resize(m_colorTexture->get_y_size(), m_colorTexture->get_x_size());
Expand All @@ -51,6 +110,11 @@ void vpPanda3DRGBRenderer::setupScene()
{
vpPanda3DBaseRenderer::setupScene();
setLightableScene(m_renderRoot);
PT(Shader) shader;
shader = Shader::make(Shader::ShaderLanguage::SL_GLSL,
COOK_TORRANCE_VERT,
COOK_TORRANCE_FRAG);
m_renderRoot.set_shader(shader);
//m_renderRoot.set_shader_auto();
}

Expand Down

0 comments on commit d16a322

Please sign in to comment.