Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8d15e7
Drop Mesa workaround
rhaschke Feb 12, 2022
c59158f
Use .rgb notation for colors
rhaschke Mar 15, 2022
f53c908
Tweak square fragment shader
rhaschke Mar 15, 2022
3b8d86e
Compute size_factor only once
rhaschke Mar 16, 2022
63f3782
Fix GLSL 1.5 compatibility
rhaschke Mar 16, 2022
1ac02a9
Improve code readability
rhaschke Mar 26, 2022
83b378e
grid_cells example: reduce rate
rhaschke Mar 26, 2022
b2aeae1
adapt to new createSceneManager in Ogre 13
simonschmeisser Apr 27, 2023
13ffaa7
add missing deque include
simonschmeisser Apr 27, 2023
55f9583
add missing include for Iterator
simonschmeisser Apr 27, 2023
d4a92ee
Ogre::UTFString was removed in 13.0
simonschmeisser Apr 27, 2023
7a024a9
proof of concept for using new ogre text
simonschmeisser Apr 28, 2023
9c22338
Switch to GL3+ RenderSystem and enable RTShaderSystem
simonschmeisser Mar 27, 2022
d54da22
WIP: set location of RTShaders
simonschmeisser Mar 27, 2022
3a9cc54
Add shader generator listener
simonschmeisser Mar 28, 2022
b49c46f
initialize resources only after the RTShaderSystem has been started
simonschmeisser Mar 28, 2022
c444f28
WIP: path to current ogre version
simonschmeisser Apr 28, 2023
0463b4a
createShaderBasedTechnique
simonschmeisser Apr 28, 2023
e170802
catch exceptions while rendering
simonschmeisser May 1, 2023
e8da4d5
add createShaderBasedTechnique in more places
simonschmeisser May 1, 2023
4a766a4
enable cache due to better logging
simonschmeisser May 2, 2023
6c7ba26
WIP: renders mostly
simonschmeisser May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT DEFINED ASSIMP_LIBRARIES AND TARGET assimp::assimp)
set(ASSIMP_LIBRARIES assimp::assimp)
endif()

find_package(OGRE QUIET COMPONENTS Overlay)
find_package(OGRE QUIET COMPONENTS Overlay RTShaderSystem Bites)
if(OGRE_FOUND)
if(${OGRE_VERSION} VERSION_LESS 1.11)
set(OGRE_INCLUDE_DIRS ${OGRE_INCLUDE_DIRS} ${OGRE_Overlay_INCLUDE_DIRS})
Expand All @@ -38,7 +38,7 @@ else()
# OGRE doesn't come with correctly installed cmake files on Linux. Use pkg-config instead.
# We need both, OGRE and OGRE-Overlay. Look for both simulatenously and use prefix X_
find_package(PkgConfig REQUIRED)
pkg_check_modules(X REQUIRED OGRE OGRE-Overlay)
pkg_check_modules(X REQUIRED OGRE OGRE-Overlay OGRE-RTShaderSystem)

# Set OGRE_* variables as cmake-based find_package would do
set(OGRE_VERSION ${X_OGRE_VERSION})
Expand Down
2 changes: 1 addition & 1 deletion default.rviz
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Visualization Manager:
Cell Size: 1
Class: rviz/Grid
Color: 160; 160; 164
Enabled: true
Enabled: false
Line Style:
Line Width: 0.03
Value: Lines
Expand Down
20 changes: 12 additions & 8 deletions ogre_media/materials/glsl120/smooth_square.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ uniform float alpha;

