Skip to content

Commit 15d76ce

Browse files
committed
postfx: visorglassfocusedge, draw halos around edges of dark areas
1 parent ed70059 commit 15d76ce

10 files changed

+169
-176
lines changed

config/comp/misc.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ newui "combine" $SURFACE_COMPOSITE [
169169
if $_len [
170170
_factor = (divf 1.0 $_len)
171171

172-
looplistn _tex _idx texs [
172+
looplistn _tex _idx $texs [
173173
uiimage $_tex (at $colours $_idx) 0 1.0 1.0 [ uicolourblend $_factor ]
174174
]
175175
]

config/glsl/hud.cfg

+38-67
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ hudhalo = [
171171
varying vec2 texcoord0;
172172
varying vec4 colorscale;
173173

174-
@(? (>= (strstr $arg1 "ref") 0) [
175-
@(gfetchdefs [refractdepth refractmask])
176-
] [
177-
@(gfetchdefs [refractdepth])
178-
])
174+
@(gfetchdefs [earlydepth])
179175

180176
fragdata(0) vec4 fragcolor;
181177

@@ -212,16 +208,10 @@ hudhalo = [
212208

213209
// extract the depth information from the scene
214210
vec2 duv = gl_FragCoord.xy * halodepth;
215-
float depth = dot(gfetch(refractdepth, duv).rgb, gdepthunpackparams);
211+
float depth = dot(gfetch(earlydepth, duv).rgb, gdepthunpackparams);
216212
vec3 pos = (linearworldmatrix * vec4(depth * gl_FragCoord.xy, depth, 1.0)).xyz;
217213
float maxdist = distance(camera, pos); // linearize and calculate distance
218214

219-
@(? (>= (strstr $arg1 "ref") 0) [
220-
float rdepth = dot(gfetch(refractmask, duv).rgb, gdepthunpackparams);
221-
vec3 rpos = (linearworldmatrix * vec4(rdepth * gl_FragCoord.xy, rdepth, 1.0)).xyz;
222-
maxdist = max(maxdist, distance(camera, rpos));
223-
])
224-
225215
// depth test and discard if it fails
226216
@(if (>= (strstr $arg1 "depth") 0) [result [
227217
if(dist > maxdist) discard;
@@ -278,11 +268,11 @@ hudglass = [
278268

279269
@(? (>= (strstr $arg1 "focus") 0) [
280270
uniform sampler2D tex6;
281-
uniform vec4 glassfocus, glassdepth;
271+
uniform vec4 glassfocus, glassedgeparams, glassedgesize, glassdepth;
282272
uniform vec3 camera;
283273
uniform mat4 linearworldmatrix;
284274

285-
@(gfetchdefs tex7)
275+
@(gfetchdefs [earlydepth])
286276
])
287277

288278
uniform float time;
@@ -324,7 +314,7 @@ hudglass = [
324314

325315
@(if (>= (strstr $arg1 "focus") 0) [result [
326316
float focusdepth = dot(texture2D(tex6, vec2(0.5)).rgb, gdepthunpackparams),
327-
curdepth = dot(gfetch(tex7, texcoord0 * glassdepth.xy).rgb, gdepthunpackparams);
317+
curdepth = dot(gfetch(earlydepth, texcoord0 * glassdepth.xy).rgb, gdepthunpackparams);
328318
vec3 focuspos = (linearworldmatrix * vec4(focusdepth * glasssize.xy * 0.5, focusdepth, 1.0)).xyz,
329319
curpos = (linearworldmatrix * vec4(curdepth * texcoord0, curdepth, 1.0)).xyz;
330320
float curoffset = abs(distance(focuspos, curpos) - glassfocus.z);
@@ -335,6 +325,37 @@ hudglass = [
335325
if(glassamt > 0.0)
336326
outcolor = mix(outcolor, texture2DRect(tex5, texcoord0 * glassscale).rgb, clamp(glassamt, 0.0, 1.0));
337327

328+
@(if (>= (strstr $arg1 "focus") 0) [result [
329+
if(glassedgeparams.x > 0.0)
330+
{
331+
float edgesrc = dot(outcolor, vec3(0.21, 0.72, 0.07));
332+
if(edgesrc <= glassedgeparams.x)
333+
{
334+
float edgedist = distance(camera, curpos);
335+
if(edgedist <= glassedgeparams.z)
336+
{
337+
float edgeskew = clamp(edgedist * glassedgeparams.w, 0.0, 1.0),
338+
edgecheck = glassedgesize.x + glassedgesize.y * edgeskew,
339+
edgemax = 0.0;
340+
341+
@(looplistconcatn _coord _idx ["0.0, 1.0" "0.0, -1.0" "1.0, 0.0" "-1.0, 0.0"] [result [
342+
vec2 edgecoord@[_idx] = texcoord0 + vec2(@[_coord]) * glassedgesize.z;
343+
float edgedepth@[_idx] = dot(gfetch(earlydepth, edgecoord@[_idx] * glassdepth.xy).rgb, gdepthunpackparams);
344+
vec3 edgepos@[_idx] = (linearworldmatrix * vec4(edgedepth@[_idx] * edgecoord@[_idx], edgedepth@[_idx], 1.0)).xyz;
345+
float edgedist@[_idx] = distance(camera, edgepos@[_idx]), edgeoff@[_idx] = abs(edgedist - edgedist@[_idx]);
346+
edgemax = max(edgemax, edgeoff@[_idx]);
347+
]])
348+
349+
if(edgemax >= edgecheck)
350+
{
351+
float edgepc = (1.0 - edgesrc * glassedgeparams.y) * (1.0 - edgeskew);
352+
outcolor = mix(outcolor, vec3(glassedgesize.w), clamp(edgepc, 0.0, 1.0));
353+
}
354+
}
355+
}
356+
}
357+
]])
358+
338359
if(glassfx.x > 0.0) outcolor = mix(outcolor, vec3(dot(outcolor, vec3(0.21, 0.72, 0.07))), clamp(glassfx.x * dist, 0.0, 1.0));
339360
if(glassfx.y > 0.0) outcolor = mix(outcolor, outcolor * 0.25, clamp(glassfx.y * dist, 0.0, 1.0));
340361
if(glassfx.z > 0.0) outcolor = mix(outcolor, outcolor * glassfx.w, clamp(glassfx.z * dist, 0.0, 1.0));
@@ -459,56 +480,6 @@ hudvisor "hudvisorchroma"
459480
hudvisor "hudvisorview"
460481
hudvisor "hudvisorviewchroma"
461482

462-
huddepth = [
463-
shader $SHADER_DEFAULT $arg1 [
464-
attribute vec4 vvertex, vcolor;
465-
attribute vec2 vtexcoord0;
466-
uniform mat4 hudmatrix;
467-
varying vec2 texcoord0;
468-
469-
void main(void)
470-
{
471-
gl_Position = hudmatrix * vvertex;
472-
texcoord0 = vtexcoord0;
473-
}
474-
] [
475-
@(? (>= (strstr $arg1 "ref") 0) [
476-
@(gfetchdefs [refractdepth refractmask])
477-
] [
478-
@(gfetchdefs [refractdepth])
479-
])
480-
uniform vec3 gdepthpackparams;
481-
varying vec2 texcoord0;
482-
483-
fragdata(0) vec4 fragcolor;
484-
485-
void main(void)
486-
{
487-
@(if (= $gdepthformat 1) [result [
488-
vec3 packdepth = gfetch(refractdepth, texcoord0).rgb;
489-
]] [result [
490-
@(gdepthunpack depth [gfetch(refractdepth, texcoord0)])
491-
@(gpackdepth packdepth depth)
492-
]])
493-
494-
@(? (>= (strstr $arg1 "ref") 0) [
495-
@(if (= $gdepthformat 1) [result [
496-
vec3 refdepth = gfetch(refractmask, texcoord0).rgb;
497-
]] [result [
498-
@(gdepthunpack rdepth [gfetch(refractmask, texcoord0)])
499-
@(gpackdepth refdepth rdepth)
500-
]])
501-
502-
if(refdepth != vec3(0.0)) packdepth = refdepth;
503-
])
504-
505-
fragcolor = vec4(packdepth, 0.0);
506-
}
507-
]
508-
]
509-
huddepth "huddepth"
510-
huddepth "huddepthref"
511-
512483
shader $SHADER_DEFAULT "hudfocus" [
513484
attribute vec4 vvertex;
514485
uniform mat4 hudmatrix;
@@ -522,7 +493,7 @@ shader $SHADER_DEFAULT "hudfocus" [
522493
uniform vec2 focussize;
523494
uniform vec3 focusparams;
524495

525-
@(gfetchdefs tex7)
496+
@(gfetchdefs [earlydepth])
526497
@(ginterpdepth)
527498

528499
fragdata(0) vec4 fragcolor;
@@ -531,7 +502,7 @@ shader $SHADER_DEFAULT "hudfocus" [
531502
{
532503
if(focusparams.y > 0.0)
533504
{
534-
@(gdepthunpack curdepth [gfetch(tex7, focussize)])
505+
@(gdepthunpack curdepth [gfetch(earlydepth, focussize)])
535506
@(gdepthunpack prvdepth [texture2D(tex0, vec2(0.5))])
536507

537508
if(curdepth != prvdepth)

config/glsl/material.cfg

+30-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,33 @@
44
//
55
///////////////////////////////////////////////////
66

7+
shader $SHADER_DEFAULT "copydepth" [
8+
attribute vec4 vvertex;
9+
uniform mat4 hudmatrix;
10+
11+
void main(void)
12+
{
13+
gl_Position = hudmatrix * vvertex;
14+
}
15+
] [
16+
@(gfetchdefs [refractdepth])
17+
uniform vec3 gdepthpackparams;
18+
19+
fragdata(0) vec4 fragcolor;
20+
21+
void main(void)
22+
{
23+
@(if (= $gdepthformat 1) [result [
24+
vec3 packdepth = gfetch(refractdepth, gl_FragCoord.xy).rgb;
25+
]] [result [
26+
@(gdepthunpack depth [gfetch(refractdepth, gl_FragCoord.xy)])
27+
@(gpackdepth packdepth depth)
28+
]])
29+
30+
fragcolor = vec4(packdepth, 0.0);
31+
}
32+
]
33+
734
shader $SHADER_DEFAULT "refractmask" [
835
attribute vec4 vvertex;
936
uniform mat4 camprojmatrix;
@@ -689,11 +716,7 @@ hazeshader = [
689716
])
690717
}
691718
] [
692-
@(if (>= (strstr $arg1 "ref") 0) [result [
693-
@(gfetchdefs [refractmask refractdepth])
694-
]] [result [
695-
@(gfetchdefs [refractdepth])
696-
]])
719+
@(gfetchdefs [earlydepth])
697720
uniform vec3 hazerefract;
698721
uniform vec4 hazecolor, hazeparams;
699722
@(? (>= (strstr $arg1 "tex") 0) [
@@ -704,13 +727,8 @@ hazeshader = [
704727
fragdata(0) vec4 fragcolor;
705728
void main(void)
706729
{
707-
@(gdepthunpack depth [gfetch(refractdepth, gl_FragCoord.xy)])
708-
@(? (>= (strstr $arg1 "ref") 0) [
709-
float rdepth = dot(gfetch(refractmask, gl_FragCoord.xy).rgb, gdepthunpackparams);
710-
float dist = max(-depth, -rdepth);
711-
] [
712-
float dist = -depth;
713-
])
730+
@(gdepthunpack depth [gfetch(earlydepth, gl_FragCoord.xy)])
731+
float dist = -depth;
714732
if(dist <= 0) dist = -gdepthunpackparams.x;
715733
if(dist < hazeparams.x) discard;
716734

src/engine/command.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -4409,17 +4409,18 @@ void looplistn(ident *id, ident *id2, const char *list, const uint *body)
44094409
}
44104410
COMMAND(0, looplistn, "rrse");
44114411

4412-
void looplistconc(ident *id, const char *list, const uint *body, bool space)
4412+
void looplistconc(ident *id, ident *id2, const char *list, const uint *body, bool space)
44134413
{
44144414
if(id->type!=ID_ALIAS) return;
4415-
identstack stack;
4415+
identstack stack, stack2;
44164416
vector<char> r;
44174417
int n = 0;
44184418
lockstr locked(list);
44194419
for(const char *s = list, *start, *end, *qstart; parselist(s, start, end, qstart); n++)
44204420
{
44214421
char *val = listelem(start, end, qstart);
44224422
setiter(*id, val, stack);
4423+
if(id2) setiter(*id2, n, stack2);
44234424

44244425
if(n && space) r.add(' ');
44254426

@@ -4430,12 +4431,18 @@ void looplistconc(ident *id, const char *list, const uint *body, bool space)
44304431
r.put(vstr, len);
44314432
freearg(v);
44324433
}
4433-
if(n) poparg(*id);
4434+
if(n)
4435+
{
4436+
poparg(*id);
4437+
if(id2) poparg(*id2);
4438+
}
44344439
r.add('\0');
44354440
commandret->setstr(r.disown());
44364441
}
4437-
ICOMMAND(0, looplistconcat, "rse", (ident *id, char *list, uint *body), looplistconc(id, list, body, true));
4438-
ICOMMAND(0, looplistconcatword, "rse", (ident *id, char *list, uint *body), looplistconc(id, list, body, false));
4442+
ICOMMAND(0, looplistconcat, "rse", (ident *id, char *list, uint *body), looplistconc(id, NULL, list, body, true));
4443+
ICOMMAND(0, looplistconcatword, "rse", (ident *id, char *list, uint *body), looplistconc(id, NULL, list, body, false));
4444+
ICOMMAND(0, looplistconcatn, "rrse", (ident *id, ident *id2, char *list, uint *body), looplistconc(id, id2, list, body, true));
4445+
ICOMMAND(0, looplistconcatwordn, "rrse", (ident *id, ident *id2, char *list, uint *body), looplistconc(id, id2, list, body, false));
44394446

44404447
void listfilter(ident *id, const char *list, const uint *body)
44414448
{

src/engine/engine.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ extern int transparentlayer;
520520

521521
extern GLenum hdrformat, stencilformat;
522522
extern int gw, gh, gdepthformat, ghasstencil;
523-
extern GLuint hdrtex, gdepthtex, gcolortex, gnormaltex, gglowtex, gdepthrb, gstencilrb, refracttex;
523+
extern GLuint hdrtex, gdepthtex, gcolortex, gnormaltex, gglowtex, gdepthrb, gstencilrb, refracttex, earlydepthtex;
524524
extern int msaasamples, msaalight;
525-
extern GLuint mshdrtex, msdepthtex, mscolortex, msnormaltex, msglowtex, msdepthrb, msstencilrb, msrefracttex;
525+
extern GLuint mshdrtex, msdepthtex, mscolortex, msnormaltex, msglowtex, msdepthrb, msstencilrb, msrefracttex, msearlydepthtex;
526526
extern vector<vec2> msaapositions;
527527
extern GLuint hdrfbo, mshdrfbo;
528528
extern bool hasrefractmask;
@@ -1236,7 +1236,7 @@ extern int rendervisor;
12361236
extern int debugvisor;
12371237
struct VisorSurface : RenderSurface
12381238
{
1239-
enum { BACKGROUND = 0, WORLD, VISOR, FOREGROUND, LOOPED, BLIT = LOOPED, BUFFERS, SCALE1 = BUFFERS, GLASS, SCALE2 = GLASS, DEPTH, FOCUS1, FOCUS2, MAX };
1239+
enum { BACKGROUND = 0, WORLD, VISOR, FOREGROUND, LOOPED, BLIT = LOOPED, BUFFERS, SCALE1 = BUFFERS, GLASS, SCALE2 = GLASS, FOCUS1, FOCUS2, MAX };
12401240

12411241
struct Config
12421242
{

0 commit comments

Comments
 (0)