From d16a3229fb7d54135b16b9f9e9945aac54ff0c60 Mon Sep 17 00:00:00 2001 From: Samuel Felton Date: Fri, 26 Apr 2024 18:09:22 +0200 Subject: [PATCH] Start work on RGB shader --- .../include/visp3/ar/vpPanda3DRGBRenderer.h | 3 + .../vpPanda3DBaseRenderer.cpp | 2 +- .../vpPanda3DGeometryRenderer.cpp | 16 ++--- .../vpPanda3DRGBRenderer.cpp | 64 +++++++++++++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h index dae7ac1cce..dc60a68098 100644 --- a/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h +++ b/modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h @@ -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; + }; diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp index 3d48ff4021..154b0fbc47 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DBaseRenderer.cpp @@ -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); } diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp index 856d91072d..dfd77db411 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DGeometryRenderer.cpp @@ -192,14 +192,14 @@ void vpPanda3DGeometryRenderer::getRender(vpImage &normals, vpImagehas_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())); diff --git a/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp b/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp index 3de6354340..dfbbb93d3e 100644 --- a/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp +++ b/modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp @@ -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 &I) const { I.resize(m_colorTexture->get_y_size(), m_colorTexture->get_x_size()); @@ -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(); }