Jump to content

Deeply understanding surface.txt (Flags + Shaders)


Lindor

Recommended Posts

This topic is intended to help determined individuals to deeply understand the usage and limitation of the possibilities opened up by the different surface.txt effects. Please post every piece of your knowledge here if you're an awesome person and like to share it <3 I intend to read everything and edit it into the leading Post. Also small notes are important, adding small things once or twice in a week will hopefully have a cumulative effect. Let's start!

Flags

Spoiler

SURFACE_FLAG_MASKED = 1;
SURFACE_FLAG_TRANSPARENT = 2;
SURFACE_FLAG_OPAQUE = 4;

Spoiler

Opposite of Transparent

SURFACE_FLAG_SFX = 8;

Spoiler

SFX = sound effects

SURFACE_FLAG_TENERGY = 16;

Spoiler

 

SURFACE_FLAG_PULSATING_GLOW = 32;

Spoiler

Doesn't seem to do anything.

SURFACE_FLAG_CONSTANT_FUR = 64;
SURFACE_FLAG_VARIABLE_FUR = 128;
SURFACE_FLAG_BLACKBACK = 256;
SURFACE_FLAG_DOUBLESIDED = 512;

Spoiler

Normally, Textures are onesided, meaning that they're transparent when seen from behind. This flag changes that, so that e.g. the inquisitor Armageddon Set helmet doesn't look transparent from inside. The problem with this is that it causes buggy behaviour with light and shadow, resulting in some problematic artifacts:

On 2/21/2022 at 1:46 PM, jwiz said:

I just had a quick look at the purist pack and am seeing some ugly textural artefacts on the upper body skins of the dryad and highelf, no matter if I choose default or elite textures.

This had not been the case before.

P.S. happens also on the Seraphim though less noticable due to more diverse body armour

 

dryad_start.thumb.png.0199cb03e7f6cdff87c63c4b6b4a2ab0.pnghighelf_start.thumb.png.309257f0961b693b880c26fdebadf10d.png

 

SURFACE_FLAG_PARTICLEEMITTER = 1024;
SURFACE_FLAG_CLICKTHROUGH = 2048;
SURFACE_FLAG_MINIMESHABLE = 4096;
SURFACE_FLAG_ZMASKED = 16384;
SURFACE_FLAG_SHELLFX = 32768;
SURFACE_FLAG_CLOTHFX = 65536;

 

 

Standard surface.txt Shaders

Spoiler

obj_d_s_b_tf

Spoiler

tf = thin film

obj_d_s_b_mtl

Spoiler

mtl = metal

obj_fx_plasma
obj_hair
obj_trans
obj_velvet
obj_d_s_b

Spoiler

This is the standard go-to shader without any special effects added.

obj_d_s_b_skin
obj_ltx

Spoiler

ltx = latex

obj_d_s_b_wet
obj_fx_twings
obj_cloth
obj_skincloth
obj_fx_ghost
obj_fx_undead
obj_trans_ex
obj_skinltx

Spoiler

ltx = latex

obj_fx_add

Spoiler

// plasma

obj_fx_icepipe
obj_d_s_b_pulse

Spoiler

Originally only mean for environmental objects of the great machine, pipes, consoles etc., this shader is also used by the Elite Mounts Project for the Seraphim's Cyber Tiger's Saddle Pipes.

obj_fx_displays
obj_fx_ghostEx
obj_fx_add_fio

Spoiler

// simple adding with fader

particles_debris
particles_leaves
obj_crystal

Spoiler

Very Cool effect, this is what's happening e.g. in the crystal region. It makes the diffuse map shiny-crystally-reflective, while the glow map is responsible for the effect you can see if the object is moving relative to the camera.

obj_fx_lava

Spoiler

This is what's e.g. used in the nine hells set by the high elf.

For the lava shader you can use any texture you want as the texture3Name.  That's why EE has blight, eldritch, bloodlust, and ghostly in the hq/fx folder (this was Dmitriy's idea).  You could sub in something else entirely.  You might have some luck getting the illusion of movement that way.

