• Advertisement
Sign in to follow this  

How to mipmap procedural shaders?

This topic is 1519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A general observation for shaders that rely on procedural functions f(u,v) to generate colors is that such shaders may alias so hard at the distance. For example, if f(u,v) generates periodic lines on u and v then on distant surfaces those lines alias strongly (see attachment). If we replace the procedural function with a mipmapped texture lookup then the result improves a lot.

So my question is, is there a generic way to make a function f(u,v) "mipmap" in a pixel shader aside from the texture approach?

 

 

Share this post


Link to post
Share on other sites
Advertisement

What you want is actually anti-aliasing since what you're making is closer to rasterizing than texture mapping.  You can use any of the anti-aliasing techniques that people have been using for years, such as multisampling. You'll just have to implement them in your fragment shader, and depending on how it's written, could be very tricky.

 

Think of each pixel as a tiny little frustum instead of a ray.

Share this post


Link to post
Share on other sites

What you want is actually anti-aliasing since what you're making is closer to rasterizing than texture mapping.  You can use any of the anti-aliasing techniques that people have been using for years, such as multisampling. You'll just have to implement them in your fragment shader, and depending on how it's written, could be very tricky.

 

Anti-aliasing in terms of today's APIs works on geometry edges not on shading.

 

 

Think of each pixel as a tiny little frustum instead of a ray.

 

Yup, that's closer to a sensible approach. du/dv tells you the frequency you're being sampled at... so theoretically you do "multisampling" at higher frequencies and average the results. But I want to know if anyone has smarter/faster ideas than this...

Share this post


Link to post
Share on other sites

not so generic but for lines would be to measure the ddx ddy much like the classic checkboard shader

Share this post


Link to post
Share on other sites
 


What you want is actually anti-aliasing since what you're making is closer to rasterizing than texture mapping.  You can use any of the anti-aliasing techniques that people have been using for years, such as multisampling. You'll just have to implement them in your fragment shader, and depending on how it's written, could be very tricky.

 
Anti-aliasing in terms of today's APIs works on geometry edges not on shading.
 
 

Think of each pixel as a tiny little frustum instead of a ray.

 
Yup, that's closer to a sensible approach. du/dv tells you the frequency you're being sampled at... so theoretically you do "multisampling" at higher frequencies and average the results. But I want to know if anyone has smarter/faster ideas than this...
You need to take care of antialiasing in each fragment, which means calling a "smart" antialiasing-aware fragment shader instead of a naive one. Your shader can be less costly than brute-force pure multisampling; for example, it can generalize and abuse texture mipmapping for your specific needs (more lowpass filtering for increasing fragment depth).

The only possible way to get cheaper but lower quality antialiasing is cheating with intermediate frame buffers: scaling up a properly antialiased small buffer (saving a lot of shader invocations) or fixing the ugly results of your original shader with "morphological antialiasing" or similar postprocessing.

Share this post


Link to post
Share on other sites

For this specific example I would probably write an ad-hoc shader numerically evaluating coverage.

 

The above link looks extremely interesting, I will have to look at it in more detail.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement