简体   繁体   中英

Programming my own triangle rasterization for OpenGL?

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

在此输入图像描述

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.

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

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.

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM