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 / Water Shaders -- Seriously ?

Author
Message
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 11:15 Edited at: 8th Sep 2011 11:16
Uhmmm how can I put this delicately ... Shaders Suck !! How do you people do this with ease. I don't get it.

I just cannot seem to get the hang of it. I almost had it once.. but then the reflection of the water would not shown up. So I enabled the fast syncs and other stuff.. and it seams to make it worse. I seem to be not getting anywhere. I see that clipping has a HUGE role in this. But its 4 AM in the morning and I been up all night working this in.

Anyone got a clue here ? Here is the Source code with the water shader included.

Thanks guys.

"Life is like a box of chocolates.. eat it before it melts."
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 12:39 Edited at: 8th Sep 2011 13:01
Why blame shaders generally?

Have you checked the many water shader demos lurking on this site?

Quote: "But its 4 AM in the morning and I been up all night working this in."


Coincidence?

Anyway, I'll take a quick look.

Edit I couldn't see where you put the output from cameras 1 and 2, i.e. where do you create the reflection and refraction images? You need to use set camera to image and to make sure that those images are passed to the shader - as in Evolved's code which I guess you have.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 15:50 Edited at: 8th Sep 2011 16:21
Quote: "Why blame shaders generally?"


I do not understand your question. I never said I blame shaders.


Quote: "I couldn't see where you put the output from cameras 1 and 2, i.e. where do you create the reflection and refraction images? You need to use set camera to image and to make sure that those images are passed to the shader - as in Evolved's code which I guess you have."


That command "set camera to image" would go into the section where the cameras would go. But anytime I have used that, it does not work. And I do not know ANYTHING about shaders. Its why I am asking for help here. I supplied my code so anyone can show me if some code needs to be changed and if I am missing something, as your saying. Maybe someone who understands it, can show me exactly where to put a missing piece or at least show me how I'm supposed to write it. Because shaders is the one thing, as I said, that I cannot seam to get a grasp of.

Quote: "Have you checked the many water shader demos lurking on this site?"


Yes, where do you think I got the shader I am using from. In fact ALL of the shaders except this one demo, did not work because the examples are too old or the ZIP file that one could download was missing in one way or another. The whole folder on Shaders is a joke do to a lack of updated content. That thread started back in 2005. I read for two days on that thread, but it has a LOT of missing code or lack of info do to the changes that the compiler has taken over the past years. In fact, the demo I did find, was a fix to an older copy of the demo that did work at one time and no longer does because of the newer compiler versions.

EDIT : Just so you know, I tried adding the "set camera to image" and all I got was a blue screen when I did that.



"Life is like a box of chocolates.. eat it before it melts."
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 16:19 Edited at: 8th Sep 2011 16:21
Quote: "Shaders Suck !!"


Your words not mine.

I suggest you calm down and take things one at a time. Your demo will not work unless you create the reflection and refraction images as in Evolved's demo. Reinstate the set camera to image commands that are missing from your code. Then we can take it from there.

Edit Our posts crossed. I'll check your extra code now.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 16:22 Edited at: 8th Sep 2011 16:30
Quote: ""Shaders Suck !!""


Wow I must have been tired for me to say that in the forum. My bad.. lol

And I did add those two by the way. You should see them in the water section. And it updates in the DO LOOP which is inside the Terrain section.

Quote: "Edit Our posts crossed. I'll check your extra code now."


Thanks bro. And I am calm, I'm just frustrated that I cannot grasp the concept of shaders. I mean why is more then 1 camera used. Things like that, which I could not find an answer to anywhere else.

I can explain how the ATOM works from an atomic level, but you give me a shader and I am like WTF is this happy horse <<bleep>>. ha ha ha

"Life is like a box of chocolates.. eat it before it melts."
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Sep 2011 16:47
A shader is just like an after effect added to something rendered to an image. Sometimes you need more cameras to view the model at different angles at the same time.

