Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Apr 16, 2023
2 parents 72acf55 + 5979a50 commit 4af6ea5
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 16 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# version format
version: 2.8.0-{branch}-build{build}
version: 2.8.1-{branch}-build{build}

os: Visual Studio 2019

Expand Down
8 changes: 8 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
\page changelog Change Log

# Version 2.8.1: Released April 17th, 2023
- Changes in libraries:
- \ref mrpt_opengl_grp
- Expose shadow bias parameters into mrpt::opengl::TLightParameters
- BUG FIXES:
- OpenGL shadow rendering: Fix error in calculation of anti peter-panning and shadow acne effects.


# Version 2.8.0: Released April 8th, 2023
- Changes in apps:
- rosbag2rawlog: Added support for converting nav_msgs/Odometry topics to mrpt::obs::CObservationOdometry
Expand Down
4 changes: 3 additions & 1 deletion libs/opengl/include/mrpt/opengl/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class Program

/** Set uniform variables: */
void setInt(const char* uniformName, int value) const;
void setFloat(const char* uniformName, float value) const;
void setFloat(
const char* uniformName, float value,
bool failIfNotExists = true) const;
void setFloat3(const char* uniformName, float v1, float v2, float v3) const;
void setFloat4(
const char* uniformName, float v1, float v2, float v3, float v4) const;
Expand Down
4 changes: 4 additions & 0 deletions libs/opengl/include/mrpt/opengl/TLightParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ struct TLightParameters
/** Light direction (must be normalized) */
mrpt::math::TVector3Df direction = {-0.40825f, -0.40825f, -0.81650f};

/** Shadow tuning parameters ("anti shadow acne") */
float shadow_bias = 1e-5, shadow_bias_cam2frag = 1e-5,
shadow_bias_normal = 1e-4;

void writeToStream(mrpt::serialization::CArchive& out) const;
void readFromStream(mrpt::serialization::CArchive& in);

Expand Down
4 changes: 3 additions & 1 deletion libs/opengl/shaders/shadow-calculation.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ R"XXX(#version 300 es
uniform highp sampler2D shadowMap;
uniform highp vec3 light_direction;

uniform highp float shadow_bias, shadow_bias_cam2frag, shadow_bias_normal;

mediump float ShadowCalculation(
highp vec4 fragPosLightSpace,
mediump vec3 normal,
Expand All @@ -26,7 +28,7 @@ mediump float ShadowCalculation(
highp float currentDepth = projCoords.z;

// check whether current frag pos is in shadow1D
highp float bias = 1e-5 + 1e-5*cam2fragDist + 1e-4*(1.0-max(0.0,dot(normal, -light_direction)));
highp float bias = shadow_bias + shadow_bias_cam2frag*cam2fragDist + shadow_bias_normal*(1.0-max(0.0,dot(normal, light_direction)));
#if 0
mediump float shadow = currentDepth-bias > closestDepth ? 1.0 : 0.0;
#else
Expand Down
9 changes: 9 additions & 0 deletions libs/opengl/src/CRenderizableShaderTexturedTriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ void CRenderizableShaderTexturedTriangles::render(const RenderContext& rc) const
{
// bound to GL_TEXTURE0 + "i":
s.setInt("shadowMap", SHADOW_MAP_TEXTURE_UNIT);

// Shadow params:
if (const auto& l = rc.lights; l)
{
rc.shader->setFloat("shadow_bias", l->shadow_bias);
rc.shader->setFloat(
"shadow_bias_cam2frag", l->shadow_bias_cam2frag);
rc.shader->setFloat("shadow_bias_normal", l->shadow_bias_normal);
}
}

// Set up the vertex array:
Expand Down
9 changes: 9 additions & 0 deletions libs/opengl/src/CRenderizableShaderTriangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ void CRenderizableShaderTriangles::render(const RenderContext& rc) const
{
// bound to GL_TEXTURE0 + "i":
s.setInt("shadowMap", SHADOW_MAP_TEXTURE_UNIT);

// Shadow params:
if (const auto& l = rc.lights; l)
{
rc.shader->setFloat("shadow_bias", l->shadow_bias);
rc.shader->setFloat(
"shadow_bias_cam2frag", l->shadow_bias_cam2frag);
rc.shader->setFloat("shadow_bias_normal", l->shadow_bias_normal);
}
}

// Set up the vertex array:
Expand Down
41 changes: 32 additions & 9 deletions libs/opengl/src/DefaultShaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,21 @@ Program::Ptr mrpt::opengl::LoadDefaultShader(const shader_id_t id)
#include "../shaders/shadow-calculation.f.glsl"
;
uniforms = {
"p_matrix", "v_matrix", "m_matrix",
"light_pv_matrix", "shadowMap", "light_diffuse",
"light_ambient", "light_specular", "light_direction",
"light_color", "cam_position", "materialSpecular"};
"p_matrix",
"v_matrix",
"m_matrix",
"light_pv_matrix",
"shadowMap",
"light_diffuse",
"light_ambient",
"light_specular",
"light_direction",
"shadow_bias",
"shadow_bias_cam2frag",
"shadow_bias_normal",
"light_color",
"cam_position",
"materialSpecular"};
attribs = {"position", "vertexColor", "vertexNormal"};
break;

Expand All @@ -174,11 +185,23 @@ Program::Ptr mrpt::opengl::LoadDefaultShader(const shader_id_t id)
fragShaderIncludes =
#include "../shaders/shadow-calculation.f.glsl"
;
uniforms = {"p_matrix", "v_matrix", "m_matrix",
"light_pv_matrix", "shadowMap", "light_diffuse",
"light_ambient", "light_specular", "light_direction",
"light_color", "cam_position", "materialSpecular",
"textureSampler"};
uniforms = {
"p_matrix",
"v_matrix",
"m_matrix",
"light_pv_matrix",
"shadowMap",
"light_diffuse",
"light_ambient",
"light_specular",
"light_direction",
"shadow_bias",
"shadow_bias_cam2frag",
"shadow_bias_normal",
"light_color",
"cam_position",
"materialSpecular",
"textureSampler"};
attribs = {"position", "vertexNormal", "vertexUV"};
break;

Expand Down
5 changes: 4 additions & 1 deletion libs/opengl/src/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,12 @@ void Program::setInt(const char* uniformName, int value) const
#endif
}

void Program::setFloat(const char* uniformName, float value) const
void Program::setFloat(
const char* uniformName, float value, bool failIfNotExists) const
{
#if MRPT_HAS_OPENGL_GLUT || MRPT_HAS_EGL
if (!failIfNotExists && !hasUniform(uniformName)) return;

glUniform1f(uniformId(uniformName), value);
#endif
}
Expand Down
8 changes: 7 additions & 1 deletion libs/opengl/src/TLightParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ using namespace std;

void TLightParameters::writeToStream(mrpt::serialization::CArchive& out) const
{
const uint8_t version = 1;
const uint8_t version = 2;
out << version;

out << diffuse << ambient << specular << direction << color;
out << shadow_bias << shadow_bias_cam2frag << shadow_bias_normal; // v2
}

void TLightParameters::readFromStream(mrpt::serialization::CArchive& in)
Expand All @@ -42,7 +43,12 @@ void TLightParameters::readFromStream(mrpt::serialization::CArchive& in)
}
break;
case 1:
case 2:
in >> diffuse >> ambient >> specular >> direction >> color;
if (version >= 2)
{
in >> shadow_bias >> shadow_bias_cam2frag >> shadow_bias_normal;
}
break;
default: MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(version);
};
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<package format="3">
<name>mrpt2</name>
<!-- Before updating version number, read [MRPT_ROOT]/version_prefix.txt first -->
<version>2.8.0</version>
<version>2.8.1</version>
<description>Mobile Robot Programming Toolkit (MRPT) version 2.x</description>

<author email="[email protected]">Jose-Luis Blanco-Claraco</author>
Expand Down
2 changes: 1 addition & 1 deletion version_prefix.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2.8.0
2.8.1
# IMPORTANT: This file is parsed by CMake, don't add any comment to
# the first line.
# This file is used in both Windows and Linux scripts to automatically
Expand Down

0 comments on commit 4af6ea5

Please sign in to comment.