• Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language GLSL
  • License
    MIT License
  • Created almost 8 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💫 GLSL shader that enables drawing of thick and smooth lines/curves in 3D (OpenSceneGraph visualization)

GLSL shader for 3D Bezier curves with added fog effect (using OpenSceneGraph)

GLSL shader for lines and curves

This is an example project that demonstrates how to draw thick and smooth lines / curves in 3D. It is known that the native GL_LINE_STRIP_ADJACENCY creates gaps when drawing a polyline. Another restriction of the above mode is that thickness cannot surpass certain threshold (e.g., 10.f, depending on the machine). This code demonstrates how a GLSL shaders can help to solve the above problems.

It is possible to draw two types of geometries with the provided shaders:

  1. Polylines
  2. Bezier curves

Both of the geometries can be placed in a 3D space with any line thickness.

As a bonus, I added a simplest fog effect inside the fragment shader for a Bezier curve.

3D polylines

The polyline shaders can be found as Shaders/polyline.* files. The vertex and fragment shaders are simple pass-through, while the geometry shader provides the functionality to turn the input geometry into a thich triangular strip which is always turned towards the screen.

3D Bezier curves

Refer to the Shaders/bezier.* set of files. The main principle is the same as for the polyline shaders. The vertex shader is a pass-through. The fragment shader demostrates a simple fog effect on the geometry, and the geometrical shader treats the input geometry as Bezier control points, breaks the input curve into the provided number of segments and draws each segment in the same manner as a polyline segment. I.e., it emits a rectangular strip which is always turned towards the camera.

Requirement

  • Compiler that supports C++, e.g., GCC
  • OpenSceneGraph library (>= 3.4.0)
  • Graphics card supporting OpenGL (>=3.3) - make sure your drivers are updated
  • CMake (>=2.8.11)

Troubleshoot

On slightly older machines, it is possible to encounter the Error C6033 : Hardware limitations reached, can only emit ... vertices of this size.. In this case, modify the number of maximum emitting vertices within the shader file.

In Stroke.geom file, seek for SegmentsMax and max_vertices variables, and, depending on the maximum number of vertices your hardware supports, change their values. E.g., if the number of maximum vertices is 102 on your machine (based on the error message), set:

const int SegmentsMax = 24; // max_vertices = (SegmentsMax+1)*4;
// ...
layout(triangle_strip, max_vertices = 100) out;

Build

Use CMakeLists.txt to do the build, then run shader-3dcurve.

More Repositories

1

CurveFitting

〰️ Curve fitting based on Schneider's algorithm. Written using C++11 and OpenSceneGraph (visualization)
C++
93
star
2

cherish

🏰 Sketch- and image-based system for 3D representation and documentation of cultural heritage sites
C++
41
star
3

DistCorr-lib

Optical distortion calculation and correction; open source C, C++ library
C++
34
star
4

QtOSG-hello

An example of using Travis and Coverity for project with dependency on Qt and OpenSceneGraph
C++
32
star
5

osg-intersectors-example

🔲 Example of line, point and virtual plane intersectors: changing polygon outline by using hover and drag mouse events (using C++11 and OpenSceneGraph)
C++
26
star
6

corrCA-prototype

Chromatic aberration correction software, C/C++
C++
12
star
7

dotfiles

vim, zsh, tmux, lxterminal, dircolors configs, all unified to solarized; working on Linux and Cygwin; very easy install
Shell
9
star
8

ellipseC

C++ code to detect precise ellipse center using Levenberg-Marquardt algorithm. The code is a part of chromatic aberration correction software, as well as calibration matrix calculator
C++
8
star
9

Kmat-virtual

Camera matrix calculation with affine bias compensation using virtual data
C++
7
star
10

cryo3d

3d protein model reconstruction pipeline from cryo-em particle images, developed at Yale IPAG
MATLAB
7
star
11

vimcheat

Personal vim cheat sheet based on ProVim book
6
star
12

ParallelTransportFrame

Parallel Transport Frame implementation and example usage - C++ and OpenSceneGraph
C++
5
star
13

cacharr

Matlab class that allows to work with very large matrices through caching; thus avoid matrix allocation out-of-memory error.
MATLAB
5
star
14

rshell-mat

Bash / Shell scripts represented by a Matlab interface class in order to imitate Matlab distributor
Shell
1
star
15

codalgs

coursera etc
C++
1
star
16

cherish-installer

Installer files for Cherish software
1
star