diff --git a/ogre_media/materials/glsl150/billboard.geom b/ogre_media/materials/glsl150/billboard.geom index 08e53670a6..e24ab79de8 100644 --- a/ogre_media/materials/glsl150/billboard.geom +++ b/ogre_media/materials/glsl150/billboard.geom @@ -19,12 +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=4) out; @@ -32,10 +33,10 @@ 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(); } diff --git a/ogre_media/materials/glsl150/box.geom b/ogre_media/materials/glsl150/box.geom index 64b31af93d..974f889f2f 100644 --- a/ogre_media/materials/glsl150/box.geom +++ b/ogre_media/materials/glsl150/box.geom @@ -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; @@ -44,12 +44,12 @@ void emitVertex( int side, vec4 x, vec4 y, vec4 z, vec3 tex, vec4 size_factor ) vec4 pos_rel = tex.x*x + tex.y*y + tex.z*z; 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.rgb * 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.rgb, gl_in[0].gl_FrontColor.a ); + color = vdata[0].color; #endif #ifdef WITH_DEPTH diff --git a/ogre_media/materials/glsl150/flat_color.frag b/ogre_media/materials/glsl150/flat_color.frag new file mode 100644 index 0000000000..eec271a0cb --- /dev/null +++ b/ogre_media/materials/glsl150/flat_color.frag @@ -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); +} diff --git a/ogre_media/materials/glsl150/glsl150.program b/ogre_media/materials/glsl150/glsl150.program index 14c4fba115..31d5ae7b12 100644 --- a/ogre_media/materials/glsl150/glsl150.program +++ b/ogre_media/materials/glsl150/glsl150.program @@ -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 + } +} diff --git a/ogre_media/materials/glsl150/pass_pos_color.vert b/ogre_media/materials/glsl150/pass_pos_color.vert index 9ee147ca5d..216e1feb0a 100644 --- a/ogre_media/materials/glsl150/pass_pos_color.vert +++ b/ogre_media/materials/glsl150/pass_pos_color.vert @@ -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; } diff --git a/ogre_media/materials/glsl150/shaded_circle.frag b/ogre_media/materials/glsl150/shaded_circle.frag new file mode 100644 index 0000000000..f5083d5e9f --- /dev/null +++ b/ogre_media/materials/glsl150/shaded_circle.frag @@ -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); +} diff --git a/ogre_media/materials/glsl150/smooth_square.frag b/ogre_media/materials/glsl150/smooth_square.frag new file mode 100644 index 0000000000..2218e67559 --- /dev/null +++ b/ogre_media/materials/glsl150/smooth_square.frag @@ -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); +} diff --git a/ogre_media/materials/scripts150/point_cloud_box.material b/ogre_media/materials/scripts150/point_cloud_box.material index 8c76c163b1..4a136fc600 100644 --- a/ogre_media/materials/scripts150/point_cloud_box.material +++ b/ogre_media/materials/scripts150/point_cloud_box.material @@ -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 @@ -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 {} } } diff --git a/ogre_media/materials/scripts150/point_cloud_flat_square.material b/ogre_media/materials/scripts150/point_cloud_flat_square.material index cafb2e8852..de678439b7 100644 --- a/ogre_media/materials/scripts150/point_cloud_flat_square.material +++ b/ogre_media/materials/scripts150/point_cloud_flat_square.material @@ -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 {} } } diff --git a/ogre_media/materials/scripts150/point_cloud_sphere.material b/ogre_media/materials/scripts150/point_cloud_sphere.material index bd6289347d..1edaa5f11a 100644 --- a/ogre_media/materials/scripts150/point_cloud_sphere.material +++ b/ogre_media/materials/scripts150/point_cloud_sphere.material @@ -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 {} } } diff --git a/ogre_media/materials/scripts150/point_cloud_square.material b/ogre_media/materials/scripts150/point_cloud_square.material index 276ec62c40..24ab1f2ecc 100644 --- a/ogre_media/materials/scripts150/point_cloud_square.material +++ b/ogre_media/materials/scripts150/point_cloud_square.material @@ -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 {} } }