Programming Memoirs

Faking anti-aliasing in CUDA graphic output

Faking anti-aliasing of CUDA content with OpenGL

Recently I’ve been working on a CUDA ray tracing application which uses OpenGL for CUDA graphics output. I was slightly annoyed by the rough, aliased, edges of my output, but I wanted to avoid implementing a fully fledged anti-aliasing solution. This short post described how to fake anti-aliasing in your CUDA output in a highly computationally efficient (and simple) manner by using OpenGL’s texture filtering.

One way to display CUDA output is to render it to an OpenGL PBO, copy it to a texture and texture it on a quad covering whole OpenGL view port, see here for more info. In a typical situation one texture pixel (texel) maps directly to corresponding screen pixel.

However, if you shift the textured quad, or the viewport, slightly, so that there is no direct mapping between texels and pixels you will enforce OpenGL to applying subtle linear filtering to the texture. Thus, you’ll get rid of those nasty aliased edges. See the image for side-by-side comparison.

Shifting the viewport:


float offset = 0.998; // slighly shifted from 1.0
glOrtho(-offset, offset,
           -offset, offset,
           0, 1000);  // zNear, zFar

Remember to have OpenGL texture filtering set to GL_LINEAR for the texture:

GL_LINEAR returns the weighted average of the four texture elements that are closest to the centre of the pixel being textured


GLuint tex; // Texture to which PBO content from CUDA is copied

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  // GL_LINEAR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // GL_LINEAR
glBindTexture(GL_TEXTURE_2D, 0);

Pros:

  • it’s lighting-fast the whole ‘anti-aliasing’ process is done by rasterization hardware of your GPU
  • it’s dead simple to implement — which means little changes to your existing code

Cons:

  • It’s still not true anti-aliasing; thus the image gets slightly blurred also in low-contrast areas (which is not the case with true AA)
  • It’s not a perfect solution — it works best for close to diagonal edges (like to ones on the image). if a given edge is close to being horizontal/vertical the results are far less impressive.

38 ResponsesLeave one →

  1. You actually stated this adequately!
    writing college essays for money [url=https://writingthesistops.com/]good thesis statement[/url] online writing help for college students

    Reply
  2. Really lots of terrific info!
    hire essay writer [url=https://topessayservicescloud.com/]https://topessayservicescloud.com/[/url] writing editing services

    Reply
  3. Kudos! Wonderful information!
    community service essay [url=https://englishessayhelp.com/]https://englishessayhelp.com/[/url] academic ghostwriting services

    Reply
  4. Thanks! An abundance of tips!
    writing a reflective essay [url=https://topessaywritinglist.com/]essaytyper[/url] essay writing service recommendation

    Reply
  5. You made your point!
    civil service essay [url=https://writingthesistops.com/]https://writingthesistops.com/[/url] are essay writing services legal

    Reply
  6. Kudos! I value it!
    college entrance essay [url=https://theessayswriters.com/]essays writers[/url] help writing thesis

    Reply
  7. Regards! Very good stuff.
    great college essays [url=https://quality-essays.com/]college essay checker[/url] christian ghostwriting services

    Reply
  8. You actually suggested it very well.
    how to write an essay about yourself for college [url=https://homeworkcourseworkhelps.com/]homework motivation[/url] custom academic writing

    Reply
  9. You said it nicely..
    review of essay writing services [url=https://paperwritingservicestops.com/]https://paperwritingservicestops.com/[/url] best resume writing services 2020

    Reply
  10. Cheers! Lots of material.
    how to write an interpretive essay [url=https://essayssolution.com/]essays on why i want to go to college[/url] best seo article writing service

    Reply
  11. Good forum posts. With thanks.
    how to write a great narrative essay [url=https://writingthesistops.com/]https://writingthesistops.com/[/url] can you write my assignment

    Reply
  12. Truly all kinds of valuable data!
    how to write an autobiographical essay [url=https://topswritingservices.com/]best cv writing services[/url] essay writing service usa

    Reply
  13. You’ve made your stand pretty well!.
    writing a three paragraph essay [url=https://writingthesistops.com/]https://writingthesistops.com/[/url] professional personal statement writing services

    Reply
  14. Many thanks, Lots of stuff.
    best college essay writing services [url=https://topessaywritinglist.com/]how can i pay someone to write my essay[/url] custom writing reviews

    Reply
  15. Incredible tons of terrific information.
    writes essay for you [url=https://topswritingservices.com/]custom writings[/url] statement writer

    Reply
  16. Awesome write ups. Regards!
    community service college essay [url=https://writingthesistops.com/]thesis writing service uk[/url] how to write a community service essay

    Reply
  17. Superb information. Cheers.
    i need someone to write my essay [url=https://topessaywritinglist.com/]https://topessaywritinglist.com/[/url] wanted freelance writers

    Reply
  18. Thanks a lot. Lots of material.
    great writing 3 from great paragraphs to great essays [url=https://quality-essays.com/]argumentative essay topics[/url] research proposal writing service

    Reply
  19. With thanks! I value it!
    first generation college student essay [url=https://homeworkcourseworkhelps.com/]calvin and hobbes homework[/url] is there a website that writes essays for you

    Reply
  20. Cheers! I enjoy it.
    using essay writing service [url=https://homeworkcourseworkhelps.com/]homework help cpm[/url] top professional resume writing services

    Reply
  21. Wow a good deal of superb info.
    how to write a satirical essay [url=https://paperwritingservicestops.com/]rainforest writing paper[/url] academic essay writing service

    Reply
  22. Kudos. A lot of posts.
    how to write an essay for college admission [url=https://quality-essays.com/]https://quality-essays.com/[/url] professional cv and resume writing services

    Reply
  23. You expressed this really well!
    how to write a informative essay [url=https://topessayservicescloud.com/]https://topessayservicescloud.com/[/url] admission essay writing services

    Reply
  24. Thank you! I appreciate it!
    things to write an argumentative essay on [url=https://essayssolution.com/]mit college essay[/url] thesis writing services

    Reply
  25. You revealed it adequately!
    how to write a good essay for college [url=https://homeworkcourseworkhelps.com/]homework help[/url] dissertation writing help

    Reply
  26. You actually explained it very well.
    can someone write my essay for me [url=https://englishessayhelp.com/]best essay websites[/url] essay writing service review

    Reply
  27. Kudos. I enjoy it!
    write essay [url=https://topessaywritinglist.com/]essay writer[/url] cheap custom writing

    Reply
  28. You made the point!
    can i get someone to write my essay [url=https://writingthesistops.com/]https://writingthesistops.com/[/url] help with writing a personal statement

    Reply
  29. Appreciate it! Ample facts.
    how to write an essay to get into college [url=https://homeworkcourseworkhelps.com/]how to do homework fast[/url] hiring a writer

    Reply
  30. Nicely put. Thanks a lot. funny college application essay [url=https://quality-essays.com/]argumentative essay topics[/url] disseratation

    Reply
  31. I am sorry, it does not approach me. Who else, what can prompt?


    It is remarkable, it is very valuable phrase safe moira dela torre lyrics, private ryan 2014 soca mix, [url=http://prayer-in-c.mp3juices.red/]mp3juices c[/url] alaine lucky you mp3

    Reply
  32. I am sorry, it does not approach me. Who else, what can prompt?


    It is remarkable, it is very valuable phrase safe moira dela torre lyrics, private ryan 2014 soca mix, [url=http://prayer-in-c.mp3juices.red/]mp3juices c[/url] alaine lucky you mp3

    Reply
  33. I am very grateful to you. Many thanks.


    Effectively? new virginity, virginity s, [url=https://first-love-agency.com/]sell innocence agency[/url] virginity hit

    Reply
  34. Has casually come on a forum and has seen this theme. I can help you council. Together we can find the decision.


    Useful piece stream online tv live, live ren tv stream, [url=https://liveschauen.com/5-dmax-live-stream-kostenlos-online-ohne-anmeldung.html]https://liveschauen.com/5-dmax-live-stream-kostenlos-online-ohne-anmeldung.html[/url] live tv stream torrent

    Reply
  35. Very curiously :)


    I can not take part now in discussion – it is very occupied. I will be free – I will necessarily express the opinion. filme hd subtitrate hd, video hd filme online и [url=https://seehd.space/]SeeHD[/url] hd filme runterladen

    Reply
  36. Let’s talk on this theme.


    Absolutely with you it agree. In it something is also idea excellent, agree with you. ganze filme hd, filme online 720p hd или [url=https://movie4k.cx/films-genre-stream/krimi/]https://movie4k.cx/films-genre-stream/krimi/[/url] hd filme 3d

    Reply
  37. I think, what is it — a false way. And from it it is necessary to turn off.


    What necessary phrase… super, remarkable idea k models, milf models или [url=https://lux-escort-paris.com/fr/]post here[/url] hot models

    Reply
  38. To diagnose erectile dysfunction, the doctor will ask questions about the symptoms and medical history.

    Reply

Leave a Reply