Water shaders tend to use extra cameras for this reason (although I'm sure you could use just one camera a lot of the time) because you need views of the scene from different angles or with different settings to get reflection and refraction.

The shader just tells the graphics card how to manipulate the given rendered images.

I'm sure GG could give you a more informed answer as he is our resident shader guru but that's basically it I think...

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 16:57
Quote: "I'm just frustrated that I cannot grasp the concept of shaders."


I sympathise - this particular shader demo is not the best place to start.

Quote: "I mean why is more then 1 camera used."


This particular shader uses a reflection of the surrounding scene. This is obtained by placing an additional camera below the water surface. The set camera to image command then outputs this version of the scene to an image so it can be used to form the reflections seen in the water. The other camera is used to form the image that is used to render the refracted scene seen through the water. There are other ways of doing this.

Regarding your code I'm not sure where the problem is exactly. Both images seem to be correctly created by the two camera renders but, as you say, the whole scene disappears and you just get the blue backdrop. I have to admit that is baffling me at the moment, i.e. why would two missing textures appear to work when supplied textures don't? I'll do a bit more experimenting now but I'll have to break off and do something else soon - then I'll return to this again later.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 16:59 Edited at: 8th Sep 2011 17:27
So the order of how the code is can be important then ? Like Camera position needs to be set before the Shader ? I think that's how I set this up. I think.... :/

Quote: "Regarding your code I'm not sure where the problem is exactly. Both images seem to be correctly created by the two camera renders but, as you say, the whole scene disappears and you just get the blue backdrop. I have to admit that is baffling me at the moment, i.e. why would two missing textures appear to work when supplied textures don't? I'll do a bit more experimenting now but I'll have to break off and do something else soon - then I'll return to this again later."


I appreciate any help you can give to this problem. And The info you guys have given here has already started to help me understand things. Thank you for this.

I am wondering though. I do not have Camera 0. I only have Camera 1 and 2. Do I need Camera 0 ?

"Life is like a box of chocolates.. eat it before it melts."
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 17:33
You do have camera 0 - it is the default camera. You specify the camera mask to use it here in the UpdateWater function:



and the sync itself is here in your main loop:



Somewhat confusingly you have your camera positioning commands all over the place which makes your code hard to follow - but that in itself is unlikely to be the problem. I'm still baffled and I'll have to leave this for a bit now.

By the way, why have you got object 3 and object 500? They both seem to be water objects or have I misunderstood?
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 17:49 Edited at: 8th Sep 2011 17:51
Ok, I updated the code. Now I can see and move. But the reflection is wrong. Its all black.

As for Camera 0, I added it, and that is how I am able to get the game to work. Check it all out with the shaders, I set everything to its defaults according to the demo I had and now I am able to walk around. But again, the water is all black.

As for both objects 3 and 500, it was in the demo, so I tried to make sure it worked. I am still not sure why it needed both, although both are set as water.

Anyhow, here is the full code.

"Life is like a box of chocolates.. eat it before it melts."
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 17:50 Edited at: 8th Sep 2011 17:53
Here is the picture I get with the above code so far.



Keep in mind, OBJECT 2 I have setup as a sphere so that there could be some sort of reflection in the water. If there was no skybox ( sphere ) at all, the water would never reflect.

"Life is like a box of chocolates.. eat it before it melts."
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 18:20 Edited at: 8th Sep 2011 18:50
Ok, I think I solved the riddle of the two objects. 3 is the lower part of the water. The 500 IS the water surface itself.

I fixed the code, and its working accept the black part still. But go under water and then back above water and watch what happens. I am shading the surface. So now I need to find out why its not getting shaded in the first place.

I believe it has to do with the way its setup here :



Newer Updated Full Source Code on this post. Current File Name is ActiveTerrain-9-8-2011e.zip

Two things I think I am doing wrong. 1.) it looks like I have something out of order because according to the above code, its not getting IMG to begin with. 2.) in the code where it checks if the camera goes above or below the sea level, it shades the water with a texture. I had changed it from shading Obj 3 to Obj 500. I should have left it at 3.

EDIT : Ok I worked out those two problems and its pretty close to the original demo. It works and thats what counts here. Now I just need to work out some glitches with it. Like the black that shows up when you rotate the camera down. Other then that it seams to be working.

"Life is like a box of chocolates.. eat it before it melts."
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 18:48 Edited at: 8th Sep 2011 18:51
I finally got it !! Newly updated file in above post. ActiveTerrain-9-8-2011e.zip





"Life is like a box of chocolates.. eat it before it melts."
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 19:01 Edited at: 8th Sep 2011 19:03
Found time to have a look at your revised code.

I'm wondering whether DBPro functionality has changed somewhere. I changed your code so that the cameras and their images were created before texturing the water object. I also changed one texturing line which semed wrong. This now gives something resembling water:



