Jump to content

A "psychic" shader mod; development begins...


DanW58
 Share

Recommended Posts

22 hours ago, hyperion said:

ERROR: Failed to compile shader 'shaders/glsl/model_common.vs':

0:138(2): error: `v_half' undeclared

0:138(21): error: `sunVec' undeclared

0:138(21): error: operands to arithmetic operators must be numeric

0:138(11): error: no matching function for call to `normalize(error)'; candidates are:

0:138(11): error: float normalize(float)

0:138(11): error: vec2 normalize(vec2)

0:138(11): error: vec3 normalize(vec3)

 

1 hour ago, hyperion said:

Still get the same error.

I can't imagine how this is possible.  Can you verify your model_common.vs is the same as what I have?

Lines 28 to 38 should read,


varying vec4 v_normal;
varying vec3 v_eyeVec;
varying vec3 v_half;
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX
  #if (USE_INSTANCING || USE_GPU_SKINNING) && (USE_NORMAL_MAP || USE_PARALLAX)
    varying vec4 v_tangent;
    //varying vec3 v_bitangent;
  #endif
#endif

Which declares varying v_half outside of any conditionals.

Then,  lines 130 to 138 should read,


  gl_Position = transform * position;

  vec3 eyeVec = cameraPos.xyz - position.xyz;
  vec3 sunVec = -sunDir;
  v_normal.xyz = normal;
  v_eyeVec = eyeVec;
  v_half = normalize(normalize(sunVec) + normalize(eyeVec));

where sunVec is declared as a type vec3 variable, outside of any conditions.

If what you got is the same, I completely don't understand.  If it isn't the same, we need to find out why;  there should not be such a bug in svn or diff to cause a changed file to be missed...

EDIT:  Diff 16014 under D3555 looks right.

 

@Stan` Thanks, I'm taking a short break from the blender adventure;  will get back to it shortly.  (To think I used to live my whole life inside Blender, many years ago, but today need to take frustration breaks from it, breaks my heart.)

Edited by DanW58
Link to comment
Share on other sites

I was playing around with the high water shader.  I wanted to try two things:  Using LOD bias in reading the bottom texture in proportion to the depth, to increase blurring.  This is NOT because water blurs light passing through it;  it is a surface effect, namely that waves are fractals, even at small and smaller range there's waviness, and this produces angular scatter, which then becomes a larger and larger absolute area scatter the longer it travels down from the surface.

In the shader, if I'm understanding the code, there's blurring of the bottom done manually by doing a bunch of reads with displacements, and averaging the values.  I wasn't going to mess with that, but was simply going to add a computed LOD bias, so that each of the reads would itself already have some blurring.

I found, to my surprise, that our terrain textures don't seem to have LOD's.  This is strange, because a texture with LOD's typically scales more smoothly as you zoom out than one without, which is quite desirable even if you are not manually trying to use bias.  So that effort failed.

The other thing I wanted to try was using a real Fresnel formula for specularity.

As soon as I did, sky reflections nearly disappeared, and the waves became hardly noticeable;  so I boosted the brightness of the sky-box, and multiplied the xy of the water normals by 5.  This is real Fresnel ... almost;  the algorithm is called Schlick's Approximation, but it is an approximation used in science;  far more accurate than typical graphics approximations.  The reason waves became more subtle is because the waviness was, in fact, rather subtle, as the Fresnel approximation that was used dramatically increased their visibility.

It looks different, and I like it, and I'm going to keep my high water shader mod for my own playing;  but it may not be for everyone.  The waves look more realistic in my eyes, but also a little rougher.  This, again, tells me this shader could use a uniform to control wave strenght for island hopping in rainy, stormy days.

There may also be a need for the map to control wave strength.  The strength I got I think is pretty good for seas, but lakes could use far less strength.  Notice how distorted the reflections are in the second shot below.  Some lakes could use an almost complete absence of waves.  (Then again, rivers could use increased murkiness.)

EDIT:  Never mind;  there ARE uniforms for waviness and murkiness.

((Actually, I may have stepped into some trap in the code... something affecting how reflections alpha-blend.  The reflections of the dock got too faint I think.))

Here's a comparison screenshot:  The original waves first:

OLDwater.jpg

The modified shader second:

NEWwater.jpg

 

There's a ...

#define USE_FRESNEL_APPROXIMATION 1

... that I threw in there, that causes the original code to compile.  Commenting it out causes my mod to compile.

Cheers!

 

water_high.fs

Edited by DanW58
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

Managed to fix the problem with reflections.  There was a tweak factor there of 0.75 alpha-blending that seemed to be necessary with the approximation, but seemed to break things with true Fresnel.

No; it doesn't work yet...

 

 

 

 

Edited by DanW58
Link to comment
Share on other sites

1 hour ago, DanW58 said:

I was playing around with the high water shader.  I wanted to try two things:  Using LOD bias in reading the bottom texture in proportion to the depth, to increase blurring.  This is NOT because water blurs light passing through it;  it is a surface effect, namely that waves are fractals, even at small and smaller range there's waviness, and this produces angular scatter, which then becomes a larger and larger absolute area scatter the longer it travels down from the surface.

