0

I am trying to render rounded triangles to increase performance. To illustrate what I mean, see the picture below:

enter image description here

I tried in the CPU, now is there a way to move this algorithm somehow to the GPU? I can change the method's code that calls the fragment shader?

By the way if I can do it, then what programming language I need to re-make it to?

I am using an OpenGL 2.1 GPU with just 20GB-30GB memory bandwidth.

Bart
  • 19,692
  • 7
  • 68
  • 77
Fijiwiji
  • 1
  • 1
  • 2
  • 3
    *"trying to render rounded triangles to increase performance"*...what exactly do you mean by that? Could you illustrate? – Bart Dec 17 '12 at 15:29
  • @Bart http://nuwen.net/img/news2006/opengl20060902.png something like that. With that you can render a circle with two triangles and ellipse you can render with four triangles. – Fijiwiji Dec 17 '12 at 15:32
  • You can't change the rasterization, but you could code a fragment shader to kill fragments in order to alter the shape of a triangle. – JasonD Dec 17 '12 at 15:40
  • Why not simply triangulate that shape? That is, split it up into multiple triangles until it sufficiently approximates the rounding? – Bart Dec 17 '12 at 15:44
  • @JasonD Then I can at least create some small API and compile with GLSL the code to get the GPU? – Fijiwiji Dec 17 '12 at 15:47
  • @Bart "I am trying to render rounded triangles **to increase performance**." – Fijiwiji Dec 17 '12 at 15:48
  • @Fijiwiji The shader could would be relatively simple, and it would all be done on the GPU. How you want to utilise it is up to you. – JasonD Dec 17 '12 at 15:49
  • 1
    @Fijiwiji And without any explicit details I have no reason to believe that your performance will be adversely affected by triangulation. – Bart Dec 17 '12 at 15:53
  • @JasonD I don't think I can create 3D rounded triangles with that. 2D would work great like in the image above. – Fijiwiji Dec 17 '12 at 15:54
  • @Bart I don't prefer fifty triangles on one\two triangles with even greater quality. – Fijiwiji Dec 17 '12 at 15:56
  • @Fijiwiji What is a "3D rounded triangle"? A triangle is 2D. If you want some kind of 3D surface, that's different... – JasonD Dec 17 '12 at 16:00
  • @JasonD I mean that it has like a up push in the middle of it and in the Z axis, then if you kill fragments then if you'll look at the triangle from the left of it then you'll see that the triangle hasn't really push up in the middle of it. – Fijiwiji Dec 17 '12 at 16:05
  • Then as others have said, your best bet is subdivision. You could use the GPU to do that, but it depends on your specific requirements. – JasonD Dec 17 '12 at 16:08
  • @JasonD That's what I asked in the question XD. How I can talk (Like OpenGL) to GPU directly... – Fijiwiji Dec 17 '12 at 16:13
  • You can't. You would need to use shaders - either geometry, or maybe the tesselation pipeline (hull/domain shaders). – JasonD Dec 17 '12 at 16:16
  • @JasonD Then how OpenGL works with triangles? The algorithm is in the GPU's core? – Fijiwiji Dec 17 '12 at 17:13
  • Yes, rasterisation is not programmable. Even if it was, it happens after projection, and thus deals effectively in 2D primitives. – JasonD Dec 17 '12 at 17:16
  • @JasonD Then... I can run code that execute fragment shader on GPU atleast? I heard Nividia managed to render rounded triangles. – Fijiwiji Dec 17 '12 at 18:02

3 Answers3

1

I'm not sure exactly what you're up to, but it seems a bit dubious. You can actually end up hurting performance trying to do some of these custom calculations in a shader to render a circle or ellipse.

Modern GPU hardware can push billions of triangles a second. You're probably splitting hairs here.

In any case, if you want to 'fake' the geometry, this may be of interest to you: https://alfonse.bitbucket.io/oldtut/Illumination/Tutorial%2013.html

Hedede
  • 1,133
  • 13
  • 27
Aeluned
  • 769
  • 5
  • 11
  • I didn't mentioned it but I am trying it on OpenGL 2.1 GPU with just 20GB-30GB memory bandwidth. (This GPU used more than 10 years) – Fijiwiji Dec 17 '12 at 15:58
  • @Fijiwiji: Geometry is usually not a memory bandwidth hog. Textures are. – datenwolf Dec 17 '12 at 18:27
  • @datenwolf I just wanted to make you know how this GPU is pounded. If this GPU was new it's bandwidth'll be around 160GB. – Fijiwiji Dec 17 '12 at 18:40
1

Read the paper Resolution Independent Curve Rendering using Programmable Graphics Hardware by Charles Loop and Jim Blinn.

Short version: assuming you have an efficient inside/outside test for your curve, render the enclosing hull shape as triangle(s), use a fragment shader to discard the pixels outside the curve.

Second the concern by Aeluned that transferring the algorithm to the GPU won't automatically make it faster.

Hugh Fisher
  • 2,321
  • 13
  • 8
0
  1. Well on OpenGL 2.1 you do not have geometry shaders (3.2+) so you can forget about GPU.
  2. You can not improve rasterizing performance of convex shapes by your curved triangles
    • complexity of rasterization of any convex polygon is the same as any triangle of the same area
    • the difference is only in:
    • number of passing vertexes
      • memory transfer
      • with geometry shader this will be better with your triangles usage
    • number of boundary lines
      • boundary lines rasterization for filling
      • will be worse with your triangles usage
      • (need to join more triangles instead of single shape polygon)

So its not a good idea to implement this for better performance in your case.

The only thing i can think of to use this for is to ease up manual generation of shapes.

In that case just write a function glRoundedTriangle(....)

  • which generate the correct vertexes,colors,normals,texture coordinates from given input parameters.

how it would looked like is unknown because you did not specify the rounded triangle geometry/shape and/or input parameters (for example 3 points + 3 signed curve radiuses ?)

To improve performance in OpenGL use VBO/VAO

Spektre
  • 49,595
  • 11
  • 110
  • 380