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.

DarkBASIC Professional Discussion / a shader for creating Perlin noise images

Author
Message
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2014 19:01 Edited at: 24th Aug 2014 20:35
[Update 24 August 2014
Latest version attached to this post. This has the options to add/remove octaves and enables you to show the seamless version.

This version uses the random1 RNG in the shader which gives slightly better images in my opinion - but is a bit slower than my own random2.

My next task is to fix the seamless version so you can have different images tiling together correctly (as requested by Derek Darkly ).]

I've recently posted or discussed early versions of a Perlin noise shader on two of GrumpyOne's threads:

http://forum.thegamecreators.com/?m=forum_view&t=211834&b=1

http://forum.thegamecreators.com/?m=forum_view&t=211857&b=1

Rather than continually mess up his thread I thought I'd better post my effort here.

I've attached a demo which allows you to create a 1024x1024 image (in green of course ) consisting of Perlin noise. The demo allows you to select which of 8 octaves of noise to use (just press one the keys 0-7 to toggle the octave). The image should update virtually instantly.

You can create a new image of the same type by pressing the up/down keys which merely change the seeds used in the random number generator in the shader.

The one problem with the shader at the moment is that it doesn't produce images which tile seamlessly - the demo shows the image itself on the left and the same image tiled 3x3 on the right.

You can see which octaves are selected by the column of numbers on the left of the screen. The screenshot below shows an image using octaves 2-7:





Powered by Free Banners

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2014 19:04
Screenshot for previous post.



Powered by Free Banners

Attachments

Login to view attachments
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 20th Aug 2014 19:47
Works great! Love the octaves feature.

One of my game goals is to eventually be able to fly over seamless, tiled terrains at high speed while generating upcoming terrains on the fly. This is definitely a step towards that. (Applying the information to an actual mesh would be the other major part, of course.)

Looking forward to updates, even though what you have is already great. Excellent work!

666GO†O666
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2014 21:12
Thanks.

You've got GrumpyOne to blame for this - his posts reminded me I'd started this some time back but hadn't put it into a usable form. It is at least usable now. Just need to fix the tiling issue.



Powered by Free Banners
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 20th Aug 2014 21:38 Edited at: 20th Aug 2014 21:41
This is a conveniently practical shader function for a variety of applications, and one of the effects I struggled to produce in HLSL.

Thanks for the timely enlightenment GG. I guess the next challenge is to make it seamless; some finite aspect of the algorithm is no doubt the repetitious culprit.

Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2014 02:01
Quote: "I guess the next challenge is to make it seamless; some finite aspect of the algorithm is no doubt the repetitious culprit."


Yes. I'm baffled by that problem at the moment. I've got a hard coded version of one octave and it tiles perfectly. I suspect a silly error somewhere in my code - although an otherwise minor precision issue might also be to blame. I'm inclined to doubt that latter theory though, since I would then expect difficulties along the various tile seams within the main image and not merely along the outer edges.

This is the first time I've encountered the persistent Dark Shader problems you mentioned a while back. I just cannot run this shader in Dark Shader - DS gets as far as syntax checking (which is what I need really) and then gives me the familiar timeout errors. I thought the new version of DS fixed this but it doesn't. Fortunately, it runs fine in DBPro. I haven't tested this on my desktop machine yet. I've noticed that the problem gets progressively worse as I add extra bits of code.

Once I've fixed the seam issue I intend to optimise the code - I suspect it can be streamlined a lot. However, I doubt that will make it run much faster since the shader compiler has an efficient optimizer built in. On the other hand it's possible that cleaning up the code will remove or highlight the bug. It might also allow it to run properly in Dark Shader.

The other annoying thing is that I had to use a workaround to supply the shader with the selected octaves. There's a DBPro command that comes with Dark Shader that's supposed to do the job, i.e. set object effect constant vector element. That command works - but I can only get it to work once per element! So if you remove an octave you can't then reinstate it using that command. That's the sole reason for the use of the otherwise clumsy float4's list1 and list2 in the shader. But at least that works effortlessly.

I'd also like to follow up Derek Darkly's comment:

Quote: "One of my game goals is to eventually be able to fly over seamless, tiled terrains at high speed while generating upcoming terrains on the fly."


although I'm not sure how to implement that yet. One solution might be to fix the edge tangents with the same seed throughout but change the seeds for the interior tangents. But as you say, that'll have to wait till I've mastered the seamless issue.





Powered by Free Banners
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 21st Aug 2014 21:34 Edited at: 21st Aug 2014 21:44
Quote: " till I've mastered the seamless issue."


What about your seamless texture technique? Any way to incorporate that into this?

Or would it be possible to mirror, say, 10% of the image edges before applying the shader?
For example, take 10% of the top and left edges, mirror & slap them on the bottom and right edges, then add the perlin noise, or is that too cheap? LoL

