<p>In OpenGL, there are 6 different shader types:</p>

<ol>
<li>Vertex Shader</li>
<li>Tesselation Control Shader</li>
<li>Tesselation Evaluation Shader</li>
<li>Geometry Shader</li>
<li>Fragment Shader (Pixel)</li>
<li>Compute Shader</li>
</ol>

<p>The first 5 are part of the render pipeline and fulfill a very specific purpose in that pipeline. They are executed in ascending order. The shader types 2.-4. are optional and can be skipped. Between those stages, some operations are performed, that are very specific to rendering. Have a look at <a href="https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview" rel="nofollow noreferrer">this link</a> for further information. </p>

<p>The problem here is: Since the rendering pipeline has a very specific purpose (generating an image of pixels), it is very hard to use it and its shaders for something else than rendering. Won't say it is impossible, but it gets certainly harder and harder the less your goal has something to do with pixel generation.</p>

<p>For general-purpose computations, you can use compute shaders. You can basically compute anything there, so this is probably the shader type you are looking for. However, the way you ask your questions gives me the feeling, that you have some misunderstandings on how rendering works in general and you should probably read some literature about how the render pipeline creates an image from 3d data.</p>

<blockquote>
  <p>But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)? </p>
</blockquote>

<p>As written above, generally yes. It is possible to write a shader that does that. But probably not with the same technique as the outline is created in the "pixel case". It is certainly much more complicated.</p>

<blockquote>
  <p>Or in a different example, this image was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?</p>
</blockquote>

<p>Again, yes it is possible for <strong>a</strong> shader to fulfill this task, but you wouldn't use a pixel (fragment) shader for that. You would also need to approach the whole task very differently.</p>

<blockquote>
  <p>Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?</p>
</blockquote>

<p>The shaders of the rendering pipeline are tied to a very specific task and have very specific boundaries on their inputs and outputs. But if you know what you are doing, you can probably hack around those limitations. However, I think it wouldn't make much sense to do so, except you want to prove that you can. 
Instead, you can use a compute shader for any computation, that has nothing to do with rendering.</p>

<p><strong>To sum it up</strong></p>

<p>You can use compute shaders to get other output types than just pixels and images made of pixels. However, calculating basic 2d shapes/curves/vector graphics from 3d data will most likly be fundamentally different than generating a corresponding bunch of pixels from that same data. In conclusion, you can't just turn a switch (change 2-3 lines of code) to select which output you like to have.</p>

CC BY-SA 4.0
2020-04-18T11:17:27.273Z
2020-04-18T11:17:27.273Z
wychmaster
<p>I’m fairly new to shader programs in general but I have a question concerning vector graphics. I understand that a pixel shader can generate the color information to draw some sort of geometry on screen. But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)? </p>

<p>Or in a different example, <a href="https://i.sstatic.net/YvwZq.jpg" rel="nofollow noreferrer">this image</a> was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?</p>

<p>I’ve tried to do some preliminary internet searches but can’t find anything that would answer this type of question. Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?</p>

CC BY-SA 4.0
2020-04-18T07:19:19.357Z
Yes and no. Not the way you think.
joojaa
<opengl><geometry-shader>
Vector graphics output from shader program
andyopayne
# Vector graphics output from shader program

(Asked by: username_0 on 2020-04-17)

I’m fairly new to shader programs in general but I have a question concerning vector graphics. I understand that a pixel shader can generate the color information to draw some sort of geometry on screen. But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)?

Or in a different example, [this image](https://i.sstatic.net/YvwZq.jpg) was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?

I’ve tried to do some preliminary internet searches but can’t find anything that would answer this type of question. Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?

**Tags:** opengl, geometry-shader

> **Comments:**
> **username_1**: Yes and no. Not the way you think.  

---

## 1 answers

### Answer by username_2 on 2020-04-18. Score: 2

In OpenGL, there are 6 different shader types:

1. Vertex Shader
2. Tesselation Control Shader
3. Tesselation Evaluation Shader
4. Geometry Shader
5. Fragment Shader (Pixel)
6. Compute Shader

The first 5 are part of the render pipeline and fulfill a very specific purpose in that pipeline. They are executed in ascending order. The shader types 2.-4. are optional and can be skipped. Between those stages, some operations are performed, that are very specific to rendering. Have a look at [this link](https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview) for further information.

The problem here is: Since the rendering pipeline has a very specific purpose (generating an image of pixels), it is very hard to use it and its shaders for something else than rendering. Won't say it is impossible, but it gets certainly harder and harder the less your goal has something to do with pixel generation.

For general-purpose computations, you can use compute shaders. You can basically compute anything there, so this is probably the shader type you are looking for. However, the way you ask your questions gives me the feeling, that you have some misunderstandings on how rendering works in general and you should probably read some literature about how the render pipeline creates an image from 3d data.

> But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)?

As written above, generally yes. It is possible to write a shader that does that. But probably not with the same technique as the outline is created in the "pixel case". It is certainly much more complicated.

> Or in a different example, this image was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?

Again, yes it is possible for **a** shader to fulfill this task, but you wouldn't use a pixel (fragment) shader for that. You would also need to approach the whole task very differently.

> Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?

The shaders of the rendering pipeline are tied to a very specific task and have very specific boundaries on their inputs and outputs. But if you know what you are doing, you can probably hack around those limitations. However, I think it wouldn't make much sense to do so, except you want to prove that you can.
Instead, you can use a compute shader for any computation, that has nothing to do with rendering.

**To sum it up**

You can use compute shaders to get other output types than just pixels and images made of pixels. However, calculating basic 2d shapes/curves/vector graphics from 3d data will most likly be fundamentally different than generating a corresponding bunch of pixels from that same data. In conclusion, you can't just turn a switch (change 2-3 lines of code) to select which output you like to have.


---

