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
Xlaydos
20
Years of Service
User Offline
Joined: 26th Mar 2004
Location:
Posted: 25th Jul 2009 20:03
Sorry for the late reply. Thanks for having a look at the mandelbrot shader for me Taught me a lot about the inner workings of shaders. Unfortunatly i don't have a PS3 or PS4 card, so i guess i am stuck at 512 instructions which isn't enough for detail at higher zooms.

Thanks for your time.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 26th Jul 2009 04:31
Quote: "Unfortunatly i don't have a PS3 or PS4 card, so i guess i am stuck at 512 instructions which isn't enough for detail at higher zooms."


I'm working on that.

[At higher zooms you have the added precision problem as well - finite precision arithmetic can't separate points which are very close together. ]
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 31st Jul 2009 00:10
bump... I don't want this thread to die!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Jul 2009 01:17
Don't panic!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 7th Aug 2009 16:23 Edited at: 7th Aug 2009 16:24
I would like to make a request.

A very simple water shader with cube map reflections and some basic bumpiness to actually show that its water.
water color is the only thing which should be editable.

finally the most importantly, i need shores to have some sort of waves.
(shores will be defined with a greyscale bitmap, lets say the more white, the deeper it is, the more black, the closer to the shore)

Thanks in advance.

EDIT: oh the water should be effected by fog (fog color and range should be editable also if possible)

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: 7th Aug 2009 17:01
Interesting request. I've been meaning to do something like this for some time.

Now would seem to be a good moment.

Games like King's Bounty: The Legend and Sid Meier's Pirates! have effects like that. Nothing like a challenge to whet the appetite.
Alfa x
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 7th Aug 2009 21:49 Edited at: 7th Aug 2009 21:50
That's gonna be usefull to our RTS project as well, since we will have mist of various colours in game. Can you keep the FPS as high as you can?

@ CUcumber: How you will do the fog?
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 8th Aug 2009 11:23
i wont be doing the fog, the shader guru who is going to create the shader i requested will implement the fog in the shader.
Which should be easy as 1 line.

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: 8th Aug 2009 12:11
Quote: "Which should be easy as 1 line."


In that case you could add it yourself.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Aug 2009 23:04
OK, here's the first draft of a shader according to CuCuMBeR's "simple" spec.

I'm going to develop it in stages. Most of the spec is standard so I'll do that later. The interesting stuff is getting the breakers on the waves near the shore. This demo is a first stab at that aspect and comments are welcome.

I'm unlikely to attempt to make the breakers match the waves that will eventually be visible on the water - but you never know.

The demo uses a screen resolution of 1680x1050x32 - just change that if necessary.

I hope the division between land and sea is obvious. The "land" will eventually be made using a new object (such as an Advanced Terrain object) but at the moment is just part of the same plane as the sea.

** Note: The project file was created using a beta version of the new editor which uses an absolute path for the executable - you will probably need to change that before compiling and running the demo (or delete the project .dbpro file and create a new project - whichever you prefer).

Attachments

Login to view attachments
aki
15
Years of Service
User Offline
Joined: 8th Nov 2008
Location:
Posted: 9th Aug 2009 02:59
Wow GG, awesome shader so far. I never knew about the Time parameter! I can't wait to see it finished.
david w
18
Years of Service
User Offline
Joined: 18th Dec 2005
Location: U.S.A. Michigan
Posted: 9th Aug 2009 06:40
I wish I had time to try to write or at least help with that shader.

What I really want to make is a morph shader. Now that would be sweet. I think when I get my current project wrapped up a bit more I may take a stab at it.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Aug 2009 13:18 Edited at: 9th Aug 2009 13:19
Quote: "What I really want to make is a morph shader. Now that would be sweet. I think when I get my current project wrapped up a bit more I may take a stab at it."


I hope you do. I'm sure it can be done. I had an unsuccessful attempt during the nVidia competition when Scraggle was hoping to include one in his ConCentric game - but I was still fairly new to shaders myself back then. One thing I didn't allow for then was the recalculation of the normals to get the lighting right. You probably also need a reasonable number of polys to get a good effect.

Anyway, good luck with that and I hope you post progress here so we can help out if necessary.

Quote: "Can you keep the FPS as high as you can?"


I'll try.

The first task though is to get something working, code optimisations come later. Shaders are one of the few occasions when it can pay to get every last bit of performance - mainly because the instructions are being processed millions of times a second. Although I'll be developing the shader on my main machine I will test it on my old dinosaur and laptop as well so I'll have a good idea of its performance overall. I won't have time to work on this today but expect to return to it tomorrow or Tuesday.

Quote: "Wow GG, awesome shader so far. I never knew about the Time parameter! I can't wait to see it finished."


Thanks aki.
Alfa x
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 9th Aug 2009 15:25
Hi GG,
the shader is looking good so far.
You are really, really good at this, the waves look outstandig.

Quote: "The first task though is to get something working, code optimisations come later. Shaders are one of the few occasions when it can pay to get every last bit of performance - mainly because the instructions are being processed millions of times a second. Although I'll be developing the shader on my main machine I will test it on my old dinosaur and laptop as well so I'll have a good idea of its performance overall. I won't have time to work on this today but expect to return to it tomorrow or Tuesday.
"


Ok. Can you include different levels of quality when you get it to work too?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Aug 2009 17:19
Quote: "Can you include different levels of quality when you get it to work too?"


Several different levels of fog should do it.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th Aug 2009 12:04
Not bad.

Your signature has been erased by a mod because it is way too awesome!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 10th Aug 2009 12:56
Nice waves, thats what i really needed. Can you use a white foam texture with the gradient stuff instead the breaker texture?

Now with a simple cube reflection and some bumpiness and maybe some transparency, it will be a great water.

Allright, as you insisted alot that i do the fog, here it is as simple and useless as possible.



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: 10th Aug 2009 13:32 Edited at: 10th Aug 2009 13:33
Quote: "Nice waves, thats what i really needed."


Thanks.



Quote: "Can you use a white foam texture with the gradient stuff instead the breaker texture?"


That will require some thinking about . The present method uses a single coordinate, depth essentially, for the wave texture lookup. A standard texture, e.g. foam or whatever, would require a second coordinate from somewhere. I just need to decide on the simplest way of doing that.

Quote: "Now with a simple cube reflection and some bumpiness and maybe some transparency, it will be a great water."


Yes, I was thinking of adding some transparency even though you didn't mention it originally. I've seen it used in some games and it looks really good. It certainly helps to have an example game scene to look at.

Quote: "Allright, as you insisted alot that i do the fog, here it is as simple and useless as possible."


You may have succeeded. I'm not convinced vertex fog will always work properly. I'll check it though.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 10th Aug 2009 14:36
Quote: "You may have succeeded. I'm not convinced vertex fog will always work properly. I'll check it though."


I dont know how to calculate it manually and add it the pixel color.

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: 11th Aug 2009 02:14
Quote: "I dont know how to calculate it manually and add it the pixel color."


Have a look at this.

Fog has been added and the dba code has been tweaked a bit.

Will add water next.

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 11th Aug 2009 09:57
nice.

But you know the problem, when you are close to the shore you see the pixel waves. Thats why we need a better texture on the waves.

There is always one more imbecile than you counted on.
SAAB Driver
18
Years of Service
User Offline
Joined: 1st Nov 2005
Location:
Posted: 13th Aug 2009 22:32 Edited at: 13th Aug 2009 22:34
Hi guys

I have been asking this question a few times before cause i need to solve this shader problem. But no real answer has been told.
I have load up a FPSC map in darkbasic, when i try to run a fullscreen shader code this happens. [img]null[/img]

In this code im using the bloom effect.

The texture disapear, there must be a way to solve this, to make the texture appear again.

heres the full code:



Please help.

Hello!

Attachments

Login to view attachments
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 14th Aug 2009 09:22
Try changing

To


Your signature has been erased by a mod because it is way too awesome!
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 14th Aug 2009 16:19
Any progress on my water?

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: 14th Aug 2009 18:22
Quote: "The texture disapear, there must be a way to solve this, to make the texture appear again."


Was it there to begin with?

What happens if you just load object 901 without the shader and camera stuff?

Quote: "Any progress on my water?"


Not yet - been busy with other things the last few days. Will return to it soon.
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 15th Aug 2009 10:04
Hey Green Gandalf...i've been reading through this thread and it looks like you're really good with shaders, i'm very new to writing shaders. Do you know how to add shadows to one of my point lights? or perhaps if i change it to a directional light?

Check out my game...the artwork isn't really holding up right now, but here are the controls

a,q,w,e,d,c,x,z: directions
r,t: attacks

all the art in there is really just temp...i think i need to see how the final shader will look before i spend anymore time creating art. The animations are pretty rough looking too, but the combo system is working.

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 Aug 2009 13:18
provoststeven

Not sure whether this helps:

real time shadows
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Aug 2009 20:19
CuCuMBeR

Have a look at the attached demo. It's just a water effect. Is that the sort of effect you want to add? If so I'll add it to the "breaking waves" shader.

Attachments

Login to view attachments
Alfa x
17
Years of Service
User Offline
Joined: 1st Jul 2006
Location: Colombia
Posted: 16th Aug 2009 01:28
Wow!.
Excellent water effect.
Do you have more variety of water effects beside this?


PS: I know you didn't asked me.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 16th Aug 2009 03:08
Quote: "Do you have more variety of water effects beside this?"


A few - but some look more like wobbling jelly than water.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 16th Aug 2009 14:56 Edited at: 16th Aug 2009 14:59
that effect looks really nice!

CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 17th Aug 2009 10:06 Edited at: 17th Aug 2009 10:13
Yes it looks like a great water, maybe you can make 2 techniques with one doesnt have any specularity or fancy stuff?

And there seems no transparency?

Aaand, instead the plain water texture, can we just use a rgb color for the water?

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: 17th Aug 2009 12:10
Quote: "Yes it looks like a great water"


Thanks.

Quote: "maybe you can make 2 techniques with one doesnt have any specularity or fancy stuff?"


I'm sure I can remove the fancy stuff.

Quote: "And there seems no transparency?"


Not yet.

Quote: "Aaand, instead the plain water texture, can we just use a rgb color for the water?"


Yes - but you then lose the option to have a more interesting texture.
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 17th Aug 2009 12:25
Quote: "I'm sure I can remove the fancy stuff.

Yes - but you then lose the option to have a more interesting texture."


Just nevermind, we want the cheapest possible water dont we?

There is always one more imbecile than you counted on.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 17th Aug 2009 16:06
and it might be better if it is smoother. Of course, it's another thing actually doing that...

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Aug 2009 17:07
Quote: "and it might be better if it is smoother"


That's mainly a matter of finding a more suitable normal map - I just used the first one I could find for the demo.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 17th Aug 2009 19:32
by smoother I meant that on my comp the movement is jerky.


forever loading...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Aug 2009 21:42
Quote: "by smoother I meant that on my comp the movement is jerky."


Yes, I've sometimes noticed that - but mainly on my old machines. The movement on my new PC is smooth. Till I had this new machine I wasn't convinced it wasn't just an optical illusion - but now I think it's a limitation of certain graphics cards. I've no idea of the cause or how to fix it. I've noticed it on several shader demos which involve scrolling images so I guess it's something to do with that.
aki
15
Years of Service
User Offline
Joined: 8th Nov 2008
Location:
Posted: 17th Aug 2009 22:31
Quote: "Yes, I've sometimes noticed that - but mainly on my old machines. The movement on my new PC is smooth. Till I had this new machine I wasn't convinced it wasn't just an optical illusion - but now I think it's a limitation of certain graphics cards. I've no idea of the cause or how to fix it. I've noticed it on several shader demos which involve scrolling images so I guess it's something to do with that. "

Instead of using the time parameter, I always used an internal DBP variable which is regulated via timer() and passed it into the shader.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Aug 2009 23:05
Quote: "Instead of using the time parameter, I always used an internal DBP variable which is regulated via timer() and passed it into the shader. "


Does that solve the problem?

My experience of doing it that way is that it makes it worse - but it's a long time since I tried that method.
aki
15
Years of Service
User Offline
Joined: 8th Nov 2008
Location:
Posted: 17th Aug 2009 23:27
Quote: "Does that solve the problem?"

It should - unfortunately (or not so much) I don't have the smoothing problem on this computer so I can't tell.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2009 01:39
Quote: "It should "


Why?

When I get time I'll power up Dinosaur and try both ways and see what happens.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 18th Aug 2009 15:03 Edited at: 18th Aug 2009 15:26
[nevermind]


forever loading...
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 18th Aug 2009 15:23 Edited at: 18th Aug 2009 15:24
Guys please dont interrupt, i think the shader is coming up nicely.
If the animation looks jerky on your computer, it is because your computer sucks.

Gandalf, i appreciate you spending time on this shader, and im hoping to see the finished one soon.
But the 1pixel waves on the shore has to change into a better texture.

There is always one more imbecile than you counted on.
thenerd
15
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 18th Aug 2009 15:26
sorry,


forever loading...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Aug 2009 16:11
Quote: "Gandalf, i appreciate you spending time on this shader, and im hoping to see the finished one soon."


Thanks for that. Sorry about the delays - I'm in the middle of the frantic harvest season in my garden at home so other things are getting delayed. I will finish this as soon as I can.

Quote: "But the 1pixel waves on the shore has to change into a better texture."


I will certainly fix that if I can - probably once I've got a full working demo with all the main features added.
provoststeven
14
Years of Service
User Offline
Joined: 17th Jul 2009
Location: Irvine, California
Posted: 19th Aug 2009 09:46
does anyone know of good sources for shaders online? I've already seen the nvidia library, and i couldn't find what i'm looking for. All I need is a shader that supports all of the following:

diffuse maps, normal maps, specular maps, emissive maps and shadows

(emissive means glow)

it'd be nice with a post bloom effect...but if not, that's cool.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2009 18:25
CuCuMBeR

Quote: "Allright, as you insisted alot that i do the fog, here it is as simple and useless as possible."


Believe it or not I'll probably be using something very similar to your method in the final version. I've just done some testing on a different project and your method using effect states is noticeably faster than my method especially on older machines.

I'm glad I "insisted" now.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 20th Aug 2009 22:50
Quote: "Believe it or not I'll probably be using something very similar to your method in the final version. I've just done some testing on a different project and your method using effect states is noticeably faster than my method especially on older machines."


Ouch! I forgot something very basic. Back to the drawing board.

Anyway, here's the latest demo. Progress so far:

1. I've aligned the waves with a terrain.
2. Added fog to the sea, terrain and skybox (the fog on the sea doesn't quite match the terrain's fog yet).
3. Added transparency to the sea.

Still to do:

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. ]

Attachments

Login to view attachments
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 21st Aug 2009 11:32
Quote: "Believe it or not I'll probably be using something very similar to your method in the final version. I've just done some testing on a different project and your method using effect states is noticeably faster than my method especially on older machines."


Hehehe.

Quote: "1. I've aligned the waves with a terrain."


I dont think the waves are aligned at the shore. Maybe you can use a black and white image to define the borders instead the greyscale map?

There is always one more imbecile than you counted on.

Login to post a reply

Server time is: 2024-06-17 16:57:10
Your offset time is: 2024-06-17 16:57:10