Skip to content

Commit

Permalink
import from tesseract SVN 2019-04-19
Browse files Browse the repository at this point in the history
eihrul (51):
      fix clang warnings
      reset UI world state when building
      always init color in slot view
      findfragdatalocs fix
      remove gamma name hack
      fix hvecs on gcc 7
      non-loc weapon switch sound
      linkedpart cleanups
      fix translation of linked models
      don't remove the current window if we're using it
      disable audio on SDL 2.0.6
      get rid of scale.h
      generateshader fix
      model shader fixes
      force shader fix
      add nospec flag to lights
      flushpart fix
      nospec light shader
      modelloader cleanups
      decal shader fixes
      premultiply decal diffuse textures
      decal shader parallax fix
      decal shader normals fix
      add model flags to force shadows
      add bumpblend shader parameter for decals
      limit progress fps
      MDL_FORCETRANSPARENT option
      better collision with clip surfaces
      remove pointincube
      collision guard space
      classifyface fix
      set null shader on dummy decal
      map name cleanups
      vote fix
      update VC toolchain
      map cfg fix
      fix zipstream seek to end
      limit BIH mesh tris
      fix server gunselect
      addgban fix
      warning fix
      vrotate 6 and 7
      texrotation cleanups
      getpubkey command
      getservauth command
      rndstr command
      rndstr fix
      rndstr cleanup
      processmasterinput fix
      ragdoll commands should check if model is loading
      make maxsoundradius read-only
  • Loading branch information