The more opaque the alpha channel in the sg map, the more intense the lava effect. This also supersedes/diminishes the emissive glow however.

obj_d_s_b_lava
obj_d_s_b_skinlava
obj_d_s_b_mtllava

Spoiler

mtl = metal

fx2
fx2_skin
fx3
fx3_skin
fx4
fx5
fx6

Spoiler

The Inquisitor's Scourge Armor Set's, e.g. Saraki's Path to the Netherworld's, effect.

texture0Name = Diffuse Map
texture1Name = No idea
texture2Name = Glow Color Map
texture3Name = This is always "maps/heroes/inquisitor/sets/scourge/s_inq_scourge_fx2.tga", I think it controls the wobblyness of the fx

 

Wierdly, this shader lacks a normal map.

fx7

Spoiler

This is the effect of e.g. The Inquisitor's Deylen Set:

DfCjIeL.jpeg

texture0Name = diffuse map
texture1Name = glow map
texture2Name = normal Map

It gives it this cool looking reflective illusion.

It usually only works with color gradients, meaning that neighbouring pixels can only change so much for the effect to be triggered, with the best result on pictures with a uniform color. A trick to trigger the effect on non gradient-like images is to make them Brightness-Gradient images (V in HSV or L in LAP), althought that is not a 100%-reliable method.

tree_Tree
tree_Leaf
tree_Branch
tree_TreeSnow
tree_BranchSnow

 

 

Scripting shaders

Spoiler

Shaders can be scripted and applied in surface.txt. The scripting language is C# with Unity Game Engine's API (which is wierd cause Sacred 2 doesn't use Unity game engine).

What surface.txt calls Shaders are not actually shaders, but a combination of multiple shaders in shader.zip. The "ambDiff = ...," is the most important of the shaders, this is the actual effect. Honestly I'm not even sure whther the diffusePnt shaders actually do anything.

Here are the most important findings/general tips about scripting Shaders in shader.zip:

types

mainVS - vertex shader
mainPS - pixel shader
floatA where A is integer - A-dimensional floating point vector
floatAxB where A,B are integer - AxB floating point matrix
texAD(B, C) - B is AxA matrix (actually a A-dimensional texture), C is color vector. Only works in conjuntion with "uniform samplerAD   B" at the beginning of the shader fragout setup.
s2halfA where A is integer - same as floatA, but less precision
s2halfAxB where A, B is integer - same as floataxb, but less precision


hardcoded objects and names

bgr - blue, green, red
param - different, a grey 3D color vector, dependent on ingame time. grey means all rgb components are the same.
textureA where A is integer - this is what surface.txt textureAName means. The texture linking is either hardcoded into FX, or part of the model or it's an entry in surface.txt tied to the model through itemtype.txt.


functions

dot(a, b) = dot product of two vectors
cross(a, b) = cross product of two vectors
lerp(a, b, x) = x*b+(1-x)*a where a=vector,b=vector,x=scalar (float)
clip(x) = every texel where x is smaller than 0 does not get rendered.
xxx.a = alpha channel of xxx where xxx is tex2D or tex3D
sin = sinus function
pow(a, b) = a^b
 

General tips:

most of the time vectors are in bgra color space. NOT rgba.
Unless you're scripting a shader specifically for surface.txt, you can always decrease the number of textures a shader expects, but never increase it.
clip(x) does not work for verteces, it works for pixels.

 

Edited by Lindor
  • Respect! 1
Link to comment
  • 3 weeks later...

One note about the DOUBLESIDED flag 512.

The only light source that causes the artefacting is the sun. Does not happen at all in caves/dungeons or at night.

EDIT:

Also, it disappears when a storm comes (weather effect that obscures the sun).

Edited by idbeholdME
  • Appreciation 1
Link to comment

I'm trying to decipher how the fx6 shader works. That's the wobbly FX shader for Saraki's Path to the Netherworld. I can't figure out what texture1name does, at first I thought it'd control glow intensity but that's not it (unfortunately). I think glow intensity is controlled by the luminosity of the texture2name and the color of the glow by texture2name's color. texture0name is the diffuse map.

