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