Removing Moire pattern from GLSL shader

Discussion about everything. New games, 3d math, development tips...
Post Reply
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Removing Moire pattern from GLSL shader

Post by bitplane »

I've spent the last two weeks working with an Apple Mac advocate and hacker, I have been exposed to some of the delights of OSX. One of which is the realtime video capture filters, which are a variety of cool shaders.
One that caught my eye is a kind of comic book filter, which splits the image into low res print-like CYM dots of varying sizes, and adds high resolution black using edge detection.. The effect is really cool, so I thought I'd try my hand at making one. So, last night I had a try and came up with this:

Image

Ignore the fact that the dots are cropped and don't overlap neighbouring squares (it's just a proof of concept), and focus your attention to the distortion at large distances-

Image

Now, I'm pretty sure I can't do anything about the Moire effect existing - it is caused by the difference between the pattern of the dots and the pixel fragments. However, I'd like to hide it. I'm guessing I need to know how much space a fragment takes up, its relative size and orientation. Use this value to smooth out the dot-based stuff and replace it with pixels at a certain zoom level.

So the question is, how would I do this? I've heard I can use the derivative functions to work this out, but it's beyond my rudementary mathematics knowledge. Any of you math/shader guys care to explain it in layman's terms please, or point me at an example?

Here's a 16mb xvid avi of the distortion, of course the code will be available when I finish/abandon it, or someone asks for it ;)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Looks like the effect you encounter when you try to render wire mesh fence at some distances. I'd try to play with different bilinear/trilinear/anisotrope filtering settings - or try to "cheat" and blur the texture first.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Yes, that's exactly the problem.
Textures are filtered but I'm not drawing textures, I'm reading from the (unfiltered) texture and drawing 3 circles instead. It's the circles that need filtering.
Their next level of "mip-map" would be a tile of solid colour, which is easy enough to make. I need to know what its mip-map level would be.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

It would be easier to reach a cure if you told us your method, im guessing its a fractuals based method and not a texture LUT with magenta cyan yellow circles method because:

1- ugly effect because the circles are made mathematically per fragment and not mipmapped.
2- cutoff borders (wouldn't happen if the texture lut is used because its totally mod able).

If a texture was used to source the circles, mipmapping minification should make it look a bit better ( i think its way too sharp in the pics unless you have filtering/ ansio on).

one way of reducing this is to inovolve some texture lookup in your math, no matter how simple so mipmapping can help with minifictaion.

Im just guessing here since i dont know how the effect is really done, see me on irc
:wink:
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

hmmm you just replied while i was typing this out, please check on irc :wink:
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

an update in case anyone else comes across these problems..

Answer was in chapter 17 in the orange book-
17.5.1 wrote: // Determine the width of the projection of one pixel into s-t space
vec2 fw = fwidth(TexCoord);
Image

video: http://youtube.com/watch?v=tt2NqS99nmg
Last edited by bitplane on Wed Oct 24, 2007 5:17 am, edited 2 times in total.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Fantatsic
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Post Reply