PCF based on screen pixel Jitter

Source: Internet
Author: User

PCF is nothing more than adding the surrounding pixels, and then taking an average value. the smoothness of the result is directly related to the kernel size.

Next we will give you a hand for the Sawtooth teapot PCF with the stroke:

2x2:

3x3:

4x4:

Of course, the larger the kernel, the better the effect. however, the effect is not obvious to a certain extent, and performance issues must be considered. After all, texture sampling is slow for multiple times. in fact, through jitter, a small amount of sampling can be used to achieve an approximate larger kernel effect. here we use 4 sampling times to simulate the effect of 4x4 PCF. The sample template is as follows:

A register VPOs is added in ps3.0 to take the screen coordinates of the current pixel directly and determine the sampling position based on the parity of the coordinates:

Sampler2d texture0; <br/> float2 finverseviewportdimensions; </P> <p> struct ps_input <br/>{< br/> float2 texcoord: texcoord0; <br/> float2 screenpos: VPOs; <br/>}; </P> <p> float4 ps_main (ps_input input): color0 <br/>{< br/> float2 offset = fmod (input. screenpos, 2.0); </P> <p> float4 color = 0; <br/> color + = tex2d (texture0, input. texcoord + (float2 (-1.5,-1.5) + offset) * finverseviewportdimensions); <br/> color + = tex2d (texture0, input. texcoord + (float2 (-0.5, 0.5) + offset) * finverseviewportdimensions); <br/> color + = tex2d (texture0, input. texcoord + (float2 (-1.5, 0.5) + offset) * finverseviewportdimensions); <br/> color + = tex2d (texture0, input. texcoord + (float2 (-0.5, 1.5) + offset) * finverseviewportdimensions); <br/> color * = 0.25; </P> <p> return color; <br/>}< br/>

The final effect is a very efficient solution used in shadow blur:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.