From 4ff227315a393350956c3a004dae7ac69cd2d036 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 30 Apr 2016 18:09:25 +0300 Subject: [PATCH] alot of changes; geometry highlighting is broken; but you can control console colors now! ;-) --- data/shaders/srlight_geom.frag | 38 ++++++++++++++------ render.d | 81 ++++++++++++++++++++++++++++-------------- 2 files changed, 81 insertions(+), 38 deletions(-) diff --git a/data/shaders/srlight_geom.frag b/data/shaders/srlight_geom.frag index 52f30f4..90e53e7 100644 --- a/data/shaders/srlight_geom.frag +++ b/data/shaders/srlight_geom.frag @@ -64,25 +64,17 @@ void main (void) { return; } - // check ajacent tiles + // check adjacent tiles bool hit = false; - /* - for (int dy = -1; dy < 2; ++dy) { - for (int dx = -1; dx < 2; ++dx) { - if (dx != 0.0 || dy != 0.0) { - if (hit = lightAtTile(ivec2(ocxy.x+dx*8, ocxy.y+dy*8), dx, dy)) break; - } - } - } - */ { +#if 0 vec2 ltpos = gl_TexCoord[0].xy; // in light texture (texLMap) float pixelStep = 1.0/lightTexSize.y; // in light texture int move = ocxy.x&0x07; ltpos.x -= pixelStep*move; move = int(gl_FragCoord.y)&0x07; ltpos.y -= pixelStep*move; - // check ajacent tiles + // check adjacent tiles ltpos -= pixelStep*8; float savedx = ltpos.x; for (int dy = -1; dy < 2 && !hit; ++dy) { @@ -92,12 +84,36 @@ void main (void) { } ltpos = vec2(savedx, ltpos.y+pixelStep*8); } +#else /* for (int dy = 8; dy > 0; --dy) { if (texture2D(texLMap, ltpos, 0).a > MIN_ALPHA) { hit = true; break; } ltpos.y -= pixelStep; } */ + //gl_FragColor = vec4(gl_TexCoord[0].y, 0, 0, 1); + //return; + /* + ocxy.x = ocxy.x&~7; + ocxy.y = ocxy.y&~7; + */ + float tlsz = textureSize(texLMap, 0).y; + vec2 ltpos = gl_TexCoord[0].xy; // in light texture (texLMap) + float pixelStep = 1.0/tlsz; // in light texture + //ltpos.y += pixelStep; + //hit = (texture2D(texLMap, ltpos/tlsz, 0).a > MIN_ALPHA); + hit = ( + texture2D(texLMap, vec2(ltpos.x-pixelStep, ltpos.y-pixelStep), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x , ltpos.y-pixelStep), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x+pixelStep, ltpos.y-pixelStep), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x-pixelStep, ltpos.y ), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x+pixelStep, ltpos.y ), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x-pixelStep, ltpos.y+pixelStep), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x , ltpos.y+pixelStep), 0).a > MIN_ALPHA || + texture2D(texLMap, vec2(ltpos.x+pixelStep, ltpos.y+pixelStep), 0).a > MIN_ALPHA || + false + ); +#endif } if (hit) { diff --git a/render.d b/render.d index 2776bb9..10f2866 100644 --- a/render.d +++ b/render.d @@ -76,6 +76,10 @@ __gshared bool doLighting = true; __gshared bool gamePaused = false; __gshared bool rConsoleVisible = false; __gshared int rConsoleHeight = 16*3; +__gshared uint rConTextColor = 0x00ff00; // rgb +__gshared uint rConCursorColor = 0xff7f00; // rgb +__gshared uint rConInputColor = 0xffff00; // rgb +__gshared uint rConPromptColor = 0xffffff; // rgb __gshared bool renderVBL = true; __gshared bool oldRenderVBL = false; shared bool editMode = false; @@ -324,6 +328,10 @@ shared static this () { conRegVar!gamePaused("g_pause", "pause game"); conRegVar!rConsoleVisible("r_console", "console visibility"); conRegVar!rConsoleHeight(16*3, vlHeight, "r_conheight"); + conRegVar!rConTextColor("r_contextcolor", "console log text color, 0xrrggbb"); + conRegVar!rConCursorColor("r_concursorcolor", "console cursor color, 0xrrggbb"); + conRegVar!rConInputColor("r_coninputcolor", "console input color, 0xrrggbb"); + conRegVar!rConPromptColor("r_conpromptcolor", "console prompt color, 0xrrggbb"); rConsoleHeight = vlHeight-vlHeight/3; rConsoleHeight = vlHeight/2; conRegVar!frameInterpolation("r_interpolation", "interpolate camera and sprite movement"); @@ -474,6 +482,12 @@ public void initOpenGL () { // ////////////////////////////////////////////////////////////////////////// // __gshared ulong conLastChange = 0; +static void glColorUint (uint c) { + pragma(inline, true); + glColor4f(((c>>16)&0xff)/255.0f, ((c>>8)&0xff)/255.0f, (c&0xff)/255.0f, 1.0f); +} + + void renderConsoleFBO () { enum XOfs = 2; if (conLastChange == cbufLastChange) return; @@ -507,7 +521,7 @@ void renderConsoleFBO () { scope(exit) glPopMatrix(); glTranslatef(XOfs, y, 0); int w = conCharWidth('>'); - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glColorUint(rConPromptColor); conDrawChar('>'); uint spos = conclilen; while (spos > 0) { @@ -516,16 +530,16 @@ void renderConsoleFBO () { w += conCharWidth(ch); --spos; } - glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + glColorUint(rConInputColor); foreach (char ch; concli[spos..conclilen]) conDrawChar(ch); // cursor bindTexture(0); - glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + glColorUint(rConCursorColor); glRectf(0, 0, 12, 16); y -= conCharHeight; } // draw console text - glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + glColorUint(rConTextColor); glPushMatrix(); scope(exit) glPopMatrix(); glTranslatef(XOfs, y, 0); @@ -871,7 +885,7 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa /*version(none)*/ fboLSpotSmall.exec({ glDisable(GL_BLEND); //glClearColor(0.0f, 1.0f, 0.0f, 1.0f); - glClearColor(0.0f, 0.0f, 0.0f, 0.1f); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); //orthoCamera(fboLSpotSmall.width, fboLSpotSmall.height); @@ -917,7 +931,13 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa version(smspot) { //glDisable(GL_BLEND); float occn = 1.0f*lightSize/(MaxLightRadius*2); - float occt = 1.0f-occn; + //float occt = 1.0f-occn; + x0 = ((x0+3)/8)*8; + y1 = ((y1+3)/8)*8; + x1 = ((x1+3)/8)*8; + y0 = ((y0+3)/8)*8; + //x1 = x0+lightSize; + //y0 = y1+lightSize; bindTexture(fboLSpotSmall.tex.tid); glBegin(GL_QUADS); /* @@ -947,32 +967,39 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa // and blend it again, with the shader that will touch only occluders shadLightGeom.exec((Shader shad) { //shad["lightTexSize"] = SVec2F(lightSize, lightSize); - version(smspot) { - shad["lightTexSize"] = SVec2F(lightSize, fboLSpotSmall.height); - } else { - shad["lightTexSize"] = SVec2F(lightSize, fboLSpotBG.tex.height); - } + shad["lightTexSize"] = SVec2F(lightSize, fboLSpotSmall.height); + //shad["lightTexSize"] = SVec2F(lightSize, fboLSpotBG.tex.height); shad["lightColor"] = SVec4F(lcol.x, lcol.y, lcol.z, lcol.w); shad["lightPos"] = SVec2F(lightX, lightY); //shad["lightPos"] = SVec2F(lightX-lightRadius, lightY-lightRadius); - version(smspot) { - bindTexture(fboLSpotSmall.tex.tid); - } else { - bindTexture(fboLSpotBG.tex.tid); - } + bindTexture(fboLSpotSmall.tex.tid); + //bindTexture(fboLSpotBG.tex.tid); float occn = 1.0f*lightSize/(MaxLightRadius*2); + //x0 = ((x0+4)/8)*8; + //y1 = ((y1+4)/8)*8; + //x1 = x0+lightSize; + //y0 = y1+lightSize; + /* + x0 = ((x0+4)/8)*8; + y1 = ((y1+4)/8)*8; + x1 = ((x1+4)/8)*8; + y0 = ((y0+4)/8)*8; + */ + x0 &= ~7; + y1 = ((y1+7)/8)*8; + x1 = ((x1+7)/8)*8; + y0 &= ~7; glBegin(GL_QUADS); - version(smspot) { - glTexCoord2f(0.0f, occn); glVertex2i(x0, y0); // top-left - glTexCoord2f(occn, occn); glVertex2i(x1, y0); // top-right - glTexCoord2f(occn, 0.0f); glVertex2i(x1, y1); // bottom-right - glTexCoord2f(0.0f, 0.0f); glVertex2i(x0, y1); // bottom-left - } else { - glTexCoord2f(0.0f, occs); glVertex2i(x0, y0); // top-left - glTexCoord2f(occe, occs); glVertex2i(x1, y0); // top-right - glTexCoord2f(occe, 1.0f); glVertex2i(x1, y1); // bottom-right - glTexCoord2f(0.0f, 1.0f); glVertex2i(x0, y1); // bottom-left - } + glTexCoord2f(0.0f, occn); glVertex2i(x0, y0); // top-left + glTexCoord2f(occn, occn); glVertex2i(x1, y0); // top-right + glTexCoord2f(occn, 0.0f); glVertex2i(x1, y1); // bottom-right + glTexCoord2f(0.0f, 0.0f); glVertex2i(x0, y1); // bottom-left + /* + glTexCoord2f(0.0f, occs); glVertex2i(x0, y0); // top-left + glTexCoord2f(occe, occs); glVertex2i(x1, y0); // top-right + glTexCoord2f(occe, 1.0f); glVertex2i(x1, y1); // bottom-right + glTexCoord2f(0.0f, 1.0f); glVertex2i(x0, y1); // bottom-left + */ glEnd(); //drawAtXY(fboLSpotBG.tex.tid, lightX-lightRadius, lightY-lightRadius, lightSize, lightSize, mirrorY:true); }); -- 2.11.4.GIT