void main()
{
const float outer = 0.48;
const float inner = 0.45;
float ax = gl_TexCoord[0].x-0.5;
float ay = gl_TexCoord[0].y-0.5;

float blend = smoothstep(-0.48, -0.45, ay) * (1.0 - smoothstep(0.45, 0.48, ay)) *
smoothstep(-0.48, -0.45, ax) * (1.0 - smoothstep(0.45, 0.48, ax));
// blending factor, varying between 0.0 (at the border) and 1.0 (at the center of the square)
float blend = smoothstep(-outer, -inner, ay) * (1.0 - smoothstep(inner, outer, ay)) *
smoothstep(-outer, -inner, ax) * (1.0 - smoothstep(inner, outer, ax));

#if 1 // high contrast edge (dark edge on light surface / light edge on dark surface)
float inv_blend = 1.0 - blend;
vec3 col = blend * gl_Color.xyz + (sign(0.5 - length(vec3(gl_Color.xyz))) * vec3(0.2, 0.2, 0.2) + gl_Color.xyz) * inv_blend;
vec3 col = blend * gl_Color.rgb + (sign(0.5 - length(gl_Color.rgb)) * vec3(0.2, 0.2, 0.2) + gl_Color.rgb) * inv_blend;
#else // alternatively: make color at edge darker
vec3 col = (0.5 + 0.5*blend) * gl_Color.rgb;
#endif

//alternative version: make color at edge darker
//vec3 col = (0.5 + 0.5*blend) * gl_Color.xyz;
col = col + col * highlight.rgb;

col = col + col * highlight.xyz;

gl_FragColor = vec4(col.r, col.g, col.b, alpha * gl_Color.a );
gl_FragColor = vec4(col.rgb, alpha * gl_Color.a);
}
17 changes: 9 additions & 8 deletions ogre_media/materials/glsl150/billboard.geom
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,24 @@ uniform mat4 worldviewproj_matrix;
uniform vec4 size;
uniform vec4 auto_size;

in gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
} gl_in[];
in VertexData {
vec4 color;
} vdata[];

out vec4 gl_TexCoord[];
// Use exactly these names to map onto gl_Color and gl_TexCoord used by fragment shaders
out vec4 color;
out vec2 TexCoord;

layout(points) in;
layout(triangle_strip, max_vertices=4) out;

void emitVertex( vec3 pos_rel, vec3 tex )
{
pos_rel = mat3(inverse_worldview_matrix) * pos_rel;
vec4 pos = gl_in[0].gl_Position + vec4(pos_rel,0.0);
vec4 pos = gl_in[0].gl_Position + vec4(pos_rel, 0.0);
gl_Position = worldviewproj_matrix * pos;
gl_TexCoord[0] = vec4( tex.xy, 0.0, 0.0 );
gl_FrontColor = vec4( gl_in[0].gl_FrontColor );
TexCoord = tex.xy;
color = vdata[0].color;
EmitVertex();
}

Expand Down
53 changes: 25 additions & 28 deletions ogre_media/materials/glsl150/box.geom
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ uniform mat4 worldviewproj_matrix;
uniform vec4 size;
uniform vec4 auto_size;

in gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
} gl_in[];
in VertexData {
vec4 color;
} vdata[];


out vec4 gl_TexCoord[];
// Use exactly these names to map onto gl_Color and gl_TexCoord used by fragment shaders
out vec4 color;
out vec2 TexCoord;

layout(points) in;
layout(triangle_strip, max_vertices=24) out;
Expand All @@ -39,22 +39,17 @@ const vec4 axes[3] = vec4[] (
const float lightness[6] = float[] (
0.9, 0.5, 0.6, 0.6, 1.0, 0.4 );


void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )
void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex, vec4 size_factor )
{
// if auto_size == 1, then size_factor == size*gl_Vertex.z
// if auto_size == 0, then size_factor == size
vec4 size_factor = (1-auto_size.x+(auto_size.x*gl_in[0].gl_Position.z))*size;

vec4 pos_rel = tex.x*x + tex.y*y + tex.z*z;
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor * 0.5 );
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor );
gl_Position = worldviewproj_matrix * pos;
gl_TexCoord[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );
TexCoord = vec2(tex.x*0.5+0.5, tex.y*0.5+0.5);

#ifdef WITH_LIGHTING
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.xyz * lightness[side], gl_in[0].gl_FrontColor.a );
color = vec4( vdata[0].color.rgb * lightness[side], vdata[0].color.a );
#else
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.xyz, gl_in[0].gl_FrontColor.a );
color = vdata[0].color;
#endif

#ifdef WITH_DEPTH
Expand All @@ -67,26 +62,28 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )

void main()
{
// if auto_size == 1, then size_factor == size*gl_Vertex.z
// if auto_size == 0, then size_factor == size
vec4 size_factor = (0.5*(1-auto_size.x+(auto_size.x*gl_in[0].gl_Position.z)))*size;

for( int side=0; side<3; side++ )
{
int side2 = (side+1)%3;
int side3 = (side+2)%3;
vec4 x=axes[ side ];
vec4 y=axes[ side2 ];
vec4 z=axes[ side3 ];
vec4 y=axes[ (side+1)%3 ];
vec4 z=axes[ (side+2)%3 ];

// face for +z
emitVertex( side, x, y, z, vec3(-1, -1, +1) );
emitVertex( side, x, y, z, vec3(+1, -1, +1) );
emitVertex( side, x, y, z, vec3(-1, +1, +1) );
emitVertex( side, x, y, z, vec3(+1, +1, +1) );
emitVertex( side, x, y, z, vec3(-1, -1, +1), size_factor );
emitVertex( side, x, y, z, vec3(+1, -1, +1), size_factor );
emitVertex( side, x, y, z, vec3(-1, +1, +1), size_factor );
emitVertex( side, x, y, z, vec3(+1, +1, +1), size_factor );
EndPrimitive();

// face for -z
emitVertex( side+3, x, y, z, vec3(-1, -1, -1) );
emitVertex( side+3, x, y, z, vec3(-1, +1, -1) );
emitVertex( side+3, x, y, z, vec3(+1, -1, -1) );
emitVertex( side+3, x, y, z, vec3(+1, +1, -1) );
emitVertex( side+3, x, y, z, vec3(-1, -1, -1), size_factor );
emitVertex( side+3, x, y, z, vec3(-1, +1, -1), size_factor );
emitVertex( side+3, x, y, z, vec3(+1, -1, -1), size_factor );
emitVertex( side+3, x, y, z, vec3(+1, +1, -1), size_factor );
EndPrimitive();
}
}
15 changes: 15 additions & 0 deletions ogre_media/materials/glsl150/flat_color.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 150

// Passes the fragment color, multiplying a with the alpha param

uniform vec4 highlight;
uniform float alpha;

in vec4 color;
out vec4 FragColor;

void main()
{
vec3 col = color.xyz + color.xyz * highlight.xyz;
FragColor = vec4(col, color.a * alpha);
}
30 changes: 30 additions & 0 deletions ogre_media/materials/glsl150/glsl150.program
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,33 @@ vertex_program rviz/glsl150/pass_pos_color.vert glsl
{
source pass_pos_color.vert
}

fragment_program rviz/glsl150/flat_color.frag glsl
{
source flat_color.frag
default_params
{
param_named_auto highlight custom 5
param_named_auto alpha custom 1
}
}

fragment_program rviz/glsl150/shaded_circle.frag glsl
{
source shaded_circle.frag
default_params
{
param_named_auto highlight custom 5
param_named_auto alpha custom 1
}
}

fragment_program rviz/glsl150/smooth_square.frag glsl
{
source smooth_square.frag
default_params
{
param_named_auto highlight custom 5
param_named_auto alpha custom 1
}
}
21 changes: 12 additions & 9 deletions ogre_media/materials/glsl150/pass_pos_color.vert
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#version 150 compatibility
#version 150

// this merely passes over position and color,
// as needed by box.geom
// need to use exactly these names to have OGRE bind the unpacked values:
// https://ogrecave.github.io/ogre/api/latest/_high-level-_programs.html#Binding-vertex-attributes
in vec4 vertex;
in vec4 colour;

out gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
};
// this merely passes over position and color as needed by box.geom

out VertexData {
vec4 color;
} vdata;

void main() {
gl_Position = gl_Vertex;
gl_FrontColor = gl_Color;
gl_Position = vertex;
vdata.color = colour;
}
26 changes: 26 additions & 0 deletions ogre_media/materials/glsl150/shaded_circle.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 150

// rasterizes a circle that is darker at the borders than in the center

uniform vec4 highlight;
uniform float alpha;

in vec4 color;
in vec2 TexCoord;

out vec4 FragColor;

void main()
{
float ax = TexCoord.x-0.5;
float ay = TexCoord.y-0.5;

float rsquared = ax*ax+ay*ay;
float a = (0.25 - rsquared) * 4.0;

vec3 col = mix(vec3(0.8, 0.8, 0.8) * color.xyz, color.xyz, a);

col = col + col * highlight.xyz;

FragColor = vec4(col, alpha * ceil(a) * color.a);
}
34 changes: 34 additions & 0 deletions ogre_media/materials/glsl150/smooth_square.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#version 150

