Plan to kill a Monkey in one day (2)-heat flow disturbance, radial blur

Source: Internet
Author: User

Plan to kill a Monkey in one day (2)-heat flow disturbance, radial blur

If you think you're not doing anything late, you can't, but you still have a lot to do. You're afraid you won't, but you might as well try it! Stop greed, quit arrogance, and guard against rashness. Thank you for trying to practice more. You have to open RM and Word to press on yourself from time to time,

Okay, let's move on to the previous article. As the predecessors have already paved the way, I will be lazy and implement it only. This article also changes from the Blog of Xiaoyao jianke:

1,Heat Flow DisturbanceBai song Distribution

• Everyone is familiar with this atmospheric effect in nature

• Light will bend when passing through different density Media

Melting

• The density of hot air is smaller than that of cold air

• Density affects the refractive index of Media

• When Hot air rises, it will be replaced by cold air, which will change the path of light into the eyes

Some changes in the refractive index will cause distortion of the scenes we see. For details, refer to the following:

• Render scene to RGBA off-screen cache (rendered texture)

• Color write RGB values

• Distortion writes to the Alpha channel (here is only the quick trick of a single rendering effect under RM, and StencilBuffer can be used for marking in practice)

• Draw a full-screen rectangle to the backup Buffer

• Sample the off-screen buffer to obtain the curvature

• Use a disturbance texture to determine the disturbance vector, and offset the original texture coordinates after the curvature is scaled down

• Linearly scalable Poisson distribution based on Disturbance texture coordinates (offset based on Torsion curvature)

Curvature

• Determine the degree to which the current pixel is distorted by Pixel

• When light passes through more gases, the refraction level increases accordingly.

• Distortion increases with the Scene Depth

-At the beginning, clear the Alpha channel of the rendering target to 1.0, indicating the maximum depth.

-Pixel shader writes the depth of each Pixel to the alpha channel.

• A good global distortion solution is provided in depth, but your artists want local control.

• Heat Wave ry can be used to define distortion ranges, such as hot air outlet and jet engine tail

• Heat Wave textures can distort the heat wave's geometric Base

Heat ry&Heat texture

• Pixel curvature source to heat texture

• The curvature is enlarged in depth.

• Use height to further zoom in (texture coordinates) and N. V to avoid stiff Edges

• Curvature is written to Alpha Channel

Full Screen rectangle

• Full-screen rectangles are drawn using off-screen caching (rendered textures) and with disturbance textures as textures

Disturbance textures

• A 2D vector is stored in the Red and Green Channels

• Scroll the texture in two directions of the full screen rectangle and sample it twice

• Average two samples and change the value to the range of [-1.0, 1.0]

• Scale vector with torsion Curvature

• The result is a distorted vector.

Distortion Vector

• Distortion vectors are used to offset original texture coordinates

• The vector size depends on the curvature.

• This new disturbance texture is used to read the off-screen cache.

Increase Poisson distribution

• The fuzzy center is in the center of the disturbed texture coordinate

• The offset is based on the curvature (Perturbation)

DistortedShader

Float4Main (PsInputI ):COLOR

{

// Fetch from perturbation map with scrolling texture coords

Float3VPerturb0 =Tex2D(TPerturbationMap, I. texCoord1 );

Float3VPerturb1 =Tex2D(TPerturbationMap, I. texCoord2 );

// Scale and bias: (color-0.5f) * 2.0fGo back to [-1 ~ 1] range

VPerturb0 = SiConvertColorToVector (vPerturb0 );

VPerturb1 = SiConvertColorToVector (vPerturb1 );

// Average perturbation vectors

Float2Offset = (vPerturb0.xy + vPerturb1.xy) * 0.5f;

// Get distortion weight from renderable texture (stored in alpha)In the RT of the previous Pass

Float4CDistWeight =Tex2D(TRBFullRes, I. texCoord0 );

// Square distortion weight

CDistWeight. a * = cDistWeight.;

// Compute distorted texture cords fPerturbScaleHere is a predefined parameter, which can be used as the intensity of the disturbance offset.

Offset. xy = (offset. xy * cDistWeight. a) * fPerturbScale) + I. texCoord0;

// Fetch the distorted color

Float4O;

O. rgb = sistmsondisc13rgb (tRBFullRes, offset, 1.0f/screenRes. xy, cDistWeight. );

O. a = 1.0f;

ReturnO;

}

