Sign in to follow this  
davidf

Cell Texture plugin (12th Nov 2012 - updated to v1.2)

Recommended Posts

Effects > Render > Cell Texture

Edit: Updated to version 1.2 (no code changes, just made sure it uses the internationalized Render menu instead of the string "Render").

Edit: Updated to version 1.1 (added "Combined" distance type and changed "Multiply" method to "Root sum of squares", which looks a bit nicer - also handled coloring better for this method. See left image in the second row below for an example).

This plugin was inspired by the page:

http://www.blackpawn...ar/default.html

The algorithm can create quite a lot of different texture types:

cell_texture.jpg

The parameters are:

Foreground - the color inside the cells.

Background - the color around the edge of the cells.

Swap background and foreground - exactly what it says!

Avoid border - do not place cells near the edge of the image. If this is not set, the image is tileable (i.e. it wraps around the edges).

Cell size - the side length of the invisible squares the cells are based on (there is one "point", i.e. cell centre, at a random location inside each square - with a slight bias towards the middle).

Intensity - adjust the distance where the foreground turns into the background.

Random color - amount of random color to add to individual cells.

Method - formula to use to determine the color (see the link mentioned above).

Distance - distance metric to use. "Euclidean distance" is distance in a straight line, "Manhattan distance" is the sum of the X and Y differences, "Chebychev distance" is the maximum of the X and Y differences and "Combined" is a combination of all of these.

I'd love to see any interesting uses people find for this ...

(My first plugin created using Visual C#. Yay!)

Download: CellTexturev1.2.zip

By the way, when adjacent cells are different colors, there is no antialiasing at the moment -- I need to investigate the best way to do that.

Known bug: for large cell sizes with "Subtract nearest two neighbors" and "avoid border" both set, there are sometimes some problems near the right or bottom edge of the image.

Edited by davidf

Share this post


Link to post
Share on other sites

Well done! :star::beer:

Works really well, ...good starting point for textures.

I'm in admiration of anyone that understands Visual express too :D

Thanks for sharing

Share this post


Link to post
Share on other sites

th_Blueeyes.png

Cool plug-in with heaps of potential, it helped me finish this piece.Cheers for the share.

Great! Took me some time to work out where in the image you used it ...

Share this post


Link to post
Share on other sites

May I propose an option to allow a fix position of the nucleus in the cells (i.e. centered). This would allow to create regular textures too.

And a question. Would you provide a code snippet how you are mapping the colors to the gray values generated by the algorithm?

Share this post


Link to post
Share on other sites

I couldn't stop to do more experiments using this algorithm to create textures ;-)

I changed the distance function a bit to move the nuclei out of the center of the cells and got the attached images.

Pseudo code:

distance.x = nuclei[ i].x - pixel.x; if (distance.x > 0) distance.x = distance.x * 3;
distance.y = nuclei[ i].y - pixel.y; if (distance.y < 0) distance.y = distance.y * 3;

So this may also be an idea for an additional option: Weight distances in certain directions.

post-79572-0-59572500-1352020294_thumb.j

post-79572-0-64313800-1352020309_thumb.j

post-79572-0-63369800-1352036945_thumb.j

post-79572-0-25963900-1352036967_thumb.j

Edited by midora

Share this post


Link to post
Share on other sites

And a question. Would you provide a code snippet how you are mapping the colors to the gray values generated by the algorithm?

The levels are just proportional to the distance from each point. The main algorithm for "nearest neighbor" is:

  • For each square in the grid (side length = "cell size" parameter), pick a random point (the cell centre).
  • For each pixel (x, y), find the distance D to the nearest cell centre and divide by the cell size to give a value W; if W > 1, set W to 1.
  • Linearly interpolate between the foreground and background colour using W: foreground * (1 - W) + background * W.

The "intensity" parameter is also added to W (and the result is restricted to the range 0 to 1).

I changed the distance function a bit to move the nuclei out of the center of the cells and got the attached images.

Pseudo code:

distance.x = nuclei[ i].x - pixel.x; if (distance.x > 0) distance.x = distance.x * 3;
distance.y = nuclei[ i].y - pixel.y; if (distance.y < 0) distance.y = distance.y * 3;

So this may also be an idea for an additional option: Weight distances in certain directions.

I tried it out, and here is the result:

Download: CellTextureWithDisplacement.zip

The new parameters are "X displacement" and "Y displacement". If these values are not zero, the X or Y component of the distance is multiplied by 1 + abs(displacement): if the parameter is less than zero, only negative X/Y values are multiplied, otherwise only positive values are multiplied. If the paramaters are X displacement = 2 and Y displacement = -2, the result is exactly the same as your code above.

I'm not very fond of this variation though (I think it leaves too many empty areas), so I won't make it the official download.

Share this post


Link to post
Share on other sites

I'm not very fond of this variation though (I think it leaves too many empty areas), so I won't make it the official download.

I agree, the gaps are getting too large. But there must be a difference in the distance function of our implementations if you are looking too the attached examples. Anyway I didn't expect that you give it a try immediately ;-) Thanks.

I'm more interested in a variant which does not use random positions for the nuclei.

Share this post


Link to post
Share on other sites

I'm more interested in a variant which does not use random positions for the nuclei.

The positions are based on a square grid, so using uniform positions doesn't look very interesting -- just a screen full of squares ...

You could try other types of grids (triangular, etc.) but the way I wrote the plugin depends on using a square grid, so it isn't simple to try that out.

Share this post


Link to post
Share on other sites

I'm expecting you are using squares to speed up the calculation of the pixels minimal distance value.

In general I like both regular and more irregular textures. It depends what you like to achive in your image.

Attached are examples of textures generated using the algorithm with centered nuclei.

post-79572-0-34137900-1352100395_thumb.j

post-79572-0-05766100-1352100423_thumb.j

Share this post


Link to post
Share on other sites

It looks like that the plugin does not return SubmenuNames.Render in the StaticSubMenuName function instead it seems to use "Render".

Thanks, I didn't know about that -- the .zip file in the original post has been updated to version 1.2 now (this is the only change, so no need for English speakers to re-download).

How do you learn about these kinds of things? The template code I was using didn't have this information. I'd love it if there was a "complete guide to writing PDN plugins" ...

Edited by davidf

Share this post


Link to post
Share on other sites

How do you learn about these kinds of things? The template code I was using didn't have this information. I'd love it if there was a "complete guide to writing PDN plugins" ...

Looking to more templates. Using F12. I agree that the situation is not quite comfortable for developers.

The first thing I'm doing when I start to develop on a new environment is to create a new document about the environment. Everytime I'm figuring something out, there will be a remark in this document. So I'm entering links, code snippets and more. All depends on the quality of the original documentation.

I.e. two weeks ago, I decided to check if IndirectUI is usefull. Everytime I needed a new control type I added a new section about this type. This collects all the kind of information you do not have an idea about when you are starting. Like that the color you are providing to the colorwheel must be opaque (or you are getting an exception).

At some time we may just start new topics in the Plugin Developer Central and add all the things we are figuring out.

I detected the 'Render' issue when I tested a plugin after switching Paint.NET to German. Suddenly there was an additional submenu 'Render' containing your (but not only your) plugin. Most Render plugins poped up under the german entry.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this