Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3871818
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:51:37+00:00 2026-05-19T21:51:37+00:00

I have a problem that I’m trying to optimize. I’m reproducing OpenGL functions and

  • 0

I have a problem that I’m trying to optimize. I’m reproducing OpenGL functions and my current problem is rasterizing n-pointed shapes and blending the colors based on the points.

The raster is stored in a 1 dim array of bytes of length Screen.Width * Screen.Height * 3

My implementation is quite slow and I want to optimize it a little (well, a lot). I visit each pixel in the shape and take the distance from each point (using Sqrt(x^2 + y^2), which is where things seem to be slow) and use the distance and the vert’s color to determine the color for that specific pixel.

I know there is a faster way to do this. Any help would be excellent!
Oh, I’m working in C# btw.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T21:51:37+00:00Added an answer on May 19, 2026 at 9:51 pm

    let’s assume you have a (good) reason not to use OpenGL or Directx or even GDI+.

    I’m not sure if I really understand the graphical primitive you are trying to rasterize. I assume it’s a polygon with n points. Interpolating color inside such a shape is not completely trivial, since you have different approaches to do this. So the question is, what do you want?

    Think of the differences in convex and concave (or even self-intersecting) polygons. It’s not really clear what the result “should” look like. That’s why graphics hardware stops worrying about anything else but triangles. I suggest you do (almost) the same.

    Interpolating colors inside a triangle is pretty easy and unambiguous. The buzzword to google for is baryzentric coordinates.

    So, the remaining question is how to triangulate your polygon.

    • For convex polygon you can simple once interpolate the color for the mid-point using an interpolation similar to the one I assume you are currently using for all points. Then span triangles from that mid-point to the points of your shape and interpolate inside these.
      You need the mid-point for getting the right colors. Think of a quad: the upper-right and lower-left corner colored in red and the other two corners colored in blue. Now, you have two possibility for splitting the quad into two trianges and depending on which one you use there will be a diagonal line of constant color (either red or blue). But if you insert the mid-point with an interpolated color (something like a dark magenta) everything looks fine (like you were using bilinear interpolation).

    • For self-intersecting polygons things are worse than anyone would like it. First manually determine the intersections, split the polygon in non-self-intersecting polygons and then handle each polygon for itself (calculate the mixed color for the new points introduced by the self-intersetions, like you do now).

    • For concave polygons you need to split the polygon into convex pieces and then handle these as described above. But this will change the color interpolation result! So you need to ensure that the color inside the polygon (at the edges of the cutted pieces) is correct. Therefore you need to introduce new points inside the polygon holding interpolated colors, similar to the idea of the mid-point for convex polygons. The best way to do this, is to calculate the voronoi cells of the points forming the polygons. The corner-points of these cells should be good interpolation points.

    I hope I was able to be somewhat clear on how I would handle your problem.
    It is possible to do all these things, but is it really worth the effort? Like “Cody Gray” said: why reinventing something that complicated?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.