Jump to content

Flickering shadows!


gameboy
 Share

Recommended Posts

On 08/02/2021 at 4:43 PM, hyperion said:

How the ancients used white in architecture it's unreasonable that the ground is "whiter" than the CC. While the ao might have improved I guess it also highlights the need to fix base colour.

To really give an answer whether I share @Stan` fear you claim please provide all your changes as a single patch against trunk or a mod to play with.

https://code.wildfiregames.com/D3555

It's diffed from the folder .../binaries/data/mods/public

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

On 08/02/2021 at 5:49 PM, wowgetoffyourcellphone said:

Dear god that's too dark. 

Hopefully it no longer looks too dark, even though it's the same brightness, after adjusting down the terrain.  See my second-last post for screenshots.

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

I just added yet another shader hack.  And a hack it is.  Despicable.  Reprehensible.  But it kind of works.

I got tired of seeing things like yellow bracelets and headbands that I KNOW were meant to look like gold or bronze but look like yellow paint instead.  So I wrote a disgusting algorithm to decide whether metal was intended, and where it decides that metal was intended, it shamelessly changes the diffuse and specular colors to make the thing look metallic.  So, this is totally in lieu of fixing the art.

This is what the relevant fragment shader glsl code looks like:

    float is_metal =
specCol.r*specCol.r*specCol.g*specCol.g*texdiffuse.r/max(texdiffuse.r,texdiffuse.g)*texdiffuse.g/max(texdiffuse.g,texdiffuse.b);
    is_metal *= 4.0;
    specCol = mix(specCol,sqrt(texdiffuse),is_metal);
    texdiffuse = mix(texdiffuse,texdiffuse*texdiffuse,is_metal);

Check out the bronze wrist bands and copper head band on Mr Faro, and the gold headband on his Wife.

metal.jpg

model_common.fs

metal2.jpg

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

Thanks for the encouragement.

This version now works better.  Pretty good with Ptolemaic, but the problem with the Athenians was that the texturing there makes so little sense it's nearly impossible to work with.  Like the fountain in the civic center has a ring of carpeting around, looks like persian carpeting, but obviously it has a high specular value and I can't avoid detecting it as a metal.  Maybe polished stone was the intent.  The Greek columns, I'm not sure what kind of material they are, but they seem to have high specularity AS WELL AS being white in diffuse, so they detect as metallic and get unduly darkened.  On the plus side, the Athenian spearmen's bronze helmets and shields shine!  But I got better news;  even as I was writing this post, it occurred to me I could force sense into the texturing right in the shader, before trying to detect metallic intent, simply by clamping the specular color to (0,0,0) to ((1,1,1)-diffuse),  that way, texels for which the textures add to more than white are corrected down.  This "sense injection" is what the first 3 lines of the code below do.  The second part is "metallic intent" detection, and the third part is what it does to the diffuse and specular colors in order to implement the metallic look.

So, this is not advocated as a permanent mod;  it is more of a teaching tool or demo.  Which doesn't mean I don't suggest it be incorporated in A24;  I actually do;  it will make the game look much better.  Even if it's a hack, it's a hack that helps break the plastic look monotony by depicting a few items as clearly metallic; and this is a Good Thing (TM).  What it does mean is that I suggest it be in A24, but then removed by A25, by which time most of the texturing should be revisited and made sense of;  and metallic/non-metallic distinctions should be made clearly and deliberately in the art itself, not in a shader.

However, I have trepidations about throwing this into D3555.  Partly, I'd rather wait for feedback first;  partly I think I can improve this hack further...

Relevant glsl code in model_common.fs:

    vec3 ZERO = vec3(0.0);
    vec3 ONE  = vec3(1.0);
    specCol = clamp(specCol,ZERO,ONE-texdiffuse);
    
    float is_metal;
    is_metal = dot(texdiffuse,texdiffuse);
    is_metal *= clamp(1.0-100.0*(texdiffuse.g-texdiffuse.r),0.0,1.0);
    is_metal *= clamp(1.0-100.0*(texdiffuse.b-texdiffuse.g),0.0,1.0);
    is_metal *= max(max(specCol.r,specCol.g),specCol.b);
    is_metal -= (texdiffuse.b*0.75);
    is_metal = smoothstep(0.05,0.2,is_metal);

    vec3 metal_specCol = sqrt(texdiffuse);
    vec3 metal_diffCol = texdiffuse*texdiffuse;
    specCol = mix(specCol,metal_specCol,is_metal);
    texdiffuse = mix(texdiffuse,metal_diffCol,is_metal);

Also on the positive side, note how some of the vases are clearly painted terracotta (the big ones), but the smaller ones look metallic (bronze).  Unfortunately, the chickens detect as metallic, but the end result doesn't look metallic, anyways.  Who would be going around making chickens specular?  Beats me...  The skins of most human models also detect as metallic, but after metallic processing they just look tanned, which is a positive development, as people in the first Century presumably spent more time in the sun than we do, and survived in spite of vitamin D not being available at their pharmacies.

Anyways, this is a hack, as I said;  it's main purpose is to prove to artists that there is value in getting colors and materials right by physics and optics principles;  that everything is not a matter of taste when it comes to depicting things realistically and convincingly.  Metals and non-metals are worlds apart in how they behave optically, and you need to know what you are doing to make things look right, not just follow gut feelings.  What coding and testing this hack has revealed to me is that people have been producing specular textures left and right without an iota of understanding of material specularity.  Like making white things specular as well as white, or like making the most matte things like carpets and chickens have non-zero specularity, or like expressing dielectric specularities in a metallic way, via the specular texture.

I'm including all three shaders, as they need to be tested together, though only model_common.fs has changed since my last shaders upload.

 

metal4.jpg

metal5.jpg

metal6.jpg

model_common.fs model_common.vs terrain_common.fs

metal7.jpg

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

I'm working on a new algorithm;  a much more "benevolent hack" than this one.  However, I was just playing a game in this marvelous new map, oceanside I think it's called, and upon attacking a cc I noticed how good the metal detection looks for Persians.  So I took a screenshot, and here it is.  I mean the big bronze plant pots, or whatever they are;  and the copperish bull horns.  I don't know if they were intended to look like metal, but it looks ridiculously cool to my eyes.

The new shader algorithm work I will put it under its own thread.  It will take weeks to develop, as I want to do a comprehensive coverage of all real materials.  By "benevolent hack" I mean that it will not, hopefully, second-guess the artist as much as this shader hack does.  First of all, suppose someone submits a set of textures for a model where all materials are correctly represented.  In such a case, the shader should do nothing.  So I want to write a materials analysis that favors assumptions that result in little or no actions taken.  So, first priority is identify diffuse and specular color combinations that make sense and do nothing about them;  next comes the category of representations that cannot be met given the present texture stack but that were represented as close as possible given the available means, such as materials like paints and plastics that need fresnel specularity.  Any material that has a saturated diffuse and unsaturated specular comes in this category, basically;  and the trick is to guess whether it should be a high gloss paint, a cheap paint, or a crappy plastic, just from the intensity of the specular texture relative to the diffuse.  And finally the third category is color combinations that make little or no sense, such as white diffuse and white specular, and to take a guess that it wanted to be marble, and represent it like marble.

Anyways, I'm writing pseudo-code for now;  I'll post it when it's sort of final.

 

SIEGE.jpg

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

Actually I did make a patch... up to the metal detection shader;  you can apply it, and then copy the more recent shader on top.

It's called "ao_and_terrains.patch", and you have to apply it in the /binaries/data/mods/public/ folder, because that's where I did the svn diff.  Go to the folder and type

patch -p0 -i ao_and_terrains.patch

After that, to get the metal detection/depiction shader, just copy model_common.fs to the folder /binaries/data/mods/public/shaders/glsl/  overwriting the one from the patch.

Both attached.  Enjoy.

 

ao_and_terrains.patch model_common.fs

Edited by DanW58
  • Like 1
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...