A few things still need tweaking but at least you seem to have water now.



Edit I see you've fixed it too. You posted while I was messing about with my post.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 19:05 Edited at: 8th Sep 2011 19:09
Ha ha ha.. yea I found the glitch and location was all the same and the one. ( If that made any sense lol )

Now I have to figure out why the water turns black when I point the camera down.

Thanks for all the input guys. I really appreciate it.


My glitch...



"Life is like a box of chocolates.. eat it before it melts."
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Sep 2011 19:20
Yes I noticed that. Does the black disappear if you point the camera straight down and then up again? It does on mine.

I think the problem is connected with the clipping region - part of the image won't be rendered and if the reflection/refraction calculations in the shader don't allow for this then they will return black until that part of the image has been rendered at least once. I'm not sure why the clipping plane has been set some distance above or below the water level. In fact you could simply comment out the clipping lines - I'm not convinced they help much.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 19:29
Ahh ok.. i'll look into that.. In the meantime here is the newest code with the update you mentioned in the earlier post..




File Name "ActiveTerrain-9-8-2011f.zip

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 19:32
Same with meh :3

Also, nice, but when u back up, the water starts turning pixely :S

Also, glitch. take a look at the pic :3

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 19:43
Ok, code updated and I believe I got rid of that flashing now. I also commented out the clipping and it seams to be working better now.

Now all I need to do is darken the water some and viola..

ActiveTerrain-9-8-2011g.zip

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 19:56
Ok, MUCH better. BUT the physics of the water when u look at the water from under need to be MUCH slower

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 20:00
Plus, the underwater physics is a little shaky o.o

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 20:03 Edited at: 8th Sep 2011 20:05
Hey Mugen, can you do me a favor and not double post. You can always edit your previous post. I ALWAYS check and read all posts. So I will not miss anything. Thanks man.

On another note, there are no physics on the water. Never has been. This is strictly a shader. Shaders do not have physics. I have not added Physics to this project yet.

EDIT : I will be adding a timer to slow the water down some.. but I got some other stuff I am going to change first before I bother what the speeds yet.

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 20:05
What I mean by "physics", is the way the water moves when ur under the water and u look above

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 20:07 Edited at: 8th Sep 2011 20:08
Is this what your seeing ? If so then its not the water, its my skybox reflection. I am using a solid color for my sphere ( skybox ) because I have not added an environment yet. I didn't want to mess with that until I got the water working first. Now I will be able too




"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 20:11
Do u see how fast the water "jiggles", when ur under it? THATS the problem. it needs to be MUCH slower.

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 20:23
Yes, I have the timer code in there. But I have not set it to utilize that yet. So until then, I am leaving it as it is. But thanks for the info.

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 20:30
Just use this man. Stop re-inventing the wheel

http://forum.thegamecreators.com/?m=forum_view&t=83455&b=6

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 21:14 Edited at: 8th Sep 2011 21:14
Quote: "Just use this man. Stop re-inventing the wheel"


Apparently you didn't read my previous posts as to what and why I am doing this.

And I checked out that code. The water was static. Mine at least moves. I like mine just fine.

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 21:14
U want EXTREME water? HERE'S extreme water. See Attachment

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 21:16
HAD to make new post for this. the forum only uploads 1 file per post. And Im too lazy to upload the pic myself

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 21:24
Yea, that doesn't help since its an EXE only in that file.

"Life is like a box of chocolates.. eat it before it melts."
Mugen Wizardry
User Banned
Posted: 8th Sep 2011 21:26
Do u like it? Yes or no. I can release the source if u do

CHECK OUT MY WEBSITE AT http://imageposeidon.com/ !
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 8th Sep 2011 21:29
I am starting to think your missing the point entirely. I have the same exact water as what is in that picture. The difference is I do not have my environment set up yet. And I am making my environment to work real time, not a static skybox like what your showing me there. I do not like that fake stuff. I am trying to add Night / Day cycles to my code. And the speed of the water is do to the fact that I have not setup my timer() function yet to work with it. I will have nice water once I get done working on some other stuff. Its all good bro.

"Life is like a box of chocolates.. eat it before it melts."

Login to post a reply

Server time is: 2026-07-11 14:37:15
Your offset time is: 2026-07-11 14:37:15