Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLSL 330 shaders #1726

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
18 changes: 9 additions & 9 deletions ogre_media/materials/glsl150/box.geom
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#version 150
#version 330 core

// Generates an axis-aligned box with a given size
// for each input vertex.
Expand All @@ -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 PerVertex {
vec4 frontColor;
} gs_in[];
Comment on lines -22 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are the only strictly necessary changes in this PR



out vec4 gl_TexCoord[];
out vec4 texCoord[];
out vec4 frontColor;

layout(points) in;
layout(triangle_strip, max_vertices=24) out;
Expand All @@ -49,12 +49,12 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex )
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 );
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[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );

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

#ifdef WITH_DEPTH
Expand Down
27 changes: 27 additions & 0 deletions ogre_media/materials/glsl150/depth.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 330

// Passes on the packed depth value

// Splits up a normalized depth value in the range (0..1)
// into the vertex RGB values.
// Alpha values below 1/255 are rendered transparent.

uniform float alpha;
uniform float far_clip_distance;

const float minimum_alpha = 1.0 / 255.0;

varying float depth;

void main()
{
float normalized_depth = depth / far_clip_distance;

// split up float into rgb components
const vec3 shift = vec3(256.0 * 256.0, 256.0, 1.0);
const vec3 mask = vec3(0.0, 1.0 / 256.0, 1.0 / 256.0);
vec3 depth_packed = fract(normalized_depth * shift);
depth_packed -= depth_packed.xxy * mask;

gl_FragColor = vec4( depth_packed.zyx, step( minimum_alpha, alpha ));
}
14 changes: 14 additions & 0 deletions ogre_media/materials/glsl150/glsl150.program
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

fragment_program rviz/glsl150/depth.frag glsl { source depth.frag }

//all shaders, sorted by name

geometry_program rviz/glsl150/billboard.geom glsl
Expand Down Expand Up @@ -78,3 +81,14 @@ vertex_program rviz/glsl150/pass_pos_color.vert glsl
{
source pass_pos_color.vert
}


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
}
}
19 changes: 12 additions & 7 deletions ogre_media/materials/glsl150/pass_pos_color.vert
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#version 150 compatibility
#version 330

// this merely passes over position and color,
// as needed by box.geom

out gl_PerVertex {
vec4 gl_Position;
vec4 gl_FrontColor;
};
layout(location = 0) in vec3 vertex;
layout(location = 3) in vec4 color;

uniform mat4 uProjection;

out PerVertex {
vec4 frontColor;
} perVertex;


void main() {
gl_Position = gl_Vertex;
gl_FrontColor = gl_Color;
gl_Position = uProjection * vec4(vertex, 1);
perVertex.frontColor = color;
}
30 changes: 30 additions & 0 deletions ogre_media/materials/glsl150/smooth_square.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#version 330

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

uniform vec4 highlight;
uniform float alpha;

in vec4 texCoord[];
in vec4 frontColor;

out vec4 fragColor;

void main()
{
float ax = texCoord[0].x-0.5;
float ay = 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));

float inv_blend = 1.0 - blend;
vec3 col = blend * frontColor.xyz + (sign(0.5 - length(vec3(frontColor.xyz))) * vec3(0.2, 0.2, 0.2) + frontColor.xyz) * inv_blend;

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

col = col + col * highlight.xyz;

fragColor = vec4(col.r, col.g, col.b, alpha * frontColor.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
Expand Up @@ -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 All @@ -22,7 +22,7 @@ material rviz/PointCloudBox
{
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
geometry_program_ref rviz/glsl150/box.geom(with_depth) {}
fragment_program_ref rviz/glsl120/depth.frag {}
fragment_program_ref rviz/glsl150/depth.frag {}
}
}

Expand Down
18 changes: 0 additions & 18 deletions src/rviz/ogre_helpers/render_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ void RenderSystem::loadOgrePlugins()

void RenderSystem::detectGlVersion()
{
bool mesa_workaround = false;
if (force_gl_version_)
{
gl_version_ = force_gl_version_;
Expand All @@ -186,14 +185,6 @@ void RenderSystem::detectGlVersion()
int major = caps->getDriverVersion().major;
int minor = caps->getDriverVersion().minor;
gl_version_ = major * 100 + minor * 10;

#ifdef __linux__
std::string gl_version_string = (const char*)glGetString(GL_VERSION);
// The "Mesa 2" string is intended to match "Mesa 20.", "Mesa 21." and so on
mesa_workaround = gl_version_string.find("Mesa 2") != std::string::npos && gl_version_ >= 320;
#else
mesa_workaround = false;
#endif
}

switch (gl_version_)
Expand Down Expand Up @@ -224,15 +215,6 @@ void RenderSystem::detectGlVersion()
}
break;
}
if (mesa_workaround)
{ // https://github.com/ros-visualization/rviz/issues/1508
ROS_INFO("OpenGl version: %.1f (GLSL %.1f) limited to GLSL 1.4 on Mesa system.",
(float)gl_version_ / 100.0, (float)glsl_version_ / 100.0);

gl_version_ = 310;
glsl_version_ = 140;
return;
}
ROS_INFO("OpenGl version: %.1f (GLSL %.1f).", (float)gl_version_ / 100.0, (float)glsl_version_ / 100.0);
}

Expand Down