Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] seamless texturing utility

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd May 2010 14:41 Edited at: 5th Apr 2011 01:13
*** New version attached to this post - see my post on 22 Feb 2011 for details. ***

Download now includes the exe file - 4 April 2011.

The attached program allows you to create a seamless version of an input image.

I wrote this because I wasn't happy with the built-in options that come with Texture Maker.

It works best with source images that are fairly random such as rock, sand, grass and random stone walls. The demo contains two sample source images to play with.

The program contains a contrast adjustment which reduces or eliminates the blurring that is sometimes visible along the blended edges.

For the enclosed sample images I found that overlap percentages around 10 worked well (and should be within the range 0 to 25).

If it doesn't compile then it might need IanM's Matrix1 utilities.

Here's an example using a section of our garage wall tiled 2x2.
The attached code includes the contrast adjustment.

Original image showing seams


Seamless version including contrast adjustment


Seamless version without contrast adjustment

Attachments

Login to view attachments
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 5th May 2010 23:46 Edited at: 8th Aug 2011 00:00
You rock GG! This is pretty neat

[EDIT: code below is outdated with new GG code. Scroll down to newer posts ]
For those that don't use the Maxtrix1 dlls
You can replace the Maxtrix1 max function at line [EDIT: line # no longer valid] with this:


ExoDev.Com - A Game Development Community Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2010 13:48
Thanks.
Quisco DaLuse
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: USA
Posted: 10th May 2010 16:41 Edited at: 10th May 2010 16:43
Very nice! Works well.
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 20th May 2010 19:25
Wow this really works! With the stone texture example, the seaming is there if you look for it, but you do really have to look for it. I've tried other things to make seamless textures, like Paint Shop Pro's inbuilt thing, but the results for this seem so much better. I should find a use for this at some point, and plan to study the code to see why it works so well.

A related problem is how tiled textures can look really obviously repeated. A possible solution might be to make a patchwork larger texture of various shifted instances of the base texture. I could maybe adapt this program for that.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st May 2010 00:34
Quote: "I've tried other things to make seamless textures, like Paint Shop Pro's inbuilt thing, but the results for this seem so much better"


Thanks. My dissatisfaction with the "professionals" offerings made me wonder how I would approach it. This program is the final result. Which also makes me wonder what they think they are doing.

The key step in my opinion is to add just the right amount of contrast when you blend two pixels together. This is needed because blending is just a form of weighted averaging so it tends to reduce the contrast of blended pixels. If your maths background extends to basic properties of random variables (probability, stats, mean, variance, etc) you can probably work out where my adjustment comes from.

It actually works better than I expected - although the degree of success does depend on the source texture of course.

Quote: "A related problem is how tiled textures can look really obviously repeated. A possible solution might be to make a patchwork larger texture of various shifted instances of the base texture. I could maybe adapt this program for that."


I've been thinking along the same lines. I hope you keep us posted on that.
ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 3rd Jun 2010 17:04
This is awesome!

Thank you GG.

PW Productions
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location: sitting in a chair.
Posted: 5th Jul 2010 17:55
That is so cool! Thanks!

Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 12th Jul 2010 23:54
Would you mind uploading an image to demonstrate the effect? I'm a bit lazy at times and tend to avoid download-buttons.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2010 13:54 Edited at: 15th Jul 2010 21:11
Just seen your post (I've been away from the forum for a few days).

Good suggestion. I'll prepare two images to show the effect - a before and after view.

Edit

I've added three images to the first post:

1. a stone wall image tiled 2x2
2. the same image made seamless with 10% overlap and also tiled 2x2
3. same as 2. but without the contrast adjustment.

The most obvious effect is the removal of the seam - but if you open the second two images in Paint and switch between them you should see the effect of the contrast adjustment.

The code I posted in the first post includes the contrast adjustment around the seam. I think it looks better but it is a "second order effect".

The original 2x2 tiled image is attached here, the next two posts have the seamless versions.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2010 21:13
Second image for first post.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Jul 2010 21:14
Third image for first post.

Attachments

Login to view attachments
Neuro Fuzzy
16
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 16th Jul 2010 05:59
Quote: "A related problem is how tiled textures can look really obviously repeated. A possible solution might be to make a patchwork larger texture of various shifted instances of the base texture. I could maybe adapt this program for that."


I believe I've heard that pixar has used and many animated films do use perlin noise and perlin noise-like overlays on textures, for dirt and scratches and things. But... I think that would require a shader? I don't know much about shaders and stuff.
Short of a good algorithm for procedural textures (or procedural texture tiling? Thats an interesting thought), I don't think theres much you can do besides bigger textures.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Jul 2010 14:04
Quote: "I don't think theres much you can do besides bigger textures."


There is if you are prepared to use a shader. I intend to post a demo at some point but the basic idea is to tile the terrain, etc, with an image in the usual way but use a single untiled Perlin noise texture stretched over the whole terrain to offset the texture lookups at each pixel. This helps destroy the visually annoying repetition. I've tested the basic idea but haven't "rushed into print" (I sometimes post a half-baked demo when I should spend a bit more time improving the appearance ). This is an example where a nice convincing demo would be useful because several people have mentioned this problem.
Sixty Squares
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Jul 2010 05:08
Wow, this tool is great! I can now take pictures of things I see and use them as textures . Very useful.

Quote: "I intend to post a demo at some point but the basic idea is to tile the terrain, etc, with an image in the usual way but use a single untiled Perlin noise texture stretched over the whole terrain to offset the texture lookups at each pixel."

That would be very cool to see.


Guns, cinematics, stealth, items and more!
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Sep 2010 23:14
Quote: "That would be very cool to see."


Noted - somewhat belatedly.

My list of things to do seems to get longer. Anyone know how to make it shorter?
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 3rd Sep 2010 17:08
Quote: "My list of things to do seems to get longer. Anyone know how to make it shorter? "

Change the font size?

Seriously though, you could try making a thread "GG's To Do List", and if anyone is bored they could try doing the stuff on it.
RonsWare
13
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 5th Sep 2010 17:27
If You do so , try to help

Programming is learning
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Sep 2010 19:28
Quote: "Seriously though, you could try making a thread "GG's To Do List", and if anyone is bored they could try doing the stuff on it."


My list has suddenly got longer by one.
Dr Tank
14
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 8th Sep 2010 00:57
Quote: "My list has suddenly got longer by one. "

Nice one.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 8th Sep 2010 07:23
!!!

Virtual Nomad @ California, USA . DBPro V7.5
AMD Phenomâ„¢ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Nov 2010 17:33
Wow!!!!! I love you GG. The "make seemless" thing in GIMP sucks...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Nov 2010 21:58
Thanks.

One of the reasons for writing that code was that I just couldn't see why various image editing packages made the task seem so difficult. And I still can't.
Softwizz
14
Years of Service
User Offline
Joined: 14th May 2009
Location: U.K.
Posted: 14th Feb 2011 15:18
That is very good.
It should be easy to incorporate a better file open and save system and turn it into a simple texture maker.

Thanks for code

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Feb 2011 13:57
Quote: "It should be easy to incorporate a better file open and save system and turn it into a simple texture maker."


That is yet another item on my ever-growing list of unfinished projects.
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 16th Feb 2011 16:08
Another thread I've been following with great interest but not yet spoke up yet.

Excellent work on this by the way. I have used a seamless utility but it was quite awkward. Would this be able to in the end do batch conversions so that maybe you could see all of the images processed then just tweak the individual ones? Something like this would be an essential utility.

Warning! May contain Nuts!
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 16th Feb 2011 22:35 Edited at: 1st Nov 2011 00:48
Nice Work GG.
We found source code for calling the Windows Open/Save File Dialog
on the forums. Updated your source code to use it.

[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.

Attachments

Login to view attachments
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Feb 2011 00:21
Thank you!

That's just what I needed.

I'll be revisiting this very soon with an update.
Admiral MH
13
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 17th Feb 2011 21:03
This is amazing results, thank you!!!

Also nice job with the Open/Save Dialog, but in case if you don't know, there is a free plugin, "BBB GUI" that has most of the windows GUI gadgets. It's in the WIP board. So that will be easier than using the DLL's to access the dialogs.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Feb 2011 15:19
Thanks to Stab in the Dark software we now have an improved update.

Main changes:

1. Improved file opening and saving (thanks Stab in the Dark software ).

2. Improved display of seamless images - you can now see the effect of the contrast adjustment more easily by pressing 2 to show the image without it.

3. Now supports a greater variety of image formats.

4. Now supports non-square images.

5. Added a few extra sample images - the random dots example illustrates clearly why the contrast adjustment is needed (although in that extreme case the image is already seamless of course ).

New download added to first post.
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 23rd Feb 2011 01:02 Edited at: 23rd Feb 2011 01:18
Thanks for the update!

Ofcoarse, excitingly, I had to throw my 2 cents in with my revisions to the code below:
1 - matrix dlls free ( I don't have it installed "yet" )
2 - Added fullscreen tiled texture view ( Pressing the spacebar toggles it on and off )
3 - Added "Redo overlapping %" ( Press "R" )

* Seeing the option of pressing 1,2 or "3", I deleted the "default case" in the select/case so it will not automatically go back to 3 after pressing 1 or 2.

* because I don't have the "find free dll/memblock" commands, I just simply hard coded ID's for them. Also! made sure that the memblocks were deleted at the end of each function they were created in to eliminate memory leaks( ofcoarse when ending the program DBPro will delete all used memblocks anyways. But, here we re-use memblocks as we don't need to save the contents of them after leaving the functions they were used in )

* And I simply put in a "Processing" message after entering an overlapping percent so we can see something must be happening.

stitch.dba


file open dlg.dba


ExoDev.Com - A Game Development Community Website! Featuring: XBOX360 CONTROLLER LIBRARY
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Feb 2011 01:28 Edited at: 23rd Feb 2011 01:32
Quote: "Ofcoarse, excitingly, I had to throw my 2 cents in with my revisions to the code below"


I'll look into those carefully in a few days time (I'm about to go away for a few days).

Just a few comments for now:

Quote: "1 - matrix dlls free "


I don't see the point in that. They are both free and excellent.

Quote: "2 - Added fullscreen tiled texture view"


Good idea. I'll use that.

Quote: "* Seeing the option of pressing 1,2 or "3", I deleted the "default case" in the select/case so it will not automatically go back to 3 after pressing 1 or 2."


Yes, I was beginning to find that annoying too. Thanks for the nudge.

Quote: "* because I don't have the "find free dll/memblock" commands, I just simply hard coded ID's for them."


Yes, if I'd written that part I'd have done that too. For a small program like this such refinements aren't necessary - but I left them in since they do no harm. I'm happy to delete them though and keep the code simple.

Quote: "Also! made sure that the memblocks were deleted at the end of each function they were created in to eliminate memory leaks."


I'll look into that aspect of the code. Again it wasn't my code and I left most of it as it was. I usually reuse structures where possible rather than continually creating/deleting them - which can itself be a source of memory leaks. The bitmaps are deleted because they can vary in size.

Quote: "* And I simply put in a "Processing" message after entering an overlapping percent so we can see something must be happening."


I was too lazy to do that - but it's definitely worthwhile since the processing takes a while. Another nudge in the right direction.

Thanks for the suggestions.

One change I'll probably introduce is to use buttons for the options - it's annoying to be switching unnecessarily between mouse and keyboard and I keep having to stop myself from clicking on the "S", "O" and "Q".

I'd like to add more options so a greater variety of images can be made seamless - but I don't want to over-complicate things. For example, one thing that can be done easily is to add an option for balancing the image before making it seamless, i.e. removing gradual colour gradients which can otherwise spoil the seamless effect.

Keep the suggestions coming.
Duffer
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: chair
Posted: 2nd Apr 2011 13:18
@ Green Gandalf,

This is really good. Unfortunately I've got myself in a tangle with all the plugins etc. Is there any chance you could also upload the compiled executable to the first post?

a long time dabbler with DBC and DBPro with no actual talent but lots of enthusiasm...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Apr 2011 01:14
Quote: "Is there any chance you could also upload the compiled executable to the first post?"


Done.
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 5th Apr 2011 22:00
Looks very, very cool! Yah! That even rocks! Lol. It's really useful

gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 1st Aug 2011 20:03
hi

I just found the this post

I tried to run the code but got one error

Subscript must be Integer or DWORD when referencing an array at line 126.
PROGRAM TRACE
-------------
max#(overlap# * width * 0.01, 5.0)
width1 = width-1
height1 =
ERROR TRACE

it could be one of the plugins being a pain
or there something missing

If a thought is Just a thought ~ so whats the main thought ?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Aug 2011 13:10
Quote: "it could be one of the plugins being a pain "


You need IanM's Matrix1 plugin. That message almost certainly refers to his max() function which merely returns the max of the two arguments.
gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 3rd Aug 2011 01:38
I was missing #7 now it works fine

I've collected every plug-in
I could find in the forum
I've only found 2 so far that I am missing
and they got collected recently

unforchantly there are plugins that do now work
with the dbp or 7.61 because things have changed
or it seems "IanM's Matrix1 plug-in" conflicted
with other plugins

I know a lot of plugins were transferd from
function so I just need to find the functions they
replaced and rework the programs with the quirks

some one point a program in the forum called
"Resource Hacker"

it lets you change things or even get things out
of some dll's

If a thought is Just a thought ~ so whats the main thought ?
gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 6th Aug 2011 13:59
Todd Riggins

the code to replace Maxtrix1 max function at line 25

umm is that the correct location ?

or should it be at line 126 ?

If a thought is Just a thought ~ so whats the main thought ?
Todd Riggins
19
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 7th Aug 2011 23:58 Edited at: 8th Aug 2011 00:05
Hi Resourceful, GG had updated his code since that post was made. The location of those Matrix1 max functions are in a different location now as you can see.

I have replaced the max function's :



in his function:
function makeSeamlessTex(fname$ as string)

with this code:


ExoDev.Com - A Game Development Tools Website! Featuring: XBOX360 CONTROLLER LIBRARY

Login to post a reply

Server time is: 2024-03-29 13:24:37
Your offset time is: 2024-03-29 13:24:37