Hirato committed Apr 20, 2019
1 parent a5b491e commit 6a2513e
Show file tree
Hide file tree
Showing 39 changed files with 628 additions and 552 deletions.
148 changes: 60 additions & 88 deletions config/glsl/decal.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ decalvariantshader = [
if (dtopt "R") [
defuniformparam "envscale" 1 1 1 // reflectivity map multiplier
] [if (dtopt "r") [
defuniformparam "envscale" 0.2 0.2 0.2 // reflectivity
defuniformparam "envscale" 0.2 0.2 0.2 // reflectivity
]]
reuseuniformparam "gloss" 1 // glossiness
if (dtopt "S") [
Expand All @@ -47,6 +47,9 @@ decalvariantshader = [
if (dtopt "p") [
defuniformparam "parallaxscale" 0.06 -0.03 // parallax scaling
]
if (dtopt "n") [
defuniformparam "bumpblend" 1 // alpha-blend strength for normals
]
variantshader $stype $arg1 $srow [
attribute vec4 vvertex;
@(? (dtopt "n") [
Expand Down Expand Up @@ -117,123 +120,92 @@ decalvariantshader = [
void main(void)
{
@(if (dtopt "n") [result [
@(? (|| (dtopt "p") [&& (! (dtopt "1")) (dtopt "r")]) [
vec3 camvecn = normalize(camvec);
])

@(? (dtopt "p") [
float height = texture2D(normalmap, texcoord0.xy).a;
vec2 dtc = texcoord0 + (camvecn * world).xy*(height*parallaxscale.x + parallaxscale.y);
vec3 camvecn = normalize(camvec);
vec2 dtc = texcoord0.xy + (camvecn * world).xy*(height*parallaxscale.x + parallaxscale.y);
] [
#define dtc texcoord0.xy
])

vec4 diffuse = texture2D(diffusemap, dtc);

@(? (|| (! (dtopt "0")) (dtopt "r")) [
vec3 bump = texture2D(normalmap, dtc).rgb*2.0 - 1.0;
vec3 bumpw = world * bump;
#define nvec bumpw
])

@(if (dtopt "1") [
? (dtopt "g") [
vec3 gcolor = diffuse.rgb*colorparams.rgb;
]
] [result [
gcolor.rgb = diffuse.rgb*colorparams.rgb;

@(if (dtopt "r") [result [
float invfresnel = dot(camvecn, bumpw);
vec3 rvec = 2.0*bumpw*invfresnel - camvecn;
vec3 reflect = textureCube(envmap, rvec).rgb;
@(? (dtopt "R") [
vec3 rmod = envscale.xyz*diffuse.a;
] [
#define rmod envscale.xyz
])
gcolor.rgb = mix(gcolor.rgb, reflect, rmod*clamp(1.0 - invfresnel, 0.0, 1.0));
]])
]])

@(if (dtopt "g") [result [
vec4 glowspec = texture2D(glowmap, dtc);
#define glow glowspec.rgb
#define spec glowspec.a
glow *= @(? (dtopt "G") [mix(glowcolor.xyz, pulseglowcolor.xyz, pulse)] [glowcolor.xyz]);
]])

@(if (dtopt "0") [result [
@(if (&& (dtopt "S") [! (dtopt "g")]) [result [
float spec = @(? (dtopt "p") [texture2D(glowmap, dtc).r] [texture2D(normalmap, dtc).a]);
]])
@(gspecpack [gloss.x] (if (dtopt "s") [? (dtopt "S") [spec * specscale.x] [specscale.x]]))
]])

@(if (dtopt "g") [gglowpack glow packnorm])

@(if (! (dtopt "0")) [result [
bumpw = normalize(bumpw);
@(gnormpackdef bumpw packnorm)
]])
]] [result [
#define dtc texcoord0.xy
vec4 diffuse = texture2D(diffusemap, dtc);
]])

@(if (dtopt "1") [
? (dtopt "g") [
vec3 gcolor = diffuse.rgb*colorparams.rgb;
]
] [result [
gcolor.rgb = diffuse.rgb*colorparams.rgb;
vec4 diffuse = texture2D(diffusemap, dtc);

@(if (dtopt "r") [result [
vec3 camvecn = normalize(camvec);
float invfresnel = dot(camvecn, nvec);
vec3 rvec = 2.0*nvec*invfresnel - camvecn;
vec3 reflect = textureCube(envmap, rvec).rgb;
@(? (dtopt "R") [
vec3 rmod = envscale.xyz*diffuse.a;
] [
#define rmod envscale.xyz
])
gcolor.rgb = mix(gcolor.rgb, reflect, rmod*clamp(1.0 - invfresnel, 0.0, 1.0));
]])
]])
@(if (dtopt "g") [result [
vec4 glowspec = texture2D(glowmap, dtc);
#define glow glowspec.rgb
#define spec glowspec.a
glow *= @(? (dtopt "G") [mix(glowcolor.xyz, pulseglowcolor.xyz, pulse)] [glowcolor.xyz]);
glow *= diffuse.a;
]])

@(if (dtopt "g") [result [
vec4 glowspec = texture2D(glowmap, dtc);
#define glow glowspec.rgb
#define spec glowspec.a
glow *= @(? (dtopt "G") [mix(glowcolor.xyz, pulseglowcolor.xyz, pulse)] [glowcolor.xyz]);
@(if (dtopt "0") [result [
@(if (&& (dtopt "S") [! (dtopt "g")]) [result [
float spec = @(? (|| (! (dtopt "n")) (dtopt "p")) [texture2D(glowmap, dtc).r] [texture2D(normalmap, dtc).a]);
]])
@(gspecpack [gloss.x] (if (dtopt "s") [? (dtopt "S") [spec * specscale.x] [specscale.x]]))
]])

@(if (dtopt "1") [
? (dtopt "g") [
vec3 gcolor = diffuse.rgb*colorparams.rgb;
]
] [result [
gcolor.rgb = diffuse.rgb*colorparams.rgb;

@(if (dtopt "0") [result [
@(? (&& (dtopt "S") [! (dtopt "g")]) [
float spec = texture2D(glowmap, dtc).r;
@(if (dtopt "r") [result [
@(? (|| (! (dtopt "n")) (! (dtopt "p"))) [
vec3 camvecn = normalize(camvec);
])
@(gspecpack [gloss.x] (if (dtopt "s") [? (dtopt "S") [spec * specscale.x] [specscale.x]]))
float invfresnel = dot(camvecn, nvec);
vec3 rvec = 2.0*nvec*invfresnel - camvecn;
vec3 reflect = textureCube(envmap, rvec).rgb * diffuse.a;
@(? (dtopt "R") [
vec3 rmod = envscale.xyz*spec;
] [
#define rmod envscale.xyz
])
reflect *= diffuse.a;
gcolor.rgb = mix(gcolor.rgb, reflect, rmod*clamp(1.0 - invfresnel, 0.0, 1.0));
]])
]])

@(if (dtopt "g") [gglowpack glow packnorm])
@(if (dtopt "g") [gglowpack glow packnorm])

@(if (! (dtopt "0")) [result [
vec3 normal = normalize(nvec);
@(gnormpackdef normal packnorm)
]])
@(if (! (dtopt "0")) [result [
vec3 normal = normalize(nvec);
@(gnormpackdef normal packnorm)
]])

float alpha = clamp(texcoord0.z, 0.0, 1.0) * clamp(texcoord0.w, 0.0, 1.0) * diffuse.a;
float inside = clamp(texcoord0.z, 0.0, 1.0) * clamp(texcoord0.w, 0.0, 1.0);
float alpha = inside * diffuse.a;
@(cond [dtopt "0"] [result [
gcolor.rgb *= inside;
gcolor.a *= alpha;
gcolorblend = vec4(alpha);
]] [dtopt "1"] [
? $usepacknorm [
gnormal.a = alpha;
gnormal.a = alpha * bumpblend.x;
] [
gnormalblend = vec4(alpha);
gnormalblend = vec4(alpha * bumpblend.x);
]
] [result [
gcolor.rgb *= inside;
gcolor.a = alpha;
gnormal.a = @(? (dtopt "b") [0.0] [alpha]);
@(? (dtopt "b") [
gnormal = vec4(0.0);
] [
gnormal.rgb *= alpha * bumpblend.x;
gnormal.a = alpha * bumpblend.x;
])
]])
}
]
Expand All @@ -246,7 +218,7 @@ decalshader = [
if $maxdualdrawbufs [
decalvariantshader @@arg1 @@(concatword $arg2 "0")
if @@(! (dtopt "b")) [
decalvariantshader @@arg1 @@(concatword $arg2 "1")
decalvariantshader @@@arg1 @@@(concatword $arg2 "1")
]
] [
decalvariantshader @@arg1 @@arg2
Expand Down
10 changes: 7 additions & 3 deletions config/glsl/deferred.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ lazyshader 0 msaaedgedetect [
// b -> combined base/light variants
// d -> avatar shadow dist bias variants
// D -> disable dist bias
// z -> spec toggle
dlopt = [ >= (strstr $deferredlighttype $arg1) 0 ]

unpacknormbias = 0.005
Expand Down Expand Up @@ -147,7 +148,7 @@ deferredlightvariantshader = [
])
@(if $numlights [result [
uniform vec4 lightpos[@@numlights];
uniform vec3 lightcolor[@@numlights];
uniform vec4 lightcolor[@@numlights];
@(if $spotlight [result [
uniform vec4 spotparams[@@numlights];
]])
Expand Down Expand Up @@ -573,11 +574,14 @@ deferredlightvariantshader = [
]])
light@[j]facing *= light@[j]invdist;
@(if (dlopt "m") [result [
light += diffuse.rgb*light@[j]facing * lightcolor[@@j] * light@[j]atten;
light += diffuse.rgb*light@[j]facing * lightcolor[@@j].rgb * light@[j]atten;
]] [result [
@(if (= (+ $numlights (dlopt "c")) 1) [unpackspec])
float light@[j]spec = pow(clamp(light@[j]facing*facing - light@[j]invdist*dot(camdir, light@[j]dir), 0.0, 1.0), gloss) * specscale;
light += (diffuse.rgb*light@[j]facing + light@[j]spec) * lightcolor[@@j] * light@[j]atten;
@(if (dlopt "z") [result [
light@[j]spec *= lightcolor[@@j].a;
]])
light += (diffuse.rgb*light@[j]facing + light@[j]spec) * lightcolor[@@j].rgb * light@[j]atten;
@(? (= (+ $numlights $baselight) 1) [
float foglerp = clamp(exp2(fogcoord*fogdensity.x)*fogdensity.y, 0.0, 1.0);
light *= foglerp;
Expand Down
70 changes: 61 additions & 9 deletions src/engine/animmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct animmodel : model

void setshaderparams(mesh &m, const animstate *as, bool skinned = true)
{
if(!Shader::lastshader) return;
if(key->checkversion() && Shader::lastshader->owner == key) return;
Shader::lastshader->owner = key;

Expand Down Expand Up @@ -218,7 +219,7 @@ struct animmodel : model

void setshader(mesh &m, const animstate *as)
{
m.setshader(loadshader(), !shadowmapping && colorscale.a < 1 ? 1 : 0);
m.setshader(loadshader(), transparentlayer ? 1 : 0);
}

void bind(mesh &b, const animstate *as)
Expand Down Expand Up @@ -322,6 +323,13 @@ struct animmodel : model
if(noclip) m.flags |= BIH::MESH_NOCLIP;
if(s.cullface > 0) m.flags |= BIH::MESH_CULLFACE;
genBIH(m);
while(bih.last().numtris > BIH::mesh::MAXTRIS)
{
BIH::mesh &overflow = bih.dup();
overflow.tris += BIH::mesh::MAXTRIS;
overflow.numtris -= BIH::mesh::MAXTRIS;
bih[bih.length()-2].numtris = BIH::mesh::MAXTRIS;
}
}

virtual void genshadowmesh(vector<triangle> &tris, const matrix4x3 &m) {}
Expand Down Expand Up @@ -895,7 +903,7 @@ struct animmodel : model
matrixstack[matrixpos] = matrixstack[matrixpos-1];
matrixstack[matrixpos].rotate(pitchamount*RAD, oaxis);
}
if(!index && !model->translate.iszero())
if(this == model->parts[0] && !model->translate.iszero())
{
if(oldpos == matrixpos)
{
Expand All @@ -918,7 +926,7 @@ struct animmodel : model
{
linkedpart &link = links[i];
if(!link.p) continue;
link.matrix.translate(links[i].translate, resize);
link.matrix.translate(link.translate, resize);

matrixpos++;
matrixstack[matrixpos].mul(matrixstack[matrixpos-1], link.matrix);
Expand Down Expand Up @@ -981,7 +989,7 @@ struct animmodel : model
matrixstack[matrixpos] = matrixstack[matrixpos-1];
matrixstack[matrixpos].rotate(pitchamount*RAD, oaxis);
}
if(!index && !model->translate.iszero())
if(this == model->parts[0] && !model->translate.iszero())
{
if(oldpos == matrixpos)
{
Expand Down Expand Up @@ -1017,7 +1025,7 @@ struct animmodel : model
loopv(links)
{
linkedpart &link = links[i];
link.matrix.translate(links[i].translate, resize);
link.matrix.translate(link.translate, resize);

matrixpos++;
matrixstack[matrixpos].mul(matrixstack[matrixpos-1], link.matrix);
Expand Down Expand Up @@ -1362,8 +1370,11 @@ struct animmodel : model
loopv(parts) parts[i]->cleanup();
}

virtual void flushpart() {}

part &addpart()
{
flushpart();
part *p = new part(this, parts.length());
parts.add(p);
return *p;
Expand Down Expand Up @@ -1468,8 +1479,26 @@ struct animmodel : model
return false;
}

virtual bool loaddefaultparts()
virtual bool flipy() const { return false; }
virtual bool loadconfig() { return false; }
virtual bool loaddefaultparts() { return false; }
virtual void startload() {}
virtual void endload() {}

bool load()
{
startload();
bool success = loadconfig() && parts.length(); // configured model, will call the model commands below
if(!success)
success = loaddefaultparts(); // model without configuration, try default tris and skin
flushpart();
endload();
if(flipy()) translate.y = -translate.y;

if(!success) return false;
loopv(parts) if(!parts[i]->meshes) return false;

loaded();
return true;
}

Expand Down Expand Up @@ -1672,18 +1701,41 @@ static inline bool htcmp(const animmodel::shaderparams &x, const animmodel::shad
hashtable<animmodel::shaderparams, animmodel::shaderparamskey> animmodel::shaderparamskey::keys;
int animmodel::shaderparamskey::firstversion = 0, animmodel::shaderparamskey::lastversion = 1;

template<class MDL> struct modelloader
template<class MDL, class BASE> struct modelloader : BASE
{
static MDL *loading;
static string dir;

modelloader(const char *name) : BASE(name) {}

static bool cananimate() { return true; }
static bool multiparted() { return true; }
static bool multimeshed() { return true; }

void startload()
{
loading = (MDL *)this;
}

void endload()
{
loading = NULL;
}

bool loadconfig()
{
formatstring(dir, "media/models/%s", BASE::name);
defformatstring(cfgname, "media/models/%s/%s.cfg", BASE::name, MDL::formatname());

identflags &= ~IDF_PERSIST;
bool success = execfile(cfgname, false);
identflags |= IDF_PERSIST;
return success;
}
};

template<class MDL> MDL *modelloader<MDL>::loading = NULL;
template<class MDL> string modelloader<MDL>::dir = {'\0'}; // crashes clang if "" is used here
template<class MDL, class BASE> MDL *modelloader<MDL, BASE>::loading = NULL;
template<class MDL, class BASE> string modelloader<MDL, BASE>::dir = {'\0'}; // crashes clang if "" is used here

template<class MDL, class MESH> struct modelcommands
{
Expand Down
Loading

0 comments on commit 6a2513e

Please sign in to comment.