Jump to content


Photo

Messing with sea water


  • Please log in to reply
28 replies to this topic

#1 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 05:54 AM

*
POPULAR

A suggestion that came up in the pub yesterday with Bikerdude & SirTaffsalot. My first not-quite-right attempt. I'll let the video fill in the details:

 


  • AluminumHaste, STiFU, Sotha and 14 others like this

#2 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 24 April 2016 - 06:47 AM

This is awesome steve, I love that soft edge and the way objects get darking as they deeper into the water.



#3 Sotha

Sotha

    Vertical Contest Winner

  • Active Developer
  • PipPipPipPipPip
  • 5597 posts

Posted 24 April 2016 - 09:44 AM

Yup! Seawater now has a "sexyness" attribute attached, which is nice. :wub:  I hope you can fix the remaining issues.


Clipper
-The mapper's best friend.

#4 VanishedOne

VanishedOne

    Advanced Member

  • Member
  • PipPipPip
  • 728 posts

Posted 24 April 2016 - 09:52 AM

I take it this is incorrect, then:
 

to the best of my knowledge, it is impossible to use 2 vfps in one shader. Thats the whole purpose of the undertaking. Believe me i've tried.


I wonder how long it'll be before someone tries adapting this for fog.


  • Deadlove likes this

Some things I'm repeatedly thinking about...

- louder scream when you're dying


#5 Goldwell

Goldwell

    Team Member

  • Active Developer
  • PipPipPipPip
  • 2149 posts

Posted 24 April 2016 - 10:14 AM

Fantastic job you've done there Steve! That water looks really good, I wonder how this would look with the clear water texture on it


The Accountant Series
Part 1 (coming soon) | Part 2: New In town


Lord Edgar Trilogy
Lord Edgar's Bathhouse | Lord Edgar's Disappearance | Lord Edgar's Estate
 
Stand Alone Missions
Spring Cleaning

#6 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 24 April 2016 - 10:15 AM

I wonder how long it'll be before someone tries adapting this for fog.

We can already do this, give me a sec to take some before and after images......



#7 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 10:23 AM

*
POPULAR

The fix for the distortion worked. I haven't done another vid because it'd be the same as the first one just without the bug:

 

Attached File  test_2016-04-24_16.20.21.jpg   268.77KB   2 downloads

 

 

 

 


  • Bikerdude, Arcturus, jaxa and 3 others like this

#8 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 24 April 2016 - 10:28 AM

Man that has got to be the fastest fix, for the smallest effort, for the best visuals.... to date...?



#9 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 10:28 AM

I take it this is incorrect, then:

 

You can have only one shader program of each type in any one material stage / draw call, but materials can have multiple stages.

 

The original sea water 01 material had 3 draws: one to distort the background, and two layers of sea water. 

 

The material I showed in the vid bumped that up to 4 draw calls for the water surface: The fixed version is back to 3, because the alpha layer is now drawn at the same time as the distortion. I merged the distortion shader program with the depth-testing one. 



#10 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 10:43 AM

Man that has got to be the fastest fix, for the smallest effort for the best visuals, to date...?

 

Heh I spent a good 90 minutes on that in total!

 

Because this is now a fix to the distortion shader that all waters use, we could in theory drop it into all existing water shaders like we did the fix for foreground distortion. You can set the depth at which the water looks completely opaque, either in the material file or with a shaderparm. For very clear water, you'd set it to something big like 1000000.

 

One potential fly in the ointment: I think people have achieved similar effects in the past with dark underwater fog lights, although that's buggy from a distance whereas this shouldn't be. But we can't just go changing all the default waters without checking what those look like first... it might be a bad combination in which case we'd have to content ourselves with some new murky shaders instead of upgrading old ones. 

 

I have to go cook but I'll tidy up the new vertex program and material file and post them here later. There's no engine change for this, it's just a couple of extra files that mappers can play around with and package with their map if they wish.



#11 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 24 April 2016 - 10:44 AM

Any chance I can test this on the WIp Melan and I are working on..?

 

Ninja'd



#12 VanishedOne

VanishedOne

    Advanced Member

  • Member
  • PipPipPip
  • 728 posts

Posted 24 April 2016 - 11:37 AM

You can have only one shader program of each type in any one material stage / draw call, but materials can have multiple stages.
 
The original sea water 01 material had 3 draws: one to distort the background, and two layers of sea water. 
 
The material I showed in the vid bumped that up to 4 draw calls for the water surface: The fixed version is back to 3, because the alpha layer is now drawn at the same time as the distortion. I merged the distortion shader program with the depth-testing one.

From the context of the thread I quoted, I think it was taking about multiple stages that use the program/vertexProgram/fragmentProgram keywords:
 

I wonder if you could just call each vfp in a separate stage in the same material definition?


to the best of my knowledge, it is impossible to use 2 vfps in one shader.


But anyway, evidently it is possible. Edit: maybe ungoliant's problem was with mixing postprocess effects...?


Edited by VanishedOne, 24 April 2016 - 11:49 AM.

Some things I'm repeatedly thinking about...

- louder scream when you're dying


#13 grayman

grayman

    Master Builder, Coder

  • Active Developer
  • PipPipPipPipPip
  • 11841 posts

Posted 24 April 2016 - 12:02 PM

Brilliant work!


  • AluminumHaste likes this

#14 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 02:45 PM

I want to try a different way of implementing it, but I'll post the WIP for Biker and anyone wanting to experiment with it. 

 

Material file

This is for your materials/ folder

Attached File  semiopaque.mtr.txt   1.45KB   28 downloads

 

Shader program

This needs to go in a glprogs/ folder alongside your other top-level folders (maps/,  materials/ etc). 

Attached File  heatHazeWithAlphaDepth.vfp.txt   6.35KB   22 downloads

 

__

 

How it works

The above shader draws a value 0.0 to 1.0 in the alpha channel of your screen. It says for each pixel, what % of the water shader to use and what % of the background colour to show. The two always add up to 100%. So if you set the opaque distance in the material file to 48 units (like it is in my example), and the distance between the water surface and the background for a given pixel is 16 units, then the alpha for that pixel will get set to 16 / 48 = 0.333, and you'll get 33% of the seawater shader and 66% of the background in the colour mix for that pixel. That's what "blend gl_dst_alpha, gl_one_minus_dst_alpha" means in the shader: multiply the colour from the current texture by the alpha that's already in the screen buffer (destination alpha) and the background colour by 1 minus the destination alpha. 

 

Next thing I want to try

That method might be too restrictive.. It's reduced the contrast in the seawater texture quite a lot. It's made the blue surface water brighter and the highlights duller.  I want to try something else, although I haven't really tried to fix it yet. We could make the second draw of the water texture independent of the alpha, for example. But the thing I want to try next is to get the shader to adjust the background colour directly instead of just setting up how it merges with the water surface texture. So we'd set an extra parameter in the material to indicate the opaque water colour. The shader would fade the background to that colour and not bother drawing anything into the alpha channel... you'd then just apply whatever water surface detail you want as a separate stage. It might be easier to adjust the water brightness that way. And it would be simpler too.

 

EDIT: Hmm we would lose the soft edge on the seawater that way. I guess we can leave both options open. Paint the alpha values, which the rest of the material can choose to use or ignore, and paint the water colour independently, again optional. I'll put together a few examples in another video so we can see what they look like.


  • Anderson likes this

#15 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 24 April 2016 - 05:02 PM

Could you use the diffuse texture from the dark seawater..? (textures/water_source/sea_water_002) or just make a darker version of sea_water_001

 

What value in the material def do I edit toe change how far the player can see through the water..? I guess I change the current value of 48 in the following line -

 

  -     vertexParm 2 ( 1.0 / 48.0 )   //  Set this to ( 1.0 / opaque_depth )

 

Also I'd like to try this new technique on a few other water textures -

 

- textures/water_source/water_green

- textures/water_source/water_blue

- textures/water_source/water_colored

- textures/water_source/water_dark

 

