DEMO.DESIGN
Frequently Asked Questions
 
оглавление | demo party в ex-СССР | infused bytes e-mag | новости от ib/news | другие проекты | письмо | win koi lat

следующий фpагмент (2)
- Usenet echoes (21:200/1) -------------------------- COMP.GRAPHICS.ALGORITHMS - Msg : 113 of 113 From : vf@shadow.net 2:5030/315 01 Feb 96 16:37:02 To : All 03 Feb 96 04:43:04 Subj : Re: Lens Flare Algorithm Needed -------------------------------------------------------------------------------- X-RealName: Vinnie Falco cjb@trog.dra.hmg.gb wrote: > > Can anyone supply an algorithm, or reference to an article > containing such, for generating a Lens Flare effect on > a 2-dimensional image. > > (Like the effect Photoshop can produce). Photoshop's Lens flare effect is not as complicated as one might think. First of all, there are no equations modelling any type of real-world phenomenon. All they are doing is compositing a series of colored partially opaque rings into the image. The rings are placed along a line passing through the center. If you look carefully, and analyze several specimens of Lens Flare, you will see the same size/color rings drawn every time. In addition, there is a bright spot along the line containing the rings. The bright spot has variable brightness, depending on the parameters, and contains a bunch of anti-aliased lines passing from the center. A brief outline : Choose a point lying inside the image Define a line passing through the center of the image and the chosen point. This line will extend through the center to the opposite side of the chosen point. Distribute several well-defined colored circles along the line, based on a pre-determined algorithm. For example, one possible Lens Flare might look like this : A large thin brown ring at 20% opacity at the center point A medium solid green disc at 15% opacity placed 40% along the way from the center point to the chosen point A small solild brown disc at 20% opacity placed 35% along the way from the center point to the point opposite the chosen point etc... In order to generate the circles, it would be wise to use an anti-aliased circle generation algorithm, and render the circles into a temporary grayscale buffer in memory. Once you have done that, composite the grayscale buffer to the destination buffer using a specified opacity lookup table and a specified color lookup table. A function like the following would be useful : /* VF - NOTE * Call this function once for each color channel in * the destination (e.g. RGB=3, CMYK=4) * */ void blendindopmap ( long rows, long cols, unsigned char *src, /* grayscale image */ long srcRB, /* source rowBytes */ unsigned char *mask, long maskRB, unsigned char *dest, long destRB, unsigned char *olut, /* opacity lookup table */ unsigned char *clut /* color lookup table */ ) { long x, y; srcRB-=cols; maskRB-=cols; destRB-=cols; for(y=rows;y;y--) { for(x=cols;x;x--) { long op, c, m, s; s=*src++; m=*mask++; op=olut[m]; c=clut[m]; *dest++=s + ( ( c - s ) * op ) / 255; } src+=srcRB; mask+=maskRB; dest+=destRB; } } This function composites an indexed image (stored in mask) into a grayscale image (stored in src) and puts the result into a grayscale image (stored in dest). For each pixel value in the mask, the value is used as an index into both a color lookup table and an opacity lookup table. In order to create RGB images using this function, you would have to create three separate color lookup tables and call the function 3 times (BTW this is the KEY to speed!) You can create a nice looking ring by making a radial blend in the mask, and creating an opacity lookup table that only contains a short run of opaque pixels, e.g. gOpLut[256]= { 0, 0, 10, 50, 240, 255, 255, 255, 255, 255, 255, 255, 255, 240, 50, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.... }; Since the remaining entries at the end have an opacity of zero (fully transparent) they will not show up, and your radial blend in the mask will produce a ring!

Всего 1 фpагмент(а/ов) |пpедыдущий фpагмент (1)

Если вы хотите дополнить FAQ - пожалуйста пишите.

design/collection/some content by Frog,
DEMO DESIGN FAQ (C) Realm Of Illusion 1994-2000,
При перепечатке материалов этой страницы пожалуйста ссылайтесь на источник: "DEMO.DESIGN FAQ, http://www.enlight.ru/demo/faq".