In the shader, if I'm understanding the code, there's blurring of the bottom done manually by doing a bunch of reads with displacements, and averaging the values.  I wasn't going to mess with that, but was simply going to add a computed LOD bias, so that each of the reads would itself already have some blurring.

I found, to my surprise, that our terrain textures don't seem to have LOD's.  This is strange, because a texture with LOD's typically scales more smoothly as you zoom out than one without, which is quite desirable even if you are not manually trying to use bias.  So that effort failed.

The other thing I wanted to try was using a real Fresnel formula for specularity.

As soon as I did, sky reflections nearly disappeared, and the waves became hardly noticeable;  so I boosted the brightness of the sky-box, and multiplied the xy of the water normals by 5.  This is real Fresnel ... almost;  the algorithm is called Schlick's Approximation, but it is an approximation used in science;  far more accurate than typical graphics approximations.  The reason waves became more subtle is because the waviness was, in fact, rather subtle, as the Fresnel approximation that was used dramatically increased their visibility.

It looks different, and I like it, and I'm going to keep my high water shader mod for my own playing;  but it may not be for everyone.  The waves look more realistic in my eyes, but also a little rougher.  This, again, tells me this shader could use a uniform to control wave strenght for island hopping in rainy, stormy days.

There may also be a need for the map to control wave strength.  The strength I got I think is pretty good for seas, but lakes could use far less strength.  Notice how distorted the reflections are in the second shot below.  Some lakes could use an almost complete absence of waves.  (Then again, rivers could use increased murkiness.)

EDIT:  Never mind;  there ARE uniforms for waviness and murkiness.

((Actually, I may have stepped into some trap in the code... something affecting how reflections alpha-blend.  The reflections of the dock got too faint I think.))

Here's a comparison screenshot:  The original waves first:

OLDwater.jpg

The modified shader second:

NEWwater.jpg

 

There's a ...


#define USE_FRESNEL_APPROXIMATION 1

... that I threw in there, that causes the original code to compile.  Commenting it out causes my mod to compile.

Cheers!

 

water_high.fs 12 kB · 1 download

Looks much better

Link to comment
Share on other sites

Thanks!  I still have an issue with reflections, though;  they've nearly disappeared on me;  but the more deeply I look into the code the less I seem to understand.  Near the end of the shader, Fresnel is multiplied by an alpha channel coming together with the reflections ... My head is spinning.   I just deleted a line that modulated Fresnel by shadows ...  shadows don't affect Fresnel in the real world, unless it's some highly non-linear material good to build lasers with;  but not water ...

But anything I touch seems to break everything ...

Link to comment
Share on other sites

2 hours ago, DanW58 said:

the algorithm is called Schlick's Approximation, but it is an approximation used in science;  far more accurate than typical graphics approximations. 

Actually Shlick approximation de facto is a standard in the graphics and games industry. And even more it's imperfect for some cases on modern hardware. People try to find more accurate approximations: https://belcour.github.io/blog/research/publication/2020/08/26/brdf-fresnel-decompo.html

1 hour ago, DanW58 said:

But anything I touch seems to break everything ...

It's true life. But I'm working on water refactoring. And I've already removed a bunch of in-place hacks.

Link to comment
Share on other sites

@vladislavbelov

Okay,  good to hear.

Well, take my work in halted progress, then.  I have many comments I put on it you should find useful.

water_high.fs

 

EDIT:  I think the reason this mitsuba code is so complex is that it's mixing Fresnel with roughness.  I always knew they could not be combined linearly... Glad somebody tackled it,  though I'm not sure what to do with it;  seems big.

EDIT2:  The one problem that shader mod has is with reflected objects and terrain.  I can't get them reflections to show but very faintly.  I get them stronger if instead of,

reflCol = mix( sky, reflections, reflections.a);

I write,

reflCol = min( sky, reflections );

Seems something with the alpha channel in the reflections is not as expected.  You might be able to figure out what I messed up.

Edited by DanW58
Link to comment
Share on other sites

This "metal detecting" shader keeps getting better.

Even as I work in the new shader, once in a while I use the current shader (I mean MY current shader, the metal one), as a test bed for ideas, as well as for my gaming pleasure.  I just added two very, VERY subtle effects to human skin:  An emissive 0.01 red added glow just to account for body heat;  and a sort of emissive 0.03 red glow modified by shadows AND by sunColor, but not modified by view angle or light incidence;  in other words a very slight and primitive sub-surface scattering effect.  Together with Fresnel gloss this keeps making skin more and more natural-looking.

In the shot below, it is hopeless to try and notice these things, but when the women go into the shadow of the trees or come out into the sun, you do notice a hint of translucency, barely noticeable, but it makes a world of difference.  The perception of translucency is from the fact that the shadow side of the arms glows a tiny bit brighter when the arm is hit by the sun on the other side.

