Skip to content

Commit b255497

Browse files
committed
Fix GLSL 1.5 compatibility
- Drop compatibility mode, which is not supported by Mesa - Don't use gl_ prefixes for user-declared variables - Don't redeclare gl_PerVertex
1 parent cf657f4 commit b255497

File tree

10 files changed

+139
-30
lines changed

10 files changed

+139
-30
lines changed

ogre_media/materials/glsl150/billboard.geom

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@ uniform mat4 worldviewproj_matrix;
1919
uniform vec4 size;
2020
uniform vec4 auto_size;
2121

22-
in gl_PerVertex {
23-
vec4 gl_Position;
24-
vec4 gl_FrontColor;
25-
} gl_in[];
22+
in VertexData {
23+
vec4 color;
24+
} vdata[];
2625

27-
out vec4 gl_TexCoord[];
26+
// Use exactly these names to map onto gl_Color and gl_TexCoord used by fragment shaders
27+
out vec4 color;
28+
out vec2 TexCoord;
2829

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

3233
void emitVertex( vec3 pos_rel, vec3 tex )
3334
{
3435
pos_rel = mat3(inverse_worldview_matrix) * pos_rel;
35-
vec4 pos = gl_in[0].gl_Position + vec4(pos_rel,0.0);
36+
vec4 pos = gl_in[0].gl_Position + vec4(pos_rel, 0.0);
3637
gl_Position = worldviewproj_matrix * pos;
37-
gl_TexCoord[0] = vec4( tex.xy, 0.0, 0.0 );
38-
gl_FrontColor = vec4( gl_in[0].gl_FrontColor );
38+
TexCoord = tex.xy;
39+
color = vdata[0].color;
3940
EmitVertex();
4041
}
4142

ogre_media/materials/glsl150/box.geom

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ uniform mat4 worldviewproj_matrix;
1919
uniform vec4 size;
2020
uniform vec4 auto_size;
2121

22-
in gl_PerVertex {
23-
vec4 gl_Position;
24-
vec4 gl_FrontColor;
25-
} gl_in[];
22+
in VertexData {
23+
vec4 color;
24+
} vdata[];
2625

27-
28-
out vec4 gl_TexCoord[];
26+
// Use exactly these names to map onto gl_Color and gl_TexCoord used by fragment shaders
27+
out vec4 color;
28+
out vec2 TexCoord;
2929

3030
layout(points) in;
3131
layout(triangle_strip, max_vertices=24) out;
@@ -44,12 +44,12 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex, vec4 size_factor )
4444
vec4 pos_rel = tex.x*x + tex.y*y + tex.z*z;
4545
vec4 pos = gl_in[0].gl_Position + vec4( pos_rel * size_factor );
4646
gl_Position = worldviewproj_matrix * pos;
47-
gl_TexCoord[0] = vec4( tex.x*0.5+0.5, tex.y*0.5+0.5, 0.0, 0.0 );
47+
TexCoord = vec2(tex.x*0.5+0.5, tex.y*0.5+0.5);
4848

4949
#ifdef WITH_LIGHTING
50-
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.rgb * lightness[side], gl_in[0].gl_FrontColor.a );
50+
color = vec4( vdata[0].color.rgb * lightness[side], vdata[0].color.a );
5151
#else
52-
gl_FrontColor = vec4( gl_in[0].gl_FrontColor.rgb, gl_in[0].gl_FrontColor.a );
52+
color = vdata[0].color;
5353
#endif
5454

5555
#ifdef WITH_DEPTH
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#version 150
2+
3+
// Passes the fragment color, multiplying a with the alpha param
4+
5+
uniform vec4 highlight;
6+
uniform float alpha;
7+
8+
in vec4 color;
9+
out vec4 FragColor;
10+
11+
void main()
12+
{
13+
vec3 col = color.xyz + color.xyz * highlight.xyz;
14+
FragColor = vec4(col, color.a * alpha);
15+
}

ogre_media/materials/glsl150/glsl150.program

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,33 @@ vertex_program rviz/glsl150/pass_pos_color.vert glsl
7878
{
7979
source pass_pos_color.vert
8080
}
81+
82+
fragment_program rviz/glsl150/flat_color.frag glsl
83+
{
84+
source flat_color.frag
85+
default_params
86+
{
87+
param_named_auto highlight custom 5
88+
param_named_auto alpha custom 1
89+
}
90+
}
91+
92+
fragment_program rviz/glsl150/shaded_circle.frag glsl
93+
{
94+
source shaded_circle.frag
95+
default_params
96+
{
97+
param_named_auto highlight custom 5
98+
param_named_auto alpha custom 1
99+
}
100+
}
101+
102+
fragment_program rviz/glsl150/smooth_square.frag glsl
103+
{
104+
source smooth_square.frag
105+
default_params
106+
{
107+
param_named_auto highlight custom 5
108+
param_named_auto alpha custom 1
109+
}
110+
}
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
#version 150 compatibility
1+
#version 150
22

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

6-
out gl_PerVertex {
7-
vec4 gl_Position;
8-
vec4 gl_FrontColor;
9-
};
8+
// this merely passes over position and color as needed by box.geom
9+
10+
out VertexData {
11+
vec4 color;
12+
} vdata;
1013

1114
void main() {
12-
gl_Position = gl_Vertex;
13-
gl_FrontColor = gl_Color;
15+
gl_Position = vertex;
16+
vdata.color = colour;
1417
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#version 150
2+
3+
// rasterizes a circle that is darker at the borders than in the center
4+
5+
uniform vec4 highlight;
6+
uniform float alpha;
7+
8+
in vec4 color;
9+
in vec2 TexCoord;
10+
11+
out vec4 FragColor;
12+
13+
void main()
14+
{
15+
float ax = TexCoord.x-0.5;
16+
float ay = TexCoord.y-0.5;
17+
18+
float rsquared = ax*ax+ay*ay;
19+
float a = (0.25 - rsquared) * 4.0;
20+
21+
vec3 col = mix(vec3(0.8, 0.8, 0.8) * color.xyz, color.xyz, a);
22+
23+
col = col + col * highlight.xyz;
24+
25+
FragColor = vec4(col, alpha * ceil(a) * color.a);
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 150
2+
3+
// rasterizes a smooth square with ax,ay in [-0.5..0.5]
4+
5+
uniform vec4 highlight;
6+
uniform float alpha;
7+
8+
in vec4 color;
9+
in vec2 TexCoord;
10+
11+
out vec4 FragColor;
12+
13+
void main()
14+
{
15+
const float outer = 0.48;
16+
const float inner = 0.45;
17+
float ax = TexCoord.x-0.5;
18+
float ay = TexCoord.y-0.5;
19+
20+
// blending factor, varying between 0.0 (at the border) and 1.0 (at the center of the square)
21+
float blend = smoothstep(-outer, -inner, ay) * (1.0 - smoothstep(inner, outer, ay)) *
22+
smoothstep(-outer, -inner, ax) * (1.0 - smoothstep(inner, outer, ax));
23+
24+
#if 1 // high contrast edge (dark edge on light surface / light edge on dark surface)
25+
float inv_blend = 1.0 - blend;
26+
vec3 col = blend * color.rgb + (sign(0.5 - length(vec3(color.rgb))) * vec3(0.2, 0.2, 0.2) + color.rgb) * inv_blend;
27+
#else // alternatively: make color at edge darker
28+
vec3 col = (0.5 + 0.5*blend) * color.rgb;
29+
#endif
30+
31+
col = col + col * highlight.rgb;
32+
33+
FragColor = vec4(col.rgb, alpha * color.a);
34+
}

ogre_media/materials/scripts150/point_cloud_box.material

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
material rviz/PointCloudBox
22
{
3-
/* This material should only be used with glsl < 1.50 */
3+
/* This material should only be used with glsl >= 1.50 */
44

55
// the 'gp' techniques need one input vertex per box
66
// and use geometry shaders to create the geometry
@@ -11,7 +11,7 @@ material rviz/PointCloudBox
1111
{
1212
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
1313
geometry_program_ref rviz/glsl150/box.geom(with_lighting) {}
14-
fragment_program_ref rviz/glsl120/smooth_square.frag {}
14+
fragment_program_ref rviz/glsl150/smooth_square.frag {}
1515
}
1616
}
1717

ogre_media/materials/scripts150/point_cloud_flat_square.material

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ material rviz/PointCloudFlatSquare {
77
alpha_rejection greater_equal 1
88
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
99
geometry_program_ref rviz/glsl150/billboard.geom {}
10-
fragment_program_ref rviz/glsl120/flat_color.frag {}
10+
fragment_program_ref rviz/glsl150/flat_color.frag {}
1111
}
1212
}
1313

ogre_media/materials/scripts150/point_cloud_sphere.material

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ material rviz/PointCloudSphere {
77
alpha_rejection greater_equal 1
88
vertex_program_ref rviz/glsl150/pass_pos_color.vert {}
99
geometry_program_ref rviz/glsl150/billboard.geom {}
10-
fragment_program_ref rviz/glsl120/shaded_circle.frag {}
10+
fragment_program_ref rviz/glsl150/shaded_circle.frag {}
1111
}
1212
}
1313

0 commit comments

Comments
 (0)