I also have no idea what texture3name does, I think it's the wobblyness but I'm not sure.

Do you have any idea?

Link to comment

I haven't fully understood fx6 yet, but there's something more fun I want to share:

It's possible to script your own shader in surface.txt. The most impactful line is the 'ambDiff       = "..."' line, I believe this is where the special effects come from. I've run an analysis on the file names of shader.zip, not all shaders in surface.txt use a file that contains 'ambDiff' in the file name, but I believe that all files which contain 'ambDiff' in the file name have the potential to be used for scripting additional surface.txt shaders.

ambDiff lines which don't have a ambDiff shader file:

Spoiler

image.png.94300c944dcd912f27fdcf9ef6895512.png

ambDiff lines which have corresponding shader file(s):

Spoiler

image.thumb.png.2de0cad06c4051024cbe75b074b0413e.png

shader files with ambDiff in name without corresponting ambDiff line in surface.txt:

Spoiler

image.png.1b48af469bf123c18d7580d673f59c03.png

shader files with amb in name but not ambDiff:

Spoiler

image.png.7791e566c1a068bab49fbfb6972fae59.png

The third one is the most interesting imho. So I suggest to test:

  •   ambDiff       = "object/fx/ambDiffFx4.shader",
  •   ambDiff       = "Xenon/FlowPartAmbDiff.shader",
  •   ambDiff       = "object/ambDiffGlassNoSpec.shader",
  •   ambDiff       = "object/ambDiffInst.shader",

and see what happens :)

Edited by Lindor
Link to comment

I found out that on using the lava shader, the glow map (texture1Name) has lots of impact on surfaces on the character menu screen, but little to no impact ingame, because it really works like layers. The effect, which comes from a together working of texture1Name and texture3Name, overlays everything. It might be that, depending on the normal map, texture1Name is able to 'stick out', haven't tested that yet.

additional test results:

  • "object/fx/ambDiffFx4.shader", : really cool effect, like a very fast fx6 shader but instead of wobblyness everything flies upwards. The diffuse map has some sort of "melting together" like the fx7 shader does, but only in the horizontal direction. EDIT: This is not true, check the next post.
  • "Xenon/FlowPartAmbDiff.shader", : don't use that, it corrupts the character save file.
  • "object/ambDiffGlassNoSpec.shader", : pretty bright, milky and a little bit glassy but not as much as the name suggests. The glow map's color has no effect, only the alpha channel. It's a little bit as if you're observing the diffuse map through a very milky window.
  • "object/ambDiffInst.shader", : can't spot a difference to obj_d_s_b, the standard goto without any special effect added.

 

Edited by Lindor
Reason: character menu screen, not inventory screen
Link to comment

The merging effect on the "object/fx/ambDiffFx4.shader" does not happen to the diffuse map, it happens to texture3Name. The 3rd texture is not the normal map, it's an additional layer above everything else and unfortunately diffuse+glow map, which is where the effect is happening, just barely shine through. The shader expects 3 textures however, otherwise there are red bug warning signs on the texture appearing, so I recommend to use an image just filled completely with transparency as texture3Name.

Link to comment

VERY IMPORTANT INFORMATION FOR SHADERS:

Shaders get cached, they don't get updated upon loading the game each time. When scripting new shaders, you must first delete the shader cache or else you will feel like the game is trolling you.

Navigate to C:\Users\Username\AppData\Local\Temp\Ascaron Entertainment\Sacred 2 and delete shader.cache. Also recommended when you install a new mod or play around with stuff in surface.txt.

This has taken me now so long to find out, I'm feeling scammed. Here I am sitting near to despair thinking why is nothing I do working? Yeah, nice troll.:3lmao:

It would be nice to be able to make the game update a specific shader I'm working on instead of 1760 kB added to my PC every time I want to test a new shader. @dimitrius154 Is that possible for folks like me?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...
Please Sign In or Sign Up