// rasterizes a smooth square with ax,ay in [-0.5..0.5]

uniform vec4 highlight;
uniform float alpha;

in vec4 color;
in vec2 TexCoord;

out vec4 FragColor;

void main()
{
const float outer = 0.48;
const float inner = 0.45;
float ax = TexCoord.x-0.5;
float ay = TexCoord.y-0.5;

// blending factor, varying between 0.0 (at the border) and 1.0 (at the center of the square)
float blend = smoothstep(-outer, -inner, ay) * (1.0 - smoothstep(inner, outer, ay)) *
smoothstep(-outer, -inner, ax) * (1.0 - smoothstep(inner, outer, ax));

#if 1 // high contrast edge (dark edge on light surface / light edge on dark surface)
float inv_blend = 1.0 - blend;
vec3 col = blend * color.rgb + (sign(0.5 - length(vec3(color.rgb))) * vec3(0.2, 0.2, 0.2) + color.rgb) * inv_blend;
#else // alternatively: make color at edge darker
vec3 col = (0.5 + 0.5*blend) * color.rgb;
#endif

col = col + col * highlight.rgb;

FragColor = vec4(col.rgb, alpha * color.a);
}
4 changes: 2 additions & 2 deletions ogre_media/materials/scripts150/point_cloud_box.material
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
material rviz/PointCloudBox
{
/* This material should only be used with glsl < 1.50 */
/* This material should only be used with glsl >= 1.50 */

// the 'gp' techniques need one input vertex per box
// and use geometry shaders to create the geometry
Expand All @@ -11,7 +11,7 @@ material rviz/PointCloudBox
{
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
geometry_program_ref rviz/glsl150/box.geom(with_lighting) {}
fragment_program_ref rviz/glsl120/smooth_square.frag {}
fragment_program_ref rviz/glsl150/smooth_square.frag {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ material rviz/PointCloudFlatSquare {
alpha_rejection greater_equal 1
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
geometry_program_ref rviz/glsl150/billboard.geom {}
fragment_program_ref rviz/glsl120/flat_color.frag {}
fragment_program_ref rviz/glsl150/flat_color.frag {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ material rviz/PointCloudSphere {
alpha_rejection greater_equal 1
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
geometry_program_ref rviz/glsl150/billboard.geom {}
fragment_program_ref rviz/glsl120/shaded_circle.frag {}
fragment_program_ref rviz/glsl150/shaded_circle.frag {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ material rviz/PointCloudSquare {
alpha_rejection greater_equal 1
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
geometry_program_ref rviz/glsl150/billboard.geom {}
fragment_program_ref rviz/glsl120/smooth_square.frag {}
fragment_program_ref rviz/glsl150/smooth_square.frag {}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/image_view/image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ using namespace rviz;
ImageView::ImageView(QWidget* parent) : QtOgreRenderWindow(parent), texture_it_(nh_)
{
setAutoRender(false);
#if (OGRE_VERSION < OGRE_VERSION_CHECK(13, 0, 0))
scene_manager_ = ogre_root_->createSceneManager(Ogre::ST_GENERIC, "TestSceneManager");
#else
scene_manager_ = ogre_root_->createSceneManager(Ogre::DefaultSceneManagerFactory::FACTORY_TYPE_NAME, "TestSceneManager");
#endif
}

ImageView::~ImageView()
Expand Down
2 changes: 2 additions & 0 deletions src/rviz/default_plugin/covariance_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#ifndef COVARIANCE_PROPERTY_H
#define COVARIANCE_PROPERTY_H

#include <deque>

#include <QColor>

#include <OgreColourValue.h>
Expand Down
5 changes: 5 additions & 0 deletions src/rviz/default_plugin/image_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ void ImageDisplay::onInitialize()
static uint32_t count = 0;
std::stringstream ss;
ss << "ImageDisplay" << count++;
#if (OGRE_VERSION < OGRE_VERSION_CHECK(13, 0, 0))
img_scene_manager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, ss.str());
#else
img_scene_manager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::DefaultSceneManagerFactory::FACTORY_TYPE_NAME, ss.str());
#endif

}

img_scene_node_ = img_scene_manager_->getRootSceneNode()->createChildSceneNode();
Expand Down
Loading