Look at the woman in the sun, and at the two women in the shadow of the trees.  Do the women in the shadow look a bit "cooler" than the one in the sun?  It's very subtle, but it's there.

And the Fresnel highlights of skin happen at particular moments, at particular angles, hard to catch in a screenshot, but when they happen they also add a ton of realism.  None of the women in the image are catching the sun in a specular way at the moment I got this image capture, but the men mining metal did catch some rays.

You people don't know what you are missing.  Yes, there are things you can criticize about this metal and skin detection hacks shader, but the benefits far outweigh the costs, and it is a FUN shader that keeps surprising the eye, such as by putting metal particle glints on the "metal" rocks for mining;  an unintended but highly beneficial "bug".

So far, as far as I know, NOBODY has ever even looked at this shader;  nobody has tried it.  They just look at the still pictures I post, and they lean back on their armchairs and criticize...  Most of the benefits are dynamic;  they cannot be appreciated from still images.

 

skinglow.jpg

Edited by DanW58
  • Thanks 2
Link to comment
Share on other sites

Actually, I just improved the shine on the skin, by toning it down with what I call "purity" in the new shader, namely the % of influence of the Fresnel reflecting layer.  For a car-paint, purity is 100%.  For a plastic it can range from 40% to 75%.  I found about 60% does the trick for human skin.  Otherwise it looks like it's got oil on it.  Even making the shininess low, it doesn't work, as it makes the skin look like it's in shiny nylon.  The only way to tone down the shine is by dialing down the % of the surface participating in Fresnel specularity.

 

newskin.jpg

  • Like 1
Link to comment
Share on other sites

2 hours ago, DanW58 said:

So far, as far as I know, NOBODY has ever even looked at this shader;  nobody has tried it. 

The problem is that most people in this forum dont use svn (me included) and the people that do are busy working on it and have not so much time for testing. So i can only say: I followed the progress of your shader development and i quite like it judging from the screenshots :D.  And as you can see from this thread :

People like to look at pictures. I would even suggest putting in a little screen capture video, if the effects of the shader are best seen in movement.

Link to comment
Share on other sites

Sounds like an idea.  How can I capture video, though?  I've never done that.  I'm on Ubuntu.

(In any case, you don't need to use SVN to apply my mod;  you can just do it by hand, though you might want to backup or rename each original file before replacing it.)

Link to comment
Share on other sites

for Ubuntu 18.04 and higher with the default Gnome desktop you can press Ctrl+Alt+Shift+R to capture a 30 sec video to youre video folder.

https://ubuntuhandbook.org/index.php/2020/01/record-ubuntu-desktop-built-in-screen-recorder/

Otherwise you need to use an extra screen capture software.
And good to know, i will try it when i have some free time.

Link to comment
Share on other sites

Then you probably need to try third party software.

As for testing your shader: I tried to replace the files that you provided in the other thread, but the binaries are zip compressed and windows wont let me replace it without unpacking first. Which means i have to decompress and recompress the complete binaries (several GB), which is something i'd rather not do.

Link to comment
Share on other sites

I'm installing "simplescreenrecorder".

I have no idea what binaries zip compressed you are talking about;  this is just a few files, none are binary, just a few k.

There's a bunch of .xml files, one .vs file and thre .fs files.  All are a few k in size.

I'll make an updated patch file.  In the meantime, here's just the shaders;  you can replace them alone, in the shaders folder,

..0ad/binaries/data/mods/public/shaders/glsl/

 

model_common.fs model_common.vs terrain_common.fs water_high.fs

Link to comment
Share on other sites

39 minutes ago, DanW58 said:

 

I have no idea what binaries zip compressed you are talking about;  this is just a few files, none are binary, just a few k.

You are using SVN, he is trying with the release, which is packaged (and precached NVTT remember?) in a single zip for faster file access on Windows HDDs so he has to uncompress the whole game :)

@maroder note that if you uncompress it correctly you won't have to recompress it since the game will just pick up the files.

41 minutes ago, DanW58 said:

I'm installing "simplescreenrecorder".

I would have suggested OBS but your call :)

 

  • Like 1
Link to comment
Share on other sites

Thanks for the tip Stan. Nevertheless, i tried as you suggested, but now i cant start the game anymore. It takes me directly to the mod selection, and if i click on "start mods" (public is the only one in there), it closes for a moment and then reopens the mod selection again.

I probably did something wrong during the process, but i wont bother fixing it and i will just reinstall the game.

Take home message: It easier if you provide screenshots and videos instead of investing the time to tell people how to incooperate your patch.

Link to comment
Share on other sites

6 hours ago, Stan` said:

You are using SVN, he is trying with the release, which is packaged (and precached NVTT remember?) in a single zip for faster file access on Windows HDDs so he has to uncompress the whole game

Ouch!  Wouldn't just copying the four shader files to the glsl folder work?

@maroder  I'm sorry, switching versions is not what I intended for anyone to do.

@Stan` I'll check out OBS.

EDIT:  simplescreenrecorder is working pretty well, though ...

Edited by DanW58
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...