Creating procedural textures in Java

Seconded here! Great work and I could really do with that noise generator without the extra dependencies :slight_smile:

Kev

I was going to do that, but If bonbon want’s to keep doing her project and have a library that can be used in another program then there isn’t much point for me to work on mine.
Are you going to keep working on yours bonbon?
It would save me a lot of time to start on my new game if you did.
Though no reason why I couldn’t help you on yours.

This also looks intresting: http://www.codeproject.com/KB/graphics/quilting.aspx. It’s C#, but should be portable. And could someone PLEASE implement appearance-space texture synthesis: http://research.microsoft.com/projects/AppTexSyn/ 8)

interesting, but almost everything I’ve read from Hugues Hoppe was patented :persecutioncomplex:

There is my planing ;D :

  1. adding a load/save in my editor (in work)
  2. adding some more few filters (to verify that I didn’t miss something)
  3. creating a lib (should not be that difficult, it should be only copy and past)
  4. rework the editor to deal with my own lib ::slight_smile:
  5. add filters as needed

I don’t known if I will go to the end but I want at least to do all the skeleton for the lib/editor. I each step I will give the source code so if for some reason I don’t continue, someone else will be able to.

Ok great then I’ll stop working on mine then.
The loading and saving is what I need. I’m thinking in making all my textures in it so I can send the data on the fly then the client will create a image out of it.

Not sure if this will help but here’s what I did for turbulence formula.


public static float turbulence(final float x,final float y,final float persistence,final int octave, final boolean smooth)
	{
		if(octave <1){
			return 0;
		}
		float result = Math.abs(Noise.iNoise(x,y, smooth));
		float amplitude=1;
		int frequence=1;

		for(int n=1;n<octave;n++)
		{
			frequence<<=1;
			amplitude*=persistence;
			result+=Math.abs(Noise.iNoise(x*frequence,y*frequence, smooth))*amplitude;
		}
		return result;
	}

The smooth boolean just switches the use of lInterpoleLin to lInterpoleCos.

To speed up many areas I used look up tables like so:


if(setX >= 0 && setY >= 0 && setX < Noise.arraySize && setY < Noise.arraySize){
	if(Noise.noiseValues[setX][setY] != 0.0){
		return Noise.noiseValues[setX][setY];
	}
}
        //<code>

if(setX > 0 && setY > 0 && setX < Noise.arraySize && setY < Noise.arraySize){
    	Noise.noiseValues[setX][setY] = value;
}

Update : Save & Load (it was more dificult than expected :persecutioncomplex:… I should sleep more :P)

There is an example of file

For Perlin and it variation, I should study it a little more… there is something fishy ???

I have another problem : When you draw a color with alpha on another color, the code is :


    color = color_origine * (1-alpha_dest) + color_dest * alpha_dest

But when you draw a color with alpha on another color WITH ALPHA ?

Not sure if you have notice but the apply button seems hide sometimes which you need to make the window larger to see it.
How do you remove filters or you haven’t got that option yet?
Great that you got the saving and loading working. Was it still hard with serializable or you did the saving manually?

Update : Version Alpha 0.2 out

  • lib creation
  • editor modified to use the lib
  • some optimization (Perlin noise cut by half :o)

Editor (Editor source) Lib (Lib source)

To use, the lib :

  • create an TextureLibrary
  • load a file with TextureLibrary.load()
  • get an ArrayList of texture with TextureLibrary.getTextures()
  • create a texture with Texture.create2DTexture()

Note : color can be change on the fly. TextureLibrary.getColors() return an ArrayList of used color

Problem&Solution :

1) How to mix 2 colors with alpha :
With a simple calculation, i got :

New alpha : a = a1+a2-a1a2
New color : c = (c1
a1*(1-a2)+c2*a2) / a

OK !

2) Problem with perlin noise :

What is the difference between :
c(x,y) = sum( iNoise(x,y,octave) * frequence^octave )
and
c(x,y) = sum( Abs(iNoise(x,y,octave))* frequence^octave )
?

