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 / [STICKY] Learning to write Shaders

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2009 12:06
Quote: "I dont think the waves are aligned at the shore."


What do you mean? As far as I can see the waves go right up to the terrain all the way round the islands. If you mean the terrain's texture below sea level is the same as above sea level then that's just a matter of changing the terrain's main texture - and you can do that as well as I can.

Quote: "Maybe you can use a black and white image to define the borders instead the greyscale map?"


What would be the point of that? You'd lose your depth information then. Breakers appear when the sea becomes shallow near the shore.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 21st Aug 2009 12:31 Edited at: 21st Aug 2009 12:33
no i mean, the borders of the sea is wrong at some spots. it just goes inside the terrain.



There is always one more imbecile than you counted on.

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: 21st Aug 2009 13:17 Edited at: 21st Aug 2009 13:28
Are you sure you haven't changed something?

That doesn't look like my demo.

The demo isn't complete yet of course. For example, if you change the position of the sea object then the shader constants will need to be changed as well but these changes are not done automatically at the moment.

I'll check my demo again in case I missed something - but the shore was correctly aligned when I last ran the demo and studied it.

Edit Just checked the demo on another machine and everything seems to be correctly aligned. I think you must have changed something. When I next get some time to work on this I'll include some dba code to change the shader settings automatically.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 21st Aug 2009 13:57
i didnt change anything except the camera handling.

Anyways, this is my office computer and it sucks. Ill try again at home.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2009 15:22
Quote: "i didnt change anything except the camera handling."


Strange. The fog has disappeared too.

Two things occur to me:

1. There used to be a problem with fog and Advanced Terrain - but there's no problem in my demo.

2. A long time ago (two years?) the Advanced Terrain height map and texture maps were not aligned with each other.

Perhaps your office machine has an ancient version of DBPro? I'm using U7.4.

Quote: "Ill try again at home."


OK. I'll wait to hear from you.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 21st Aug 2009 16:17 Edited at: 21st Aug 2009 16:34
Quote: "Strange. The fog has disappeared too"


I changed the camera handling aaand removed the fog from terrain aaaaaand just increased near and far values of the fog in the shader. Didnt change anything else.

EDIT: oh now it works, the water plain was wrongfully aligned.
I did this and it worked. (How comes it worked for you the otherway round?)



There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Aug 2009 16:40
Anything else you "didn't change"?

Quote: "(How comes it worked for you the otherway round?)"


A clue:

Quote: "Perhaps your office machine has an ancient version of DBPro? I'm using U7.4."


I vaguely recall Lee had a good reason for changing the default orientation of DBPro plains in a recent update. He does that sort of thing from time to time just to see if anyone is paying attention.

Which upgrades are you using on your machines?
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 24th Aug 2009 00:38
Quote: "
1. Add the waves to the sea.
2. Find a way of getting more interesting breakers near the shore.
3. Improve the fog.
4. Optimise everything to keep Alfa x happy.
[5. Have a holiday. ] "


Thank you so much.
I will use this shader in UA.

Everything is looking so good. Congrats
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 25th Aug 2009 20:43
Where is my shader gandalf?

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 25th Aug 2009 22:46
Stuck in a queue.
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 26th Aug 2009 00:45
How hard would it be to create a Diffuse\Normal\Specular shader? That's the one thing I can't seem to find anywhere for DBP.

Also, I notice some shaders require specific texture file names to work. Couldn't you somehow make a shader dependent on the images in DBP's object texture stages? And how would you go about coding that?

Sorry, I'm a newbie to HLSL, but I'm trying to learn! All I have succeeded in doing so far is to convert a non-compatible bump-mapping shader to work in Dark Basic...

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2009 01:36
Quote: "How hard would it be to create a Diffuse\Normal\Specular shader?"


That's very easy. Have you looked at the Ultimate Shader Pack on the Work in Progress board? Evolved probably included something very like that. I've posted a few too. Do a search on this board for things like normal mapping, bump mapping, etc. If you're still stuck I'll dig one out for you tomorrow.

Quote: "Also, I notice some shaders require specific texture file names to work."


No they don't. You specify at load time whether or not you wish to use the specific textures named in the shader - see the syntax for the load effect command.

Quote: "Couldn't you somehow make a shader dependent on the images in DBP's object texture stages? And how would you go about coding that?"


If you look at the numerous demos on this thread you'll see that most of them do exactly that.

Quote: "All I have succeeded in doing so far is to convert a non-compatible bump-mapping shader to work in Dark Basic..."


That's a good start for a newbie - you shouldn't find it difficult to make the minor changes necessary to get a diffuse/normal/specular shader.
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 26th Aug 2009 04:04 Edited at: 26th Aug 2009 04:07
Thanks GG! I found a normal\spec shader in the ultimate shader pack (made by ninja matt). I do have one problem with it though....the example bumped cube works fine. But when I load in my pre-UVed model, using this code:



...all that works is my diffuse. There is no bump mapping. But if I change this line....

to

...I get my diffuse again, only bumped with the normal map inputed into the shader file.

Any idea on how to get it to work with my UVed object?

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2009 13:13 Edited at: 26th Aug 2009 13:39
Quote: "Any idea on how to get it to work with my UVed object?"


Not immediately. I'll have a quick look at that shader and post back.

Edit Could you post the shader you're using? My version of the Ultimate Shader Pack might be corrupt (or out of date ). My copy of that shader doesn't contain a NormalSpecular technique which is odd.

Edit2 I don't have time to work out what's gone wrong with Ninja Matt's shader (especially since it's written in asm ). See if you can get the attached shader of mine working.

Attachments

Login to view attachments
HavokDelta6
15
Years of Service
User Offline
Joined: 22nd Aug 2009
Location: United Kingdom
Posted: 26th Aug 2009 14:17
are there any shaders out there, that will do a true refraction bassed on object depth, not just a bump map applied to visible surface (like evolved's does.)

Oh i'll do it later -.-
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 26th Aug 2009 22:40
No problem GG. The shader you made looks great, it just doesn't have a spec mask.

Thanks for your help.

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 26th Aug 2009 22:47
PLUG, Nudge - I think Green Gandalf and a few others are pretty decent with the shaders, and I would be first in line to buy a bundle pack of shaders that were designed to "operate" along side each other with relative ease.

We all have our strengths, and for me, it's coding... systems, etc... others its artwork, others shaders, and many of us are talented in various areas because that's kinda what being an indy is all about...

So... knowing full well I don't have the time or inclination to write a ton of shaders for DBPro/DarkGDK but love using them...

I want to say: Please, someone design a nice "bundle" with some demos and basic docs - I'll buy... would anyone else?

--Jason

Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 26th Aug 2009 23:05 Edited at: 27th Aug 2009 18:19
Quote: "I want to say: Please, someone design a nice "bundle" with some demos and basic docs - I'll buy... would anyone else?"

Me...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2009 23:06 Edited at: 26th Aug 2009 23:19
Quote: "No problem GG. The shader you made looks great, it just doesn't have a spec mask."


That's easy to fix. I assume the mask is zero if you don't want specular reflection and 1 if you do. I've got one lying around somewhere - but it'll be better if I just add it to the one I've already given you since that has some bug fixes.

Actually, I'll see if I can do it right now (sorry CuCuMBeR, you're not forgotten ).

Edit And here you are.

Edit2 Oops! Attached the spec map first time by mistake. Here's the shader.

Attachments

Login to view attachments
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 26th Aug 2009 23:09
Thank you! That will be much appreciated.

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Aug 2009 23:41
Just realised you probably haven't seen my edit(s).
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 27th Aug 2009 03:09
That's just what I was looking for! Wow, it looks great. And an added bonus is that it works with DB's shadow shader. Thanks again.

One last question: may I use your shader for commercial use?

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2009 12:52
Thanks for the feedback.

Any shader I post here is free for forum members to use as they wish. All I ask in return is that you include me in the credits and let me know that you have done that.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 27th Aug 2009 13:05
Quote: "Stuck in a queue. "

Quote: "Actually, I'll see if I can do it right now (sorry CuCuMBeR, you're not forgotten )."


I want my shader.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 27th Aug 2009 13:13
OK, I can take a hint.

Here is a public announcement:

No-one else gets a new custom shader from me till CuCuMBeR gets his shader.

I'll be away on holiday soon.
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 27th Aug 2009 13:38
Good news for me too!
aki
16
Years of Service
User Offline
Joined: 8th Nov 2008
Location:
Posted: 27th Aug 2009 20:02
I finally downloaded a tool called CrazyBump, and thought I'd throw it a mention in this thread - it's great for generating normal and heightmaps.

Quote: "I want my shader."

jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 27th Aug 2009 20:15 Edited at: 27th Aug 2009 20:16
that's what Knot So is... but cheaper. "Knot-So" Normal Mapper

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 28th Aug 2009 22:03
CuCuMBeR I've added the bumpmapped water to the shader and tweaked various things but I'm not happy with it yet. I'll post an update when I've made a bit more progress.

I'm waiting for inspiration.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 29th Aug 2009 09:31
Here is some inspiration



Note: You know how hard it is to find a dressed photo of this woman?

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Aug 2009 12:46
I'd call that a serious distraction.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th Aug 2009 17:08
Quote: "Here is some inspiration"

Who is it?

Your signature has been erased by a mod because we're sadistic losers with nothing better to do. (joke)
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Aug 2009 18:24
I wonder why Mobiius wants to know?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th Aug 2009 18:47
Curiosity.

Your signature has been erased by a mod because we're sadistic losers with nothing better to do. (joke)
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 30th Aug 2009 19:05 Edited at: 30th Aug 2009 19:06
Nastassja Kinski

EDIT: Where is my shadeR?

There is always one more imbecile than you counted on.
Alfa x
18
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 30th Aug 2009 19:18
Quote: "EDIT: Where is my shadeR?
"


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Aug 2009 19:34 Edited at: 30th Aug 2009 19:52
It's stuck in a GFX pipeline.

Anyway, you shouldn't have distracted me.

Edit Here's a screenshot of progress so far. The main problem is that the "breakers" don't seem to be connected with the other waves on the water. I'd like to fix that first - but entertaining family over the next few days so you'll have to wait just a bit longer.

Attachments

Login to view attachments
Math89
20
Years of Service
User Offline
Joined: 23rd Jan 2004
Location: UK
Posted: 30th Aug 2009 22:23
Don't know what it would do, but maybe you could shift the depthmap image according to the normal map. That way, the breakers might follow the waves.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 2nd Sep 2009 16:57
GG, you combined your two water shaders!


forever loading...
Lemonade
15
Years of Service
User Offline
Joined: 10th Dec 2008
Location:
Posted: 2nd Sep 2009 22:37 Edited at: 2nd Sep 2009 23:15
Looking good GG.

In case anyone here is attempting to learn HLSL like me, here's a link to a series of tuts (for beginners) that I found quite helpful:

http://rbwhitaker.wikidot.com/hlsl-tutorials

And the list of semantics:

http://msdn.microsoft.com/en-us/library/bb509647(VS.85).aspx

BTW, if anyone can find a good tutorial on post-process effects such as bloom, concussion effects, etc, I would be most grateful. And even more grateful if you could show me how to integrate it into DBP...

Check out my tech blog below!
http://cooltech-sciencelab.blogspot.com/
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Sep 2009 23:56
Good finds Lemonade.

Quote: "BTW, if anyone can find a good tutorial on post-process effects such as bloom"


The Help file in DarkShader is a good place to start.

Chris K posted some sources at the start of this thread. Might be something there. Otherwise try a search for bloom on this board. I'm sure this has been discussed before - with examples. Post back if you get stuck.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 3rd Sep 2009 11:39
Quote: "The main problem is that the "breakers" don't seem to be connected with the other waves on the water."


Can you make the normal map(water) get effected by the depth map(terrain heightmap) so it slowly gets transparent on the shores and changes color? So we can blend "breakers" with the shore to get a good enough visual.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Sep 2009 12:23
Quote: "Can you make the normal map(water) get effected by the depth map(terrain heightmap) so it slowly gets transparent on the shores and changes color? "


The transparency part is already there if you look closely.

I can change the colour at the same time. A good way of doing that would be to use an additional "foam" texture which is blended with the the main sea colour according to depth. That would be easy to add and would probably be all that's needed to improve the breakers. I'll try to find time today or tomorrow to do that. Do you have a suitable foam texture that I could use? It would save me quite a bit of time.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 3rd Sep 2009 12:55 Edited at: 3rd Sep 2009 12:58
Here are some seamless textures











There is always one more imbecile than you counted on.
Todd Riggins
20
Years of Service
User Offline
Joined: 29th Oct 2004
Location: Texas, USA
Posted: 3rd Sep 2009 16:30
lmao ... that made my day..

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Sep 2009 17:03
Thanks.

But I was thinking more of white horses than sea snakes.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 3rd Sep 2009 17:12
the first texture is what you are looking for.

There is always one more imbecile than you counted on.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Sep 2009 20:09 Edited at: 3rd Sep 2009 20:15
Quote: "the first texture is what you are looking for."


It isn't.

That's the hardest to implement unfortunately. I was thinking more of the third and fifth - although the fourth had its merits too.

The problem with the first is that you need to find not only the depth which is easy, but also the orientation which is possible and finally a simple measure of how far you are across that texture which I don't know how to calculate yet.

Sounds like a problem for Diggsey to me.

[Actually I have an idea of one way but it means precomputing another texture from the heightmap and is possibly a sledgehammer to crack a nut. I need more inspiration ...]

Edit Just had inspiration. I'm on the case again.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 3rd Sep 2009 21:25
Hi GG, would this work?

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: 3rd Sep 2009 22:27
It would in my original plan - but I can now see how to do it the way CuCuMBeR wants which should look better.

I just need to find () or make () a suitable lookup image for the orientation. I did something similar for my self-shadowing terrain shader and, with luck, the same look-up texture can be used. My only reservation now is performance - to get the right orientation I need to sample the heightmap three times. Anyway, enough speculating, it's down to work now (well after supper at least - and it's my turn to cook ). With luck I'll have something to report tomorrow.

Login to post a reply

Server time is: 2024-11-24 03:26:40
Your offset time is: 2024-11-24 03:26:40