Post-Synthesis of RTT [multi-sample simulated volume light]

Source: Internet
Author: User

Shader hasn't been written for a long time. Last time I used CG to write several shader FOR THE Paster rendering. Stroke and cartoon coloring. If you draw a stroke, first draw a solid background, remove the front, only look inside, and then draw the stroke object, depth detection is less than or equal to pass. In addition, for cartoon coloring, the color is mainly obtained from a 1D Texture Based on the energy of light absorption on the object surface. These items are available in rendermonkey, and there are also many ready-made shader in fxcomposer's shader library. Writing shader can improve your understanding of the rendering process and GPU system. Some shader cannot be used at all. The high requirement of the Shader Model is on the one hand, and the high consumption is on the other. However, some shader can simplify the implementation of many traditional effects, which is practical.

 

OK, the following is a useless shader, purely for entertainment (you can achieve the effect of GPU gems when you are free ).

 

A long time ago, I saw a method on the gpugems about the volume of light, which is hard to remember. The main implementation method is to generate a result similar to radial blur after multiple sampling based on the RTT diagram. After adjustment, the result is as if the light passes through the image.

So I used glsl to write a try in rendermonkey. The effect is fine. First look at the figure

 

 

After adjusting the light intensity and color:

 

 

 

The main PS coloring tool code is as follows:

Uniform sampler2d normalscenetex; <br/> uniform vec2 raypoint; <br/> uniform int samplenum; <br/> uniform float raycastfactor; <br/> uniform float rayexposure; <br/> uniform vec4 raycolor; <br/> uniform sampler2d raycastscenetex; <br/> varying vec2 texcoord; <br/> float getgray (vec3 C) <br/> {<br/> return 0.299 * C. R + 0.587 * C. G + 0.114 * C. b; <br/>}< br/> void main (void) <br/>{< br/> vec4 basecolor = texture2d (raycastscenetex, texcoord ); <br/> float raydist = distance (raypoint, texcoord); <br/> vec2 raydir = raypoint-texcoord; <br/> normalize (raydir ); </P> <p> If (basecolor. A <0.25) <br/>{< br/> float fsum = 1.0; <br/> float samplestep = raycastfactor * raydist/samplenum; </P> <p> // progressive sampling <br/> for (INT I = 1; I <= samplenum; ++ I) <br/>{< br/> // The current sampling position. The farther the current pixel is, the lower the sampling absorption rate. <br/> vec2 samplept = texcoord + raydir * I * samplestep; <br/> float F = 1.0/distance (samplept, texcoord); <br/> basecolor + = raycolor * getgray (texture2d (raycastscenetex, samplept) * f * rayexposure; <br/> fsum + = f; <br/>}</P> <p> // Exposure Control <br/> basecolor/= fsum; <br/>}</P> <p> gl_fragcolor = basecolor; <br/> // vec4 normalcolor = texture2d (normalscenetex, texcoord ); <br/> // gl_fragcolor = vec4 (mix (normalcolor. XYZ, basecolor. XYZ, basecolor. a), 1.0); <br/>}< br/> 

 

In addition, the link to the rendermonkey project file is as follows:

Volumeray. rfx


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.