summaryrefslogtreecommitdiff
path: root/src/engine/shader.cpp
diff options
context:
space:
mode:
authorxolatile2025-08-05 01:05:35 +0200
committerxolatile2025-08-05 01:05:35 +0200
commit6762e292d02e37a69a807e01493d4e14319cca33 (patch)
tree6be0e9914ababfe279644172f6eee9c2d0de9ef5 /src/engine/shader.cpp
parentd309df4ce4d8ad0ed995a8e1c4267412a7782021 (diff)
downloadxolatile-badassbug-6762e292d02e37a69a807e01493d4e14319cca33.tar.xz
xolatile-badassbug-6762e292d02e37a69a807e01493d4e14319cca33.tar.zst
Do not compile, deleting stuff...
Diffstat (limited to 'src/engine/shader.cpp')
-rw-r--r--src/engine/shader.cpp275
1 files changed, 2 insertions, 273 deletions
diff --git a/src/engine/shader.cpp b/src/engine/shader.cpp
index f7a740e..6134275 100644
--- a/src/engine/shader.cpp
+++ b/src/engine/shader.cpp
@@ -4,7 +4,7 @@
Shader *Shader::lastshader = NULL;
-Shader *nullshader = NULL, *hudshader = NULL, *hudnotextureshader = NULL, *textureshader = NULL, *notextureshader = NULL, *nocolorshader = NULL, *foggedshader = NULL, *foggednotextureshader = NULL, *stdworldshader = NULL;
+Shader *nullshader = NULL, *hudshader = NULL, *hudnotextureshader = NULL, *textureshader = NULL, *notextureshader = NULL, *nocolorshader = NULL, *stdworldshader = NULL;
static hashnameset<GlobalShaderParamState> globalparams(256);
static hashtable<const char *, int> localparams(256);
@@ -35,8 +35,6 @@ void loadshaders()
textureshader = lookupshaderbyname("texture");
notextureshader = lookupshaderbyname("notexture");
nocolorshader = lookupshaderbyname("nocolor");
- foggedshader = lookupshaderbyname("fogged");
- foggednotextureshader = lookupshaderbyname("foggednotexture");
nullshader->set();
@@ -352,7 +350,6 @@ void Shader::allocparams(Slot *slot)
tmu++;
}
else UNIFORMTEX("lightmap", 1);
- if(type & SHADER_ENVMAP) UNIFORMTEX("envmap", tmu++);
UNIFORMTEX("shadowmap", 7);
int stex = 0;
loopv(slot->sts)
@@ -740,37 +737,6 @@ static void gengenericvariant(Shader &s, const char *sname, const char *vs, cons
newshader(s.type, varname, vschanged ? vsv.getbuf() : reuse, pschanged ? psv.getbuf() : reuse, &s, row);
}
-static bool genwatervariant(Shader &s, const char *sname, const char *vs, const char *ps, int row = 2)
-{
- if(!strstr(vs, "//:water") && !strstr(ps, "//:water")) return false;
-
- vector<char> vsw, psw;
-
- const char *vsmain = findglslmain(vs), *vsend = strrchr(vs, '}');
- if(!vsmain || !vsend) return false;
- vsw.put(vs, vsmain - vs);
- const char *fadeparams = "\nuniform vec4 waterfadeparams;\nvarying float fadedepth;\n";
- vsw.put(fadeparams, strlen(fadeparams));
- vsw.put(vsmain, vsend - vsmain);
- const char *fadedef = "\nfadedepth = vvertex.z*waterfadeparams.x + waterfadeparams.y;\n";
- vsw.put(fadedef, strlen(fadedef));
- vsw.put(vsend, strlen(vsend)+1);
-
- const char *psmain = findglslmain(ps), *psend = strrchr(ps, '}');
- if(!psmain || !psend) return false;
- psw.put(ps, psmain - ps);
- const char *fadeinterp = "\nvarying float fadedepth;\n";
- psw.put(fadeinterp, strlen(fadeinterp));
- psw.put(psmain, psend - psmain);
- const char *fade = "\ngl_FragColor.a = fadedepth;\n";
- psw.put(fade, strlen(fade));
- psw.put(psend, strlen(psend)+1);
-
- defformatstring(name, "<water>%s", sname);
- Shader *variant = newshader(s.type, name, vsw.getbuf(), psw.getbuf(), &s, row);
- return variant!=NULL;
-}
-
bool minimizedynlighttcusage() { return glversion < 300 && maxvaryings < 48; }
static void gendynlightvariant(Shader &s, const char *sname, const char *vs, const char *ps, int row = 0)
@@ -839,7 +805,6 @@ static void gendynlightvariant(Shader &s, const char *sname, const char *vs, con
defformatstring(name, "<dynlight %d>%s", i+1, sname);
Shader *variant = newshader(s.type, name, vsdl.getbuf(), psdl.getbuf(), &s, row);
if(!variant) return;
- if(row < 4) genwatervariant(s, name, vsdl.getbuf(), psdl.getbuf(), row+2);
}
}
@@ -904,59 +869,10 @@ static void genshadowmapvariant(Shader &s, const char *sname, const char *vs, co
defformatstring(name, "<shadowmap>%s", sname);
Shader *variant = newshader(s.type, name, vssm.getbuf(), pssm.getbuf(), &s, row);
if(!variant) return;
- genwatervariant(s, name, vssm.getbuf(), pssm.getbuf(), row+2);
if(strstr(vs, "//:dynlight")) gendynlightvariant(s, name, vssm.getbuf(), pssm.getbuf(), row);
}
-static void genfogshader(vector<char> &vsbuf, vector<char> &psbuf, const char *vs, const char *ps)
-{
- const char *vspragma = strstr(vs, "//:fog"), *pspragma = strstr(ps, "//:fog");
- if(!vspragma && !pspragma) return;
- static const int pragmalen = strlen("//:fog");
- const char *vsmain = findglslmain(vs), *vsend = strrchr(vs, '}');
- if(vsmain && vsend)
- {
- vsbuf.put(vs, vsmain - vs);
- const char *fogparams = "\nuniform vec4 fogplane;\nvarying float fogcoord;\n";
- vsbuf.put(fogparams, strlen(fogparams));
- vsbuf.put(vsmain, vsend - vsmain);
- const char *vsfog = "\nfogcoord = dot(fogplane, gl_Position);\n";
- vsbuf.put(vsfog, strlen(vsfog));
- vsbuf.put(vsend, strlen(vsend)+1);
- }
- const char *psmain = findglslmain(ps), *psend = strrchr(ps, '}');
- if(psmain && psend)
- {
- psbuf.put(ps, psmain - ps);
- const char *fogparams =
- "\nuniform vec3 fogcolor;\n"
- "uniform vec2 fogparams;\n"
- "varying float fogcoord;\n";
- psbuf.put(fogparams, strlen(fogparams));
- psbuf.put(psmain, psend - psmain);
- const char *psdef = "\n#define FOG_COLOR ";
- const char *psfog =
- pspragma && !strncmp(pspragma+pragmalen, "rgba", 4) ?
- "\ngl_FragColor = mix((FOG_COLOR), gl_FragColor, clamp(fogcoord*fogparams.x + fogparams.y, 0.0, 1.0));\n" :
- "\ngl_FragColor.rgb = mix((FOG_COLOR).rgb, gl_FragColor.rgb, clamp(fogcoord*fogparams.x + fogparams.y, 0.0, 1.0));\n";
- int clen = 0;
- if(pspragma)
- {
- pspragma += pragmalen;
- while(iscubealpha(*pspragma)) pspragma++;
- while(*pspragma && !iscubespace(*pspragma)) pspragma++;
- pspragma += strspn(pspragma, " \t\v\f");
- clen = strcspn(pspragma, "\r\n");
- }
- if(clen <= 0) { pspragma = "fogcolor"; clen = strlen(pspragma); }
- psbuf.put(psdef, strlen(psdef));
- psbuf.put(pspragma, clen);
- psbuf.put(psfog, strlen(psfog));
- psbuf.put(psend, strlen(psend)+1);
- }
-}
-
static void genuniformdefs(vector<char> &vsbuf, vector<char> &psbuf, const char *vs, const char *ps, Shader *variant = NULL)
{
if(variant ? variant->defaultparams.empty() : slotparams.empty()) return;
@@ -1087,11 +1003,9 @@ void shader(int *type, char *name, char *vs, char *ps)
if(psbuf.length()) ps = psbuf.getbuf(); \
}
GENSHADER(slotparams.length(), genuniformdefs(vsbuf, psbuf, vs, ps));
- GENSHADER(strstr(vs, "//:fog") || strstr(ps, "//:fog"), genfogshader(vsbuf, psbuf, vs, ps));
Shader *s = newshader(*type, name, vs, ps);
if(s)
{
- if(strstr(vs, "//:water")) genwatervariant(*s, s->name, vs, ps);
if(strstr(vs, "//:shadowmap")) genshadowmapvariant(*s, s->name, vs, ps);
if(strstr(vs, "//:dynlight")) gendynlightvariant(*s, s->name, vs, ps);
}
@@ -1115,7 +1029,6 @@ void variantshader(int *type, char *name, int *row, char *vs, char *ps)
//renderprogress(loadprogress, info);
vector<char> vsbuf, psbuf, vsbak, psbak;
GENSHADER(s->defaultparams.length(), genuniformdefs(vsbuf, psbuf, vs, ps, s));
- GENSHADER(strstr(vs, "//:fog") || strstr(ps, "//:fog"), genfogshader(vsbuf, psbuf, vs, ps));
Shader *v = newshader(*type, varname, vs, ps, s, *row);
if(v)
{
@@ -1256,194 +1169,10 @@ ICOMMAND(setuniformparam, "sffff", (char *name, float *x, float *y, float *z, fl
ICOMMAND(setshaderparam, "sffff", (char *name, float *x, float *y, float *z, float *w), addslotparam(name, *x, *y, *z, *w));
ICOMMAND(defuniformparam, "sffff", (char *name, float *x, float *y, float *z, float *w), addslotparam(name, *x, *y, *z, *w));
-#define NUMPOSTFXBINDS 10
-
-struct postfxtex
-{
- GLuint id;
- int scale, used;
-
- postfxtex() : id(0), scale(0), used(-1) {}
-};
-vector<postfxtex> postfxtexs;
-int postfxbinds[NUMPOSTFXBINDS];
-GLuint postfxfb = 0;
-int postfxw = 0, postfxh = 0;
-
-struct postfxpass
-{
- Shader *shader;
- vec4 params;
- uint inputs, freeinputs;
- int outputbind, outputscale;
-
- postfxpass() : shader(NULL), inputs(1), freeinputs(1), outputbind(0), outputscale(0) {}
-};
-vector<postfxpass> postfxpasses;
-
-static int allocatepostfxtex(int scale)
-{
- loopv(postfxtexs)
- {
- postfxtex &t = postfxtexs[i];
- if(t.scale==scale && t.used < 0) return i;
- }
- postfxtex &t = postfxtexs.add();
- t.scale = scale;
- glGenTextures(1, &t.id);
- createtexture(t.id, max(screenw>>scale, 1), max(screenh>>scale, 1), NULL, 3, 1, GL_RGB);
- return postfxtexs.length()-1;
-}
-
-void cleanuppostfx(bool fullclean)
-{
- if(fullclean && postfxfb)
- {
- glDeleteFramebuffers_(1, &postfxfb);
- postfxfb = 0;
- }
-
- loopv(postfxtexs) glDeleteTextures(1, &postfxtexs[i].id);
- postfxtexs.shrink(0);
-
- postfxw = 0;
- postfxh = 0;
-}
-
-void renderpostfx()
-{
- if(postfxpasses.empty()) return;
-
- if(postfxw != screenw || postfxh != screenh)
- {
- cleanuppostfx(false);
- postfxw = screenw;
- postfxh = screenh;
- }
-
- int binds[NUMPOSTFXBINDS];
- loopi(NUMPOSTFXBINDS) binds[i] = -1;
- loopv(postfxtexs) postfxtexs[i].used = -1;
-
- binds[0] = allocatepostfxtex(0);
- postfxtexs[binds[0]].used = 0;
- glBindTexture(GL_TEXTURE_2D, postfxtexs[binds[0]].id);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenw, screenh);
-
- if(postfxpasses.length() > 1)
- {
- if(!postfxfb) glGenFramebuffers_(1, &postfxfb);
- glBindFramebuffer_(GL_FRAMEBUFFER, postfxfb);
- }
-
- GLOBALPARAMF(millis, lastmillis/1000.0f);
-
- loopv(postfxpasses)
- {
- postfxpass &p = postfxpasses[i];
-
- int tex = -1;
- if(!postfxpasses.inrange(i+1))
- {
- if(postfxpasses.length() > 1) glBindFramebuffer_(GL_FRAMEBUFFER, 0);
- }
- else
- {
- tex = allocatepostfxtex(p.outputscale);
- glFramebufferTexture2D_(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, postfxtexs[tex].id, 0);
- }
-
- int w = tex >= 0 ? max(screenw>>postfxtexs[tex].scale, 1) : screenw,
- h = tex >= 0 ? max(screenh>>postfxtexs[tex].scale, 1) : screenh;
- glViewport(0, 0, w, h);
- p.shader->set();
- LOCALPARAM(params, p.params);
- int tw = w, th = h, tmu = 0;
- loopj(NUMPOSTFXBINDS) if(p.inputs&(1<<j) && binds[j] >= 0)
- {
- if(!tmu)
- {
- tw = max(screenw>>postfxtexs[binds[j]].scale, 1);
- th = max(screenh>>postfxtexs[binds[j]].scale, 1);
- }
- else glActiveTexture_(GL_TEXTURE0 + tmu);
- glBindTexture(GL_TEXTURE_2D, postfxtexs[binds[j]].id);
- ++tmu;
- }
- if(tmu) glActiveTexture_(GL_TEXTURE0);
- LOCALPARAMF(postfxscale, 1.0f/tw, 1.0f/th);
- screenquad(1, 1);
-
- loopj(NUMPOSTFXBINDS) if(p.freeinputs&(1<<j) && binds[j] >= 0)
- {
- postfxtexs[binds[j]].used = -1;
- binds[j] = -1;
- }
- if(tex >= 0)
- {
- if(binds[p.outputbind] >= 0) postfxtexs[binds[p.outputbind]].used = -1;
- binds[p.outputbind] = tex;
- postfxtexs[tex].used = p.outputbind;
- }
- }
-}
-
-static bool addpostfx(const char *name, int outputbind, int outputscale, uint inputs, uint freeinputs, const vec4 &params)
-{
- if(!*name) return false;
- Shader *s = useshaderbyname(name);
- if(!s)
- {
- conoutf(CON_ERROR, "no such postfx shader: %s", name);
- return false;
- }
- postfxpass &p = postfxpasses.add();
- p.shader = s;
- p.outputbind = outputbind;
- p.outputscale = outputscale;
- p.inputs = inputs;
- p.freeinputs = freeinputs;
- p.params = params;
- return true;
-}
-
-void clearpostfx()
-{
- postfxpasses.shrink(0);
- cleanuppostfx(false);
-}
-
-COMMAND(clearpostfx, "");
-
-ICOMMAND(addpostfx, "siisffff", (char *name, int *bind, int *scale, char *inputs, float *x, float *y, float *z, float *w),
-{
- int inputmask = inputs[0] ? 0 : 1;
- int freemask = inputs[0] ? 0 : 1;
- bool freeinputs = true;
- for(; *inputs; inputs++) if(isdigit(*inputs))
- {
- inputmask |= 1<<(*inputs-'0');
- if(freeinputs) freemask |= 1<<(*inputs-'0');
- }
- else if(*inputs=='+') freeinputs = false;
- else if(*inputs=='-') freeinputs = true;
- inputmask &= (1<<NUMPOSTFXBINDS)-1;
- freemask &= (1<<NUMPOSTFXBINDS)-1;
- addpostfx(name, clamp(*bind, 0, NUMPOSTFXBINDS-1), max(*scale, 0), inputmask, freemask, vec4(*x, *y, *z, *w));
-});
-
-ICOMMAND(setpostfx, "sffff", (char *name, float *x, float *y, float *z, float *w),
-{
- clearpostfx();
- if(name[0]) addpostfx(name, 0, 0, 1, 1, vec4(*x, *y, *z, *w));
-});
-
void cleanupshaders()
{
- cleanuppostfx(true);
-
loadedshaders = false;
- nullshader = hudshader = hudnotextureshader = textureshader = notextureshader = nocolorshader = foggedshader = foggednotextureshader = stdworldshader = NULL;
+ nullshader = hudshader = hudnotextureshader = textureshader = notextureshader = nocolorshader = stdworldshader = NULL;
enumerate(shaders, Shader, s, s.cleanup());
Shader::lastshader = NULL;
glUseProgram_(0);