Jump to content
How to Install Plugins ×

Sparkle! Plugins (v2.6; Updated: 10/31/2007)


kshotts

Recommended Posts

MODERATORS NOTE:  This effect is incompatible with Paint.NET 4.0x

 

Plugin Downloads
The plugins are now attached to this post instead of downloading from my site... (I'm going through a redesign and nuked the links... sorry!)
Sparkle.zip
Madjik's Sparkle plugin

Update 10-31-2007
Happy Halloween!

Lots of Changes:
* As obvious above, revamped UI
* Added additional shape: Square (rotated diamond)
* Added "Rainbow Color" option (it's not perfectly what I wanted, but it works... based on the intensity of the pixel, a rainbow-colored hue is added; so the shape goes through red, green, blue, etc. depending on its intensity.)
* Added "Use Selection to Render Glitter" option that lets you specify exactly where you want an individual piece of glitter. If no selection, then the glitter fills the image. Along with this option comes the X/Y/Size adjustment parameters that let you adjust the position and size of this rendered glitter (it's really hard to get the selection exactly centered over the point desired). Note: this option uses the primary color - NOT the pixel in the center of the selection.
* Re-ordered sliders a bit; threshold/probability go together.
* Vary Size According to Pixel is now "Adjust Size According to Intensity"
* Enhanced shape selection list box - includes description and formulas
* Enhanced performance (depends on shape) by avoiding pixel blend operations on zero-value pixels. For flares this really helps the speed out (at least on my machine)
* For those moments where you really pooch things by picking bad settings, there is a progress bar and a STOP button that appears during rendering when previewing. You can click STOP and kill the current operation, or just watch the progress bar (if that helps). If you change any option while rendering the rendering will stop. Most importantly, it will NOT begin re-rendering with your new setting - it just halts the current operation. Change the value again, or uncheck/check Preview again to restart rendering. Even with that quirk at least you can get out of a forever operation without killing the process. (STOP does NOT work when rendering based on the selection; since there's only one flare being rendered, the operation is likely to be over quickly, so STOP is not supported in that configuration.)
* The effect is now a single-threaded effect due to the previous point - lots of hacks going on to allow the "panic" STOP button.
* Modified the Average blend operation to be more useful
* Added Weighted Average and Weighted Average (Alternate) blend operation
* Modified Multiply Blend operation a bit
* Enjoy & Have Fun!

Update 09-23-2007

Changes:
* Added additional shapes, including a 45 degree rotated flare, an eight-spoke flare (45 + 0 degree rotated flare), and a flare combo which picks 0 degree rotated flare 50% of the time and 45 degree rotated flare the other 50% of the time
Modified GUI
* Instead of the previous trackbars, the GUI uses an interface similar to Paint Shop Pro: the bar underneath the text box is a slider. It can be clicked/dragged to select values just like a trackbar. Also added a "rnd" button to many of the options - click to get a random number for the given control. (The only control without rnd is the probability control; this is to prevent the number generated being so high that the computer goes nuts trying to create the glitter)
* Seed gets the new slider control too, so you can randomly pick a seed, as well as select a specific seed.
* Added version/date string on the GUI so you can tell which version you've got
* Changed "Brightness" to "Intensity"

Update 09-19-2007

Found under Render --> Glitter (replaces my previous Glitter plugin, so if you prefer that version, make a backup before downloading!), this plugin lets you generate glowing spheres, diamonds, and flares, with lots and lots of parameters (as evidenced in the above screenshot).

A short description of each option:

Shape: Determines the shape of the glitter. Available shapes are circle, diamond, and two kinds of flares.
Threshold: As always, specifies the minimum value of any pixel (in R,G, or B, or A overall) before further processing occurs.
Maximum Size: Maximum size of the glitter
Minimum Size: Minimum size of the glitter. NOTE: If these two values are different, the system will generate a glitter with a random size between the minimum and the maximum. The only way to generate glitter of a consistent size is to make the two values equal.
Probability: For each pixel that is going to be processed, this is the probability it will be processed. For images with LOTS of pixels that'll be processed, use a low probability (like .010); for an image with only a few pixels that will be processed, use a high probability (like 20).
Brightness: Adjusts the brightness of the glitter, up to four times.
Blend Mode: Determines the type of blending used when rendering the glitter. Available modes: Overwrite, Add, Subtract, Multiply, and Average. "ADD" produces some of the best results, though "Ovewrite" can generate very cool results when using Circle shapes and large sizes (resulting image is similar to molecules... very cool). Subtract works best on bright content (otherwise the glitter isn't very visible). Multiply doesn't do a whole lot at the moment... and average does an average between the area and the glitter, not sure what this can be used for.
Seed: Determines the random # seed. Assuming the probability and the threshold aren't changed, you can modify brightness and other options without changing the arrangement of glitter by keeping this number the same.
Process Center Pixel: if checked, the center pixel is processed. This means that it is blended with itself. If the blend mode is Add or Subtract or Multiply, then the pixel is modified (Add produces a brighter pixel). Sometimes desirable, sometimes not.
Vary Size Based On Value: This varies the size of the glitter based upon the value of the pixel being processed (i.e., a bright pixel produces a brighter piece of glitter). If not checked, the glitter varies between Minimum size and Maximum size irregardless of value.

Important Note: Since some options can consume significant CPU time (if lots of glitter ends up being drawn), this plugin comes with a safety: it only renders if "Preview" is checked, or when "OK" is pressed. While this won't stop the plugin from consuming a lot of CPU with bad settings, it does at least prevent just accessing the plugin for the first time on any image from nuking the CPU. For this reason, Preview does not save its state - it must be checked each time it is used to enable real-time updates.


Update 09-17-2007

Madjik is AWESOME! Some very cool examples of his plugin based on the above is at http://paintdotnet.forumer.com/viewtopic.php?p=99688&sid=5311c042169fd8b9aaa3a0fcbc7dde25#p99688. To copy shamelessly from his post:
 

...
I'm calling flaRe the circle and flaKe the star.

The effect is in the submenu Distort.

From the codelab of kshotts
and another code I'm working on,
I've made this plugin :
==> Here is the DLL <==

==> Here is the source of the DLL <==
____________________________________________

To install:
Close Paint.net
Unzip and (re)place the DLL in your Effect folder usualy: C:/Program Files/Paint.NET/Effects
____________________________________________

The user interface:

sparkleUI.png

__Brightness Threshold (20,255, default=100) increase the value to select only the brightest pixels.
__Maximum Glitter Size (0,200, default=50) maximum (if random checked) radius.
__Glitter Possibility (0,100, default=20) Possibility (0=none, 100=all) for a bright pixel to receive a glitter.

__Flare/Flake ratio (0,100, default=50) 0=only flares, 100=only flakes, other=ratio between flares & flakes.
__Flake normal/invert ratio (0,100, default=50) 0=only normals, 100=only inverts. Normals are brighter in the center.
__Flare normal/invert ratio (0,100, default=50) 0=only normals, 100=only inverts. Normals are brighter in the center.

__Flake number of vertices (0,400, default=8) Quantity of vertices for the flake (star).
__Flare number of vertices (0,400, default=0) Quantity of rays to draw for the flare (0=perfect circle).

__Random size (default=checked) if checked all glitters have a random radius up to the selected maximum size. Else they all have the same size to the maximum.
____________________________________________

Some examples:

Original model:
sparkles0.jpg

Only flakes:
sparkles1.jpg

Only flares:
sparkles2.jpg

INFORMATION:
__The glitters are created from the top-left corner to the bottom-right corner. The last one overwrites the first one.
__A spot with a small radius is made with several pixels and each pixel of the spot could receive a glitter.

WARNING: Don't use this plugin with a white image or Brightness Threshold with a too small value:
each pixel is considered as bright the CPU will do tons of calculation!

So again, please save your work before trying any new plugin/setting...




Update

Created two new plugins: Stars and Glitter.


Sparkle Stars: Located under Render -> Stars, is a lot like Add Noise, except that it is a little more suited to sparse starfields, IMO. The controls are a little wonky, yeah, but the default settings should give a pretty good example. I'd suggest having your primary color be white and fill the background black to see anything of interest... haven't tried it with other settings... should be interesting tho! "Star Probability" indicates how likely any pixel is to become a star; 1000 is equivalent to 10%. "Intensity" affects how bright the resulting stars are; the higher the number the lower the brightness; 1500 seems to do a decent job. "Saturation" indicates whether the stars can have color or not; 255 = lots of color, 0 = grayscale.

Sparkle Glitter: Located under Render -> Glitter, is a work in progress - pretty much like all the other things here :-) Be careful with it - the wrong setting can cause your computer to think a VERY long time...

Sparkle Glitter has three settings: "Brightness Threshold" (default 200) selects only pixels with a value (in R, G, or B channel) greater than the threshold. (It also expects Alpha to be greater than threshold). "Maximum Glitter Size" (default 100) indicates how large the glitter can become. However this doesn't mean every glitter placed on the image will be this size - there's a lot of randomness going on underneath so that the glitter can be anything from 0 (none) to the full size. "Glitter Possibility" is the change that any pixel that meets the threshold requirements will become a glitter pixel. Keep this low images with lots of pixels that would satisfy this requirement... and by low, I mean between 5 and 15. On smaller images with fewer pixels this can go up much higher, but the small values work best on large images. The default is 5.

Glitter takes a few seconds to compute the image before it renders it on-screen, and I'm certain I'm not really doing it the right way, but it was the best I could come up with at the moment to get around Paint.NET's pipelining of the image... Unfortunately this brings with it its own share of bugs... namely when anything less than the entire image(/selection) is on screen, well... it doesn't listen to your changes.... I will post code below and see if anyone else can think of a decent solution... (The problem is in determining when I'm rendering the very first time... I tried to do that by assuming the first thing rendered was the top left of the selection, but that isn't always true... :-( )

Just remember: for best performance of Glitter, keep the threshold high, the glitter size reasonable (especially if you intend to process a lot of pixels over the threshold) and keep the possibility low (within 5-15).


I've created a few quick & dirty plugins that add a "glow"/"flare" effect for use in generating things like starfields, etc. The image below shows both plugins in action:


I've also created a Glitter and Stars plugin; glitter is shown below:


There are three parameters for Flare/Glow that controls the strength of the effect:

Brightness Threshold (0-255): This parameter indicates what level of brightness should be used as the trigger to cause the effect. Pixels with a brightness (in any channel, in addition to requiring the Alpha channel to be at least this level) higher than the value indicated will be processed and those that are not will be left alone (although potentially blended into the glow/flare from another high-value pixel). Note that the lower this value, the more pixels will be picked up and blended, resulting in lower brightness overall.

Maximum Flare Size (0-100): This controls the size of the flare/glow. The larger this size, the slower the plugin runs... 5-10 are decent values, anything larger takes a LONG time. Also note that the number of high-level pixels within range of the current pixel will dictate the brightness of the flare (more means less bright).

Brightness (0-100): This is a simple multiplier; it multiples the final result by the value specified. A value of two doubles the brightness, etc. The brightness is capped at white, so there should not be any odd colored pixels if the brightness is pushed to far, only a very white image.

Neither is perfect, granted, and it's pretty slow. But it's version 1, and it worked for what I wanted it to do, which was give a little ambience to a starfield.

 

MODERATORS NOTE:  This effect is incompatible with Paint.NET 4.0x

Link to comment
Share on other sites

I figured out part of the slowness, so I've reposted. It should be MUCH faster now for small sizes. Larger sizes are still slow. Hopefully it'll work better for you now :-)

Link to comment
Share on other sites

Source code; the difference between glow and flare is simply an addition instead of multiplication on the line where the weight is calculated. A lot is no doubt wrong here... being sick will do that to you! ;-)

Not sure how to speed it up much more in its current incarnation, seeing that it has to sum the entire matrix of size^2 pixels (hence why it quickly slows down), although I'm sure there are more efficient and better ways to do what I'm doing! :-)

int Amount1=220;// [0,255] Select Brightness Threshold
int Amount2=5;// [0,100] Maximum Flare Size   
int Amount3=1;// [0,100] Brightness

void Render(Surface dst, Surface src, Rectangle rect)
{
 int Threshold = Amount1;
 int MaxSize = Amount2;
 int Brightness = Amount3;
 /**********************************************************************************
  *
  * SPARKLE: Flare plugin for Paint.NET Codelab
  *    
  *
  **********************************************************************************

  This plugin "sparkles" the image by taking certain pixels above a threshold and then
  "blurring" them and brightening them across a random area of the image. Pixels below
  the threshold are left untouched, though they may be blended into the remaining result.

  Version 1.0
  Author: Kerri Shotts

  Version 1.1
  Changes: made it faster by removing the check if the pixel was visible. Still slow
   on high values, but much more tolerable!
  **********************************************************************************/

 PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);

 // Delete any of these lines you don't need
 Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

 ColorBgra CurrentPixel;
 ColorBgra LookPixel;

 float R = 0;
 float G = 0;
 float B = 0;
 float A = 0;
 long AvgCount = 0;

 for(int y = rect.Top; y < rect.Bottom; y++)
 {
   for (int x = rect.Left; x < rect.Right; x++)
   {
     CurrentPixel = src[x,y];

     int size = MaxSize;
     float mult = (int)(size*1.5);
     float Weight = 0;

     R = CurrentPixel.R; //0;
     G = CurrentPixel.G; //0;
     B = CurrentPixel.B; //0;
     A = CurrentPixel.A; //0;
     AvgCount = 1;

     for (int y1 = Math.Max(y-size,selection.Top); y1 <= Math.Min(y+size,selection.Bottom-1); y1++ )
     {
       for (int x1 = Math.Max(x-size,selection.Left); x1<= Math.Min(x+size,selection.Right-1); x1++)
       {
         LookPixel = src[x1,y1];
         if (   (LookPixel.A > Threshold) &&
              ( (LookPixel.R > Threshold) ||
                (LookPixel.G > Threshold) ||
                (LookPixel.B > Threshold) )
              )
         {
           Weight = (mult / Math.Max(1,( Math.Abs(x-x1) * Math.Abs(y-y1) )));

           R = R + ((LookPixel.R * (Weight) + CurrentPixel.R * (Weight))/mult);
           G = G + ((LookPixel.G * (Weight) + CurrentPixel.G * (Weight))/mult);
           B = B + ((LookPixel.B * (Weight) + CurrentPixel.B * (Weight))/mult);
           //A = A + (LookPixel.A * (Weight) + CurrentPixel.A * (Weight))/mult),0);
           AvgCount = AvgCount + 1;
         }
       }
     }
     if (AvgCount > 1) {
       CurrentPixel.R = (byte) (Math.Min(255,R*Brightness/AvgCount));
       CurrentPixel.B = (byte) (Math.Min(255,B*Brightness/AvgCount));
       CurrentPixel.G = (byte) (Math.Min(255,G*Brightness/AvgCount));
       CurrentPixel.A = (byte) src[x,y].A;
     }
     dst[x,y] = CurrentPixel;
   }
 }
}

Link to comment
Share on other sites

Ill download this after it gets a performance boost. I only work with large images now. It looks great, and I see myself using this for some future stuff, but I hate waiting.

I'm still alive!

Link to comment
Share on other sites

Suggestion: You should make the edges softer.

edgeil9.png

edges2ta8.png

edges3hn8.jpg

Just some kind of blurring or feathering. At the moment it doesn't look that natural. :wink: Maybe I use the wrong settings, but it is still too slow for me to test every possible setting.

And the glow is nice. :D

Link to comment
Share on other sites

Yeah... I want to. Maybe now that my brain is a little more turned on I'll be able to figure out how to make it the way I really wanted it to be... For now it doesn't like a lot of pixels close together... it works best on sparse images (like stars), but technically it should work... I've got something wrong with the averaging mechanism, I think...

Also, anything of Brightness > 1 will definitely give the effect, since the plugin only processes size by size pixels; Brightness > 2 tends to give marked boundaries between where the effect worked and where it didn't. Another thing I want to work on....

Maybe soon I'll have a fix :-)

Link to comment
Share on other sites

Maybe soon I'll have a fix :-)

For the beginning it is already good. :D

If there is any way to make it reffering to the layer down the current one, this would be the solution. It would render the stars and so on (in my mind on a transparent layer on top of the picture) and you could just to the blur manually, and this would remove all ugly edges. I have no idea if this is possible.. :?

BTW, shouldn't these plugins go to render? In my eyes they don't distort the image, they render something new... I don't know and to be honest it doesn't mind in which submenu they are.

Maybe you should remove the exclammation marks. They just don't fit into the UI (this is my personal opinion). Also it would be nice if someone with professional knowledge of coding would spend a little time with the source, speedups would be a great improvement.

Link to comment
Share on other sites

A couple more goodies, just because my brain wouldn't let things go.... They aren't perfect, by any means, but they are a little more sane for large images (at least on my computer)...

Sparkle_Stars

Sparkle_Glitter

Sparkle Stars: Located under Render -> Stars, is a lot like Add Noise, except that it is a little more suited to sparse starfields, IMO. The controls are a little wonky, yeah, but the default settings should give a pretty good example. I'd suggest having your primary color be white and fill the background black to see anything of interest... haven't tried it with other settings... should be interesting tho! "Star Probability" indicates how likely any pixel is to become a star; 1000 is equivalent to 10%. "Intensity" affects how bright the resulting stars are; the higher the number the lower the brightness; 1500 seems to do a decent job. "Saturation" indicates whether the stars can have color or not; 255 = lots of color, 0 = grayscale.

Sparkle Glitter: Located under Render -> Glitter, is a work in progress - pretty much like all the other things here :-) Be careful with it - the wrong setting can cause your computer to think a VERY long time...

Sparkle Glitter has three settings: "Brightness Threshold" (default 200) selects only pixels with a value (in R, G, or B channel) greater than the threshold. (It also expects Alpha to be greater than threshold). "Maximum Glitter Size" (default 100) indicates how large the glitter can become. However this doesn't mean every glitter placed on the image will be this size - there's a lot of randomness going on underneath so that the glitter can be anything from 0 (none) to the full size. "Glitter Possibility" is the change that any pixel that meets the threshold requirements will become a glitter pixel. Keep this low images with lots of pixels that would satisfy this requirement... and by low, I mean between 5 and 15. On smaller images with fewer pixels this can go up much higher, but the small values work best on large images. The default is 5.

Glitter takes a few seconds to compute the image before it renders it on-screen, and I'm certain I'm not really doing it the right way, but it was the best I could come up with at the moment to get around Paint.NET's pipelining of the image... Unfortunately this brings with it its own share of bugs... namely when anything less than the entire image(/selection) is on screen, well... it doesn't listen to your changes.... I will post code below and see if anyone else can think of a decent solution... (The problem is in determining when I'm rendering the very first time... I tried to do that by assuming the first thing rendered was the top left of the selection, but that isn't always true... :-( )

Just remember: for best performance of Glitter, keep the threshold high, the glitter size reasonable (especially if you intend to process a lot of pixels over the threshold) and keep the possibility low (within 5-15).

Anyway - here's a sample of Glitter:

GlitterExample.jpg

And the code...

int Amount1=200; // [0,255]Select Brightness Threshold
int Amount2=100; // [0,100]Maximum Glitter Size    
int Amount3=005; // [0,500]Glitter Possibility
Random rNum = new Random(0);
bool randomness = true;
int FirstTime = 0; 
Surface tmp;

void Render(Surface dst, Surface src, Rectangle rect)
{
 int Threshold = Amount1;
 int MaxSize = Amount2;
 double Brightness = 1;//(double)Amount3/100;
 double Possibility = (double)Amount3/1000;

 // Delete any of these lines you don't need
 Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

 ColorBgra CurrentPixel;
 ColorBgra OriginalPixel;

 int top = selection.Top;
 int left = selection.Left;
 int bottom = selection.Bottom;
 int right = selection.Right; 

 int itop;
 int ileft;
 int ibottom;
 int iright;

 double val;

 int xdif;
 int ydif;

 double Weight = 0;
 int size = MaxSize;
 double Divi = 1;
 if (rect.Top == selection.Top && rect.Left ==selection.Left)
 {
   FirstTime = 0;
 }
 FirstTime = FirstTime + 1;
 if (FirstTime==1)
 {
   try
   {
     tmp.Dispose();
   }
   catch
   {
   }
   tmp = new Surface( src.Width, src.Height );

   for(int y = top; y < bottom; y++)
   {
     for (int x = left; x < right; x++)
     {
         tmp[x,y] = src[x,y];
     }
   }
   for(int y = top; y < bottom; y++)
   {
     for (int x = left; x < right; x++)
     {
       CurrentPixel = src[x,y];

       if ( ( CurrentPixel.A > Threshold ) &&
          ( ( CurrentPixel.R > Threshold ) ||
            ( CurrentPixel.G > Threshold ) ||
            ( CurrentPixel.B > Threshold )
          ) && ( rNum.Next(0,(selection.Width * selection.Height)) <((selection.Width*selection.Height)*Possibility) ))
       {
         if (randomness) { size = rNum.Next(0,(MaxSize * (((Math.Max(Math.Max(CurrentPixel.R,CurrentPixel.G),CurrentPixel.)) - Threshold)/(255-Threshold))); }
         if (size > 1)
         {
           itop = y-size;
           ileft = x-size;
           iright = x+size+1;
           ibottom = y+size+1;
           if (itop < top) { itop = top; }
           if (ileft < left) { ileft = left; }
           if (iright > right) { iright = right; }
           if (ibottom > bottom) { ibottom = bottom; }
           for (int y1 = itop; y1 < ibottom; y1++ )
           {
             for (int x1 = ileft; x1< iright; x1++)
             {
               xdif = Math.Abs(x1-x);
               ydif = Math.Abs(y1-y);

               val = (((size^2)-(Math.Sqrt(size)))-(xdif * ydif)) /Brightness;
               if (x1==x || y1==y)
               {
                   val = val - (Math.Max (xdif, ydif)/(Brightness*2));
               }
               val = val * (255/size) ;
               if (val<0)
               { val=0; }
               if (val>255)
               { val=255; }


               OriginalPixel = tmp[x1,y1]; 
               OriginalPixel.R = (byte)((double) Math.Min(255,((OriginalPixel.R  + (CurrentPixel.R * (val/255))))));
               OriginalPixel.G = (byte)((double) Math.Min(255,((OriginalPixel.G  + (CurrentPixel.G * (val/255))))));
               OriginalPixel.B = (byte)((double) Math.Min(255,((OriginalPixel.B  + (CurrentPixel.B * (val/255))))));
               tmp[x1,y1] = OriginalPixel; 
             }
           }
         }
       }
     }
   }    
 }
 for(int y = rect.Top; y < rect.Bottom; y++)
 {
   for (int x = rect.Left; x < rect.Right; x++)
   {
       dst[x,y] = tmp[x,y];
   }
 }
}

Link to comment
Share on other sites

There's a link to this post on the first post...but I agree, a proper download link would be helpful. :-)

Oh, and AWESOME plugin! :-D

 

The Doctor: There was a goblin, or a trickster, or a warrior... A nameless, terrible thing, soaked in the blood of a billion galaxies. The most feared being in all the cosmos. And nothing could stop it, or hold it, or reason with it. One day it would just drop out of the sky and tear down your world.
Amy: But how did it end up in there?
The Doctor: You know fairy tales. A good wizard tricked it.
River Song: I hate good wizards in fairy tales; they always turn out to be him.

Link to comment
Share on other sites

Stars doesn't work, it starts on the top maybe 10% of the image and renders the rest of the image black.

Really? What settings are you using? Size of image? Since I've only tested against a black background with white primary color, does it work with that?

Link to comment
Share on other sites

I used default, I tried black background with white color, it seems to be random, it only worked once, other times it did the following, randomly placing the lines and stopping randomly.

click to see

Stars doesn't work, it starts on the top maybe 10% of the image and renders the rest of the image black.

Really? What settings are you using? Size of image? Since I've only tested against a black background with white primary color, does it work with that?

Link to comment
Share on other sites

The Glitter plugin is gorgeous! :D

One suggestion: "Stars" should be renamed to "Starfield". There is already a stars plugin (in render) and "starfield" would express the intention of the plugin in a better way I think.

And not to forget: Thanks!

Link to comment
Share on other sites

I'm made a mix between your Code and another code another code I'm working on to do this codelab:

int Amount1=200; // [0,255]Select Brightness Threshold
int Amount2=100; // [0,100]Maximum Glitter Size    
int Amount3=005; // [0,500]Glitter Possibility
Random rNum = new Random(0);
bool randomness = true;
int FirstTime = 0; 

void Render(Surface dst, Surface src, Rectangle rect)
{
 int Threshold = Amount1;
 int MaxSize = Amount2;
 double Possibility = (double)Amount3/1000;

 PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
 Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();

 ColorBgra CurrentPixel;

 int top = selection.Top;
 int left = selection.Left;
 int bottom = selection.Bottom;
 int right = selection.Right; 

 int size = MaxSize;
 if (rect.Top == selection.Top && rect.Left ==selection.Left)
 {
   FirstTime = 0;
 }
 FirstTime = FirstTime + 1;
 if (FirstTime==1)
 {
   for(int y = top; y < bottom; y++)
   {
     for (int x = left; x < right; x++)
     {
       dst[x, y] = src[x, y];
     }
   }
   for(int y = top; y < bottom; y++)
   {
     for (int x = left; x < right; x++)
     {
       CurrentPixel = src[x,y];

       if ( ( CurrentPixel.A > Threshold ) &&
          ( ( CurrentPixel.R > Threshold ) ||
            ( CurrentPixel.G > Threshold ) ||
            ( CurrentPixel.B > Threshold )
          ) && ( rNum.Next(0,(selection.Width * selection.Height)) <((selection.Width*selection.Height)*Possibility) ))
       {
         if (randomness) { size = rNum.Next(0,(MaxSize * (((Math.Max(Math.Max(CurrentPixel.R,CurrentPixel.G),CurrentPixel.)) - Threshold)/(255-Threshold))); }
         if (size > 1)
         {
           DrawFlaKe(dst, src, selectionRegion, x, y, 0, size, 8, false);

         }
       }
     }
   }    
 }
}

private void DrawFlaKe(Surface dst, Surface src, PdnRegion selectionRegion, int ix, int iy, int radiusInt, int radiusExt, int verticies, bool InvertIntensity)
{
 float th = (float)(2.0f * Math.PI / verticies); 
 float Intensity = 0;
 int b1 = 0, g1 = 0, r1 = 0, a1 = 0;

 float fx = (float)ix;
 float fy = (float)iy;
 int Rint = radiusInt;
 int Rext = radiusExt;
 if (Rext < Rint)
 {
   Rint = radiusExt;
   Rext = radiusInt;
 }
 if (Rext == Rint) Rint = Rext - 1;

 for (int R = Rint; R <= Rext; R += 1)
 {  
   float wR = (float)(R - Rint) / (float)(Rext - Rint) * 100f;
   float wRi = (float)(100 - wR); 
   if (InvertIntensity) Intensity = (float)(Math.Exp(-(wRi) * (wRi) * 0.006) + Math.Exp(-(wRi) * 0.03)) / 2.0f;
   else Intensity = (float)(Math.Exp(-wR * wR * 0.006) + Math.Exp(-wR * 0.03)) / 2.0f;
   for (float P = (float)(-Math.PI); P <= Math.PI; P += th)
   {  
     int x = (int)((float)(R * Math.Cos(P) + fx)); 
     int y = (int)((float)(R * Math.Sin(P) + fy)); 
     if (selectionRegion.IsVisible(x, y))
     {
       byte col = Utility.ClampToByte(255 * Intensity);
       b1 = col; g1 = col; r1 = col; a1 = col;
       //Accum(ref b1, ref g1, ref r1, ref a1, dst.GetBilinearSample(x,y));
       Accum(ref b1, ref g1, ref r1, ref a1, src.GetBilinearSample(x, y));
       dst[x, y] = ColorBgra.FromBgra(Utility.ClampToByte(b1), Utility.ClampToByte(g1), Utility.ClampToByte(r1), Utility.ClampToByte(a1)); 
     }
   } 
 } 
}

private void Accum(ref int b, ref int g, ref int r, ref int a, ColorBgra col)
{
 b += col.B; g += col.G; r += col.R; a += col.A;
}

There are more than 3 sliders needed. So perhaps I should create a more complex UI (than from codelab) to include them...

Link to comment
Share on other sites

There are more than 3 sliders needed. So perhaps I should create a more complex UI (than from codelab) to include them...

You are invited to do so as I can't compile it with codelab when it has more than 3 sliders :wink: .

Have you integrated the stars from your lens flare attempts? This would definately be nice!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...