The PS Code shows that the basic process is the same as the implementation method of water disturbance in the previous article, but the PoissonDiscl processing method is shown at the end,

Almost all the mathematics textbooks are still honest, right? Okay. First, let's see what the Poisson distribution is.

According to Zookeeper's guidance, let's first take a look at the Shader code. HerePixelSizeIt should be the reciprocal of the external RT size, that is, the uv width of each pixel literally. The Poisson distribution here is to continue the offset at the uv position after the current offset, sampling, neutralization ~~

Increase Poisson distributionShader

Float3SiGrowablePoissonDisc13FilterRGB

(SamplerTSource,Float2TexCoord,Float2PixelSize,FloatDiscRadius)

{

Float3COut;

Float2Poisson [12] = {Float2(-0.326212f,-0.40581f ),

Float2(-0.840144f,-0.07358f ),

Float2(-0.695914f, 0.457137f ),

Float2(-0.203345f, 0.620716f ),

Float2(0.96234f,-0.194983f ),

Float2(0.473434f,-0.480026f ),

Float2(0.519456f, 0.767022f ),

Float2(0.185461f,-0.893124f ),

Float2(0.507431f, 0.0640000f ),

Float2(0.89642f, 0.412458f ),

Float2(-0.32194f,-0.932615f ),

Float2(-0.791559f,-0.59771f )};

// Center tap

COut = tex2D (tSource, texCoord );

For(IntTap = 0; tap <12; tap ++)

{

Float2Coord = texCoord. xy + (pixelSize * poisson [tap] * discRadius );

// Sample pixel

COut + =Tex2D(TSource, coord );

}

Return(COut/13.0f );

}

2,Radial blur

View principle:

Http://www.gamerendering.com/2008/12/20/radial-blur-filter/

The implementation is actually very simple. It is much simpler than the above heat flow disturbance. It determines a central point (such as 0.5, 0.5) and connects a line with the current pixel. take the current pixel as the center, sample the nearby pixels online, and take the average value.

HLSL ):

1. // This texture shocould hold the image to blur.

2. sampler2D Texture0;

3.

4. // some const, tweak for best look

5.Const FloatFSampleDist;

6.Const FloatFSampleStrength;

7.

8.

9. // some sample positions

10.FloatSamples [10] =

11 .{

12.-0.08,

13.-1, 0.05,

14.-0.03,

15.-0.02,

16.-1, 0.01,

17. 0.01,

18. 0.02,

0.03,

20th, 0.05,

21. 0.08

22 .};

23. float4 ps_main (float2 texCoord: TEXCOORD0): COLOR

24 .{

25. // 0.5, 0.5 is the center of the screen

26. // so substracting uv from it will result in

27. // a vector pointing to the middle of the screen

28. float2 dir= 0.5-texCoord;

29. // calculate the distance to the center of the screen

30.FloatDist = length (dir );

31. // normalize the direction (reuse the distance)

32. dir/= dist;

33.

34. // this is the original color of this pixel

35. // using only this wowould result in a nonblurred version

36. float4 color = tex2D (Texture0, texCoord );

37.

38. float4 sum = color;

39. // take 10 additional blur samples in the direction

40. // the center of the screen

41.For(IntI = 0; I <10; ++ I)

42 .{

43. sum + = tex2D (Texture0, texCoord + dir * samples [I] * fSampleDist );

44 .}

45.

46. // we have taken eleven samples

47. sum/= 11.0;

48.

49. // weighten the blur effect with the distance to

50. // center of the screen (further out is blurred more)

51.FloatT = saturate (dist * fSampleStrength );

52.

53. // Blend the original color with the averaged pixels

54.ReturnLerp (color, sum, t );

55 .}

Two parameters: dynamically adjusted

For example, you can add the RM built-in Sin value changed according to Time_X to make the screen show a "clear-> fuzzy-> clear" acceleration effect.

For (int I = 0; I <10; ++ I)

{

Sum + = tex2D (Image, texCoord + dir * samples [I] * fSampleDist * abs (fSinTime0_X ));

}

How is the effect ?! Just do it!

Attached to the two RM projects:

Post-processing underwater disturbance (Poisson distribution not done yet)

/Files/hmxp8/ZephyrTest_01.rar

The ScreenSpaceEffect fx is used directly, and the radial blur is in the MotionBlur.

/Files/hmxp8/ZephyrTest_02.rar

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.