GithubHelp home page GithubHelp logo

zacklocx / shader-3dcurve Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vicrucann/shader-3dcurve

0.0 1.0 0.0 426 KB

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

Home Page: http://vicrucann.github.io/tutorials/osg-shader-3dlines/

License: MIT License

CMake 2.48% GLSL 52.19% C++ 45.33%

shader-3dcurve's Introduction

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.

shader-3dcurve's People

Contributors

bogdanni avatar vicrucann avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.