Since my random number are [0,1], there is no difference. Even so, if i use [-0.5,0.5] number, the result will be the same with a shift of 0.5. Did I misunderstand something ?

What’s next ?
All people interrested in this project should play around with the editor/lib :

  • to see if some more option are need in the actual filters
  • to see bugs in the editor (I know there is some works to do with the GUI)
  • to see need function in the editor (by the way, unused filter are remove when saving)
  • to see need filters

The editor is looking great, though I’m not great at creating tiles it seems hehe.

Can anyone create some good looking wood/grass textures?
I will surely use your library in my game once I’m to that stage.

[quote]What is the difference between :
c(x,y) = sum( iNoise(x,y,octave) * frequence^octave )
and
c(x,y) = sum( Abs(iNoise(x,y,octave))* frequence^octave )
?
[/quote]
My editor was using the random number between -1 to 1, but yours should be fine if you did -.5 to .5, it should still show the same turbulence effect.

Seems you apply button is still missing sometimes and need to make the window large to see it.
Just a few ideas:
Able to preview the texture, to see what it looks like tiled.
Able to create shapes, so we can do brick walls.
“New” in file menu.
A texture size for x/y just like in mine. So can add more detail, because currently making the image size large it gets blurry.

Update :

  • some little fix in the editor
  • adding Voronoi filter

It is a quick implementation of the Voronoi from the mathematical definition (I don’t have time to search better algorithme right now)

  • adding vector image (since I was working SVG file format a little time ago, it was quick)
    Just take a SVG file and it will try load it (don’t expect mush, only general shape with plain fill and stroke. No gradient. No Text. No Image. No predefined shape).
    For those who don’t know what SVG file are, take a look to InkScape, a good opensource vector graphics editor.

Great. The only problem I’m having now is getting people to help out to create textures, that say the program is to hard. Wondering if you could add words to the buttons instead of just symbols, or add tool tips?
Maybe even a back button would help.
Or even include an example inside the program that people can load up and learn.

If I use a SVG file would it keep the file size still small? I don’t know much about the file type.

Ok, I will try to work out the editor now then (first I have to create icon, I think)

For SVG file, it is an XML format. It don’t keep this format since there is a lot of information that I don’t need. I store it in a binary format to reduce size.

Hoo, I didn’t answer one question :P. For the saving process, I use a custom binary format (no serialization). So if someone want to do another library/editor or want to port the lib in another language, he will have no problem to do so.

Ah I see, good work. I just want to have small files because the server will be sending this data. Do you compress the files too?

Update : version 0.22

  • rework : a few the gui of the editor
  • bug correction : wrong look&feel on filter panel
  • bug correction : selection of the current filter in the tree
  • bug correction : a little mistake in the perlin nose (nothing big)
  • rework : color chooser dialogue box (now complete with a lot less bugs :P)
  • add : 1D perlin noise (to use with radia/sphere gradient for exemple)
  • modify : substract filter (loading an old version will not work :()
  • add : loading/saving of a compressed version of files (.bptz). Non compressed are .bpt

To load compressed file with the library, just do a :

library.load( new GZIPInputStream(new FileInputStream(f)) );

Working much better now.
I think there might need to be a easier way to delete to a single item on a list.
Also on the mix options the apply button is really small.
I think you should show this off if you haven’t already, because many people will find this program handy. Like make a website for it.

This stuff is so cool to play with. I’m finding the editor a little hard work to use though.

Kev

I’ve recently tried MaPZone: it’s free and it can make commercial quality textures (well, if you know how at least, there’s a learning curve).

There is the little update of the week.

Update :

  • new filter : affine tranform (zoom, rotate, translate)
  • new filter : add (add color component of two image)
  • new filter : colorup (colorize an image from the red component… I will add other later)
  • new filter : brick (regular / non regular brick, square or rounded)

It try to make a wood texture too :

Source

In the brick filter, I use a custom component for parameter. Feedback on it is apprecied :wink:

It seems that most people have difficulties to use the editor. But it is difficult to me to know where are those difficulties.
Can you explain where are your problems, what you fill unintuitive, … ?