So with the depth set to 384, I took the following wip shots -

 

Attached File  wip1.jpg   248.14KB   3 downloads

Attached File  wip2.jpg   244.43KB   1 downloads



#16 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 24 April 2016 - 06:03 PM

What value in the material def do I edit toe change how far the player can see through the water..? I guess I change the current value of 48 in the following line -

 

  -     vertexParm 2 ( 1.0 / 48.0 )   //  Set this to ( 1.0 / opaque_depth )

 

Also I'd like to try this new technique on a few other water textures -

 

- textures/water_source/water_green

- textures/water_source/water_blue

- textures/water_source/water_colored

- textures/water_source/water_dark

 

So with the depth set to 384, I took the following wip shots -

 

Cool, they're looking good already even before we experiment with method #2 and other shaders. Yes as you discovered that's how to change the murkiness. I'll change it in the next version so you just put the depth in instead of ( 1.0 / depth ) which is unnecessarily confusing. 

 

I plan to put a more waters in a test map and try tweaking it for each. The ones you called out look like a good selection to start with. 


  • Bikerdude and Anderson like this

#17 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 25 April 2016 - 02:00 AM

Grand, the only issue with sea_water_001, its appears to glow so as a result the small boat looks like its floating in place rather than on the water.



#18 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 26 April 2016 - 01:51 PM

Grand, the only issue with sea_water_001, its appears to glow so as a result the small boat looks like its floating in place rather than on the water.

 

The best fix I've found so far is to use my original material above but reduce the rgb of the two water layers to 0.1 and 0.05. 

 

I've made a new test map with lots of water channels and I've started to play around with it. I've also made a shader program that can fade out the water to a set colour independent of the surface overlays. It's not added as much flexibility as I thought, for the sea water anyway... the original looked better. I'm still on sea water but most of our waters work quite differently. Sea water uses a filtering blend, so it always darkens the background. We might find other waters work better with the colour-fade shader. Still messing with the options, but in the meantime see what you think of the reduced-rgb version of the material I posted above. 


  • Bikerdude, Dragofer and Anderson like this

#19 Spooks

Spooks

    Member

  • Member
  • PipPip
  • 366 posts

Posted 26 April 2016 - 02:44 PM

I'm currently unable to test but off the top of my head how does the shader handle simple point lights underwater? I'm not assuming it does crazy subsurface scattering and all, just wondering.


My FMs: The King of Diamonds (2016)

 

Visit my Mapbook thread sometimes!


#20 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 26 April 2016 - 03:15 PM

It doesn't handle lights as such, so lights in the water would be treated the same as any light. Lights light surfaces, and surfaces behind the water have their resulting colour filtered by the shader according to how much water there is in the way. There'd be no glow in the water itself, just light from whatever surfaces get lit.



#21 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 26 April 2016 - 03:45 PM

but in the meantime see what you think of the reduced-rgb version of the material I posted above. 

Do you mean post #14, you update the link there is now update timestamp on the post.



#22 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 26 April 2016 - 03:53 PM

I haven't posted an update, I meant you can change the rgb numbers in that shader for the last two stages. Instead of rgb 0.2 and rgb 0.15 like I put in my posted material, it looks better and darker using rgb 0.1 and rgb 0.05.



#23 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 26 April 2016 - 04:01 PM

ah ok, will do.



#24 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 18643 posts

Posted 03 June 2017 - 05:05 AM

Material file

This is for your materials/ folder

attachicon.gifsemiopaque.mtr.txt

 

Shader program

This needs to go in a glprogs/ folder alongside your other top-level folders (maps/,  materials/ etc). 

attachicon.gifheatHazeWithAlphaDepth.vfp.txt

I think I tried using the new shader in PD3, but there was an issue.


  • SteveL likes this

#25 Springheel

Springheel

    Creative Director (retired)

  • Admin
  • 36413 posts

Posted 14 August 2017 - 09:05 AM

I tested this and discovered there is a significant problem...splash particles are not visible using this water surface.  While you can see the splash over top of the object making them, none of the splash displays over top of the water surface itself.

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users