666GO†O666
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2014 23:39 Edited at: 21st Aug 2014 23:50
Quote: "What about your seamless texture technique? Any way to incorporate that into this?"


Amazing you should suggest that - that's exactly what I've just been testing!

The short answer is "Yes" - and it's a shader solution too. I merely need to put the two together in a single app. You'll then be about 95% of the way to what you want. Screenshots to follow shortly - then I'm taking a break for a while .

Edit Screenshot using Texture Maker:





Powered by Free Banners

Attachments

Login to view attachments
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Aug 2014 06:55 Edited at: 22nd Aug 2014 06:57
Quote: "Amazing you should suggest that - that's exactly what I've just been testing!"


Yeah, I was thinking - Did he forget that he already has a seamless texture app? Pretty sure I've used it before!

Quote: "I merely need to put the two together in a single app. You'll then be about 95% of the way to what you want. "


Oh yes... I want to fly forever over random, bumpy masses!

Developments like this could lead to world peace - or at least inner peace.
I'm glad there are much smarter people than I in this world, else I'd be driving a moccasin to work.

666GO†O666
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2014 13:48
Quote: "Quote: "I merely need to put the two together in a single app. You'll then be about 95% of the way to what you want. ""


Sadly, on reflection, that probably isn't true. Certainly the resulting image will be seamless but for your purpose you need control over the edges which you lose with my seamless routines.

Hopefully I'll find time to put together the seamless version in the next couple of days - but for your application something a bit different is needed. In fact does it need to be seamless? All you need is for the left hand edge of one texture to meet the right hand edge of the next so they join up seamlessly. Anyway, food for thought.

I'm still struggling to find the root cause of the failure of my various attempts to make the Perlin shader seamless in a controllable fashion. There's either a simple coding error that I can't see or certain shader functions are not working as I expect.



Powered by Free Banners
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 22nd Aug 2014 19:24 Edited at: 22nd Aug 2014 19:25
Quote: "In fact does it need to be seamless? All you need is for the left hand edge of one texture to meet the right hand edge of the next so they join up seamlessly."


True... the texture doesn't have to be seamless to itself, just to the adjoining textures, hence my suggestion of taking about 10% of 2 of the edges and mirroring them on the opposite edges (of another texture, I should have said before) then applying the shader to all. Don't know if that would work, but can't see why it wouldn't.

Quote: "I'm still struggling to find the root cause of the failure of my various attempts..."


It sucks being so close, yet not quite there..
Without the failures, though, we would hardly appreciate our successes.
Funny, I have noticed recently that deep thinking itself requires a lot of energy and can really drain you at the end of the day!

666GO†O666
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2014 21:48
Quote: "It sucks being so close, yet not quite there.."


I think I've found the error.

I just need to work in the correction to my main code. So watch this space.

Quote: "Without the failures, though, we would hardly appreciate our successes."


Very true - but I'm holding back on the champagne till I've finished the recoding and tested the full version. I am very hopeful though.



Powered by Free Banners
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Aug 2014 22:00 Edited at: 22nd Aug 2014 22:01
Quote: "I've attached a demo which allows you to create a 1024x1024 image "


Is there a way to get a smaller image?..my laptop has maximum 1366/768 and it gives me an error every time I try. Could be this error perhaps because I still use old version 1.074 ?



I'm not a grumpy grandpa

Attachments

Login to view attachments
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2014 23:29
Quote: "Is there a way to get a smaller image?"


Just change these two lines (shown in your screenshot ):



They do not need to be powers of two - I've just tested with 256x200 and everything works fine.

Quote: "Could be this error perhaps because I still use old version 1.074 ?"


I doubt it although it is possible - I'll test it here later. A more likely explanation is that your laptop objects to this shader - it is long (when compiled). Also it requires Shader Model 3. Does your laptop support that?

The shader takes a full 45 seconds to load into DBPro on my laptop but then runs at 40 fps for the basic non-seamless version, and about 20 fps for the seamless version (which I've just completed - see next post ).

Does the program fail to compile - or is it a runtime error?



Powered by Free Banners
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 22nd Aug 2014 23:35 Edited at: 24th Aug 2014 20:25
Quote: "Very true - but I'm holding back on the champagne till I've finished the recoding and tested the full version. I am very hopeful though."


Here's the new corrected demo.

The shader takes a long time to load on my laptop (about 45 seconds) so be patient.

Press and hold t to see the seamless version of the image. I've coloured the two images differently so you can see the two techniques more easily.

No time for further explanations right now - but the good news is that I can now move on to DD's request.

The original problem was a "simple" coding logic error.

[Update 24 august 2014 Current slightly improved version moved to first post. ]



Powered by Free Banners
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 22nd Aug 2014 23:41
Quote: "Just change these two lines (shown in your screenshot ):"


It was the first thing I've done . Your version "perling shader test v3 " works fine.

Quote: "Also it requires Shader Model 3. Does your laptop support that ?"

No idea, it is from 2009...five years old
Quote: "
Does the program fail to compile - or is it a runtime error?"


It doesn't compile at all ...just show this mesagebox with the error.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 00:36
Quote: "It doesn't compile at all "


Then it is nothing to do with the shader - DBPro doesn't know what that is till you run the exe.

Perhaps it's a project setting or editor issue. Have you tried changing the default resolutions in the project's Properties panel? I've got it set to 1600x900 in the project for some reason.

Quote: "I'll test it here later"


Just tested the latest demo using U7.4 on my old desktop - it runs fine.



Powered by Free Banners
chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 23rd Aug 2014 01:10
Quote: " Have you tried changing the default resolutions in the project's Properties panel? "


I'm a F.. idiot ... I've had this problem a lot of times, and I never remember the project reslousion, (something that acts independent of the screen resolusion). Now I can see the image forcing screen to 640,480,32

Nice code

Has any advantage setting so high resolusion ?

Cheers.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Aug 2014 02:10
Quote: "Has any advantage setting so high resolusion ?"


I don't think so. I was experimenting a while ago and forgot to change it back. Oops.

I'll try to remember tomorrow when I'm awake - if I try now strange things will happen.



Powered by Free Banners
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 24th Aug 2014 20:34
Latest, slightly cleaned up, version added to first post.

It uses the better random number generator which is somewhat slower.

Quote: "I'll try to remember tomorrow when I'm awake"


Only remembered after I'd posted the revised version. I'll update it now while I'm thinking about it.



Powered by Free Banners
Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 29th Aug 2014 15:25
Doesn't HLSL have a built in "noise" function to do perlin noise?

[b]
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2014 15:44 Edited at: 29th Aug 2014 15:47
Only in texture shaders as far as I know - and DBPro doesn't support those which is a pain. [Edit Hmm? I'll double check that - perhaps something has changed since I last looked. The SDK only mentions textureshaders in connection with Shader Model 1.]

I've just done a bit of experimenting with the FX compiler that comes with the MS DX9 SDK to see what was using the loading time when the shader is loaded into DBPro. The result surprised me. I was expecting it to be a DBPro feature (). It isn't. It took almost as long for the FX compiler to digest the file. Shader connoisseurs might like to inspect the assembly file produced (attached). So in this case it seems that DX9 is to blame and not DBPro.

I wonder whether DBPro will accept the compiled version? And if so, how?





Powered by Free Banners

Attachments

Login to view attachments
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 29th Aug 2014 18:21
The noise function of HLSL was dropped; only shader model 1 supports it.

Quote: "noise

Generates a random value using the Perlin-noise algorithm.
ret noise(x)


Parameters

Item Description

x


[in] A floating-point vector from which to generate Perlin noise.


Return Value

The Perlin noise value within a range between -1 and 1.

......

'Support'
Shader Model 2 (DirectX HLSL) and higher shader models no
Shader Model 1 (DirectX HLSL) yes (tx_1_0 only)"


Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2014 19:58
Yep - and only in texture shaders (as in tx_1_0).

I can't imagine why it was dropped - it was one of the most useful features of the old versions of FX Composer.



Powered by Free Banners
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2014 23:26
Quote: "it was one of the most useful features of the old versions of FX Composer"


I abandoned FX Composer some time ago because I couldn't get the old versions (FX Composer 1.8) to work on my newer machines. However, this discussion made me try again - and guess what, it runs quite happily on my W7 laptop. So I can start creating procedural shaders again.

FXC 1.8 doesn't seem to be available on the NVidia web site any more but I managed to locate a download here:

http://fileforum.betanews.com/download/nVIDIA-FX-Composer/1117465967/1



Powered by Free Banners
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Aug 2014 21:23
Quote: "it was one of the most useful features"


Definetly!

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 31st Aug 2014 12:50
Quote: "I wonder whether DBPro will accept the compiled version? And if so, how? "

It does, compile your shader using fxc.exe and then load the byte code version you can save using the /Fo <filename> command line argument.


"Why do programmers get Halloween and Christmas mixed up?"
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Aug 2014 23:19 Edited at: 31st Aug 2014 23:27
Quote: "Quote: "I wonder whether DBPro will accept the compiled version? And if so, how? "
It does, compile your shader using fxc.exe and then load the byte code version you can save using the /Fo <filename> command line argument."


I'll look into that. I know you can load the asm code as a standard .fx file after a few changes to the file (I just need to remind myself what those changes are ). I'll report back after some tests.

Edit Thanks! That was amazing! I had no idea you could do that in DBPro. That completely eliminates the shader load time. Just compile the shader once using fxc and load the .obj file in exactly the same way as a standard .fx file. Brilliant. I'll edit my demo as soon as I get the chance to do it carefully.

First really useful thing I've learnt for a long time.



Powered by Free Banners

Login to post a reply

Server time is: 2025-06-20 05:29:32
Your offset time is: 2025-06-20 05:29:32