From 0c367d032679a1f158b3553c1be44da137fa80e0 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 1 Apr 2016 22:35:05 +0300 Subject: [PATCH] lightwork: continues --- data/shaders/srlight_blur.frag | 37 ++++++++++++++++++++---------------- render.d | 43 ++++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/data/shaders/srlight_blur.frag b/data/shaders/srlight_blur.frag index 9937311..547954d 100644 --- a/data/shaders/srlight_blur.frag +++ b/data/shaders/srlight_blur.frag @@ -17,6 +17,9 @@ */ #version 130 +//#define DEBUG_RECT +//#define DEBUG_RECT1 + #define PI 3.1415926 uniform sampler2D texDist; // 1D distance @@ -28,8 +31,6 @@ uniform vec4 lightColor; uniform vec2 lightPos; // lefttop #define SHADOW_DO_BLUR -#define DEBUG_RECT - #define SOFT_SHADOWS (1.0f) @@ -37,22 +38,16 @@ uniform vec2 lightPos; // lefttop #define sample(cc_) step(r, texture2D(texDist, vec2(tc.x+(cc_)*blur, /*tc.y*/0.0)).r) //gl_FragCoord.x: [0..lightTexSize.x) -//gl_FragCoord.y: [0..lightTexSize.x) +//gl_FragCoord.y: somehow it is constant; wtf?! void main (void) { vec2 vTexCoord0 = gl_TexCoord[0].xy; - //vec2 btxy = vec2(lightPos.x-lightTexSize.x/2.0+gl_FragCoord.x, (lightPos.y-1)-gl_FragCoord.y+lightTexSize.x/2.0); - vec2 btxy = vec2(lightPos.x-lightTexSize.x/2.0+gl_FragCoord.x, (lightPos.y-2.0)-gl_FragCoord.y-lightTexSize.x*2.0); + // don't even ask me! + vec2 btxy = vec2(lightPos.x+gl_FragCoord.x, lightPos.y+gl_TexCoord[0].y*lightTexSize.x); btxy.y = mapPixSize.y-btxy.y; - //vec2 btxy = vec2(lightPos.x+gl_FragCoord.x, (mapPixSize.y-lightPos.y)+gl_FragCoord.y+lightTexSize.x); - //btxy.y = mapPixSize.y-btxy.y-1.0; - //vec2 ocxy = vec2(btxy.x, mapPixSize.y-btxy.y)/mapPixSize; vec4 color; - if (false/*texture2D(texOcc, ocxy).a > 0.75*/) { - // occluder hit, this will take care of blended light (due to blur) - color = vec4(0.0, 0.0, 0.0, 0.0); - } else { + { float ltsxi = 1.0/lightTexSize.x; // rectangular to polar @@ -96,13 +91,18 @@ void main (void) { #ifdef DEBUG_RECT color = texture2D(texBg, btxy/mapPixSize); color.b = 1.0; - color.a = 0.2; + color.a = 0.4; #else color = vec4(0.0, 0.0, 0.0, 0.0); #endif } else { // has some light here vec4 bcolor = texture2D(texBg, btxy/mapPixSize); +#ifdef DEBUG_RECT + color = bcolor; + color.b = 1.0; + color.a = 0.4; +#else if (lightColor.r+lightColor.g+lightColor.b == 0.0) { color = bcolor*vec4(vec3(lightColor.a), lit); } else { @@ -110,11 +110,16 @@ void main (void) { color += bcolor*lit; color.a = lit/2.0; } +#endif } } - //color.b = 1.0; - //color.a = min(color.a, 0.3); + /* + //color.r = (1.0/lightTexSize.x)*gl_FragCoord.y; + color.r = gl_TexCoord[0].y; + color.g = 0; + color.b = 0; + color.a = 1; + */ gl_FragColor = color; - //gl_FragColor = vec4(255, 0, 0, 0.2); } diff --git a/render.d b/render.d index 22a73ef..b94db55 100644 --- a/render.d +++ b/render.d @@ -443,7 +443,7 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // build 1d distance map to fboShadowMapId - fboDistMap[lightRadius].exec({ + fboDistMap.ptr[lightRadius].exec({ // no need to clear it, shader will take care of that shadToPolar.exec((Shader shad) { shad["lightTexSize"] = SVec2F(lightSize, lightSize); @@ -458,23 +458,21 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa fboOccluders.exec({ // no need to clear it, shader will take care of that // debug - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClear(GL_COLOR_BUFFER_BIT); + //glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + //glClear(GL_COLOR_BUFFER_BIT); shadBlur.exec((Shader shad) { shad["lightTexSize"] = SVec2F(lightSize, MaxLightRadius*2); // x: size of distmap; y: size of this texture shad["lightColor"] = SVec4F(lcol.x, lcol.y, lcol.z, lcol.w); - shad["lightPos"] = SVec2F(lightX, lightY); - //shad["lightPos"] = SVec2F(lightX-lightRadius, lightY-lightRadius); // lefttop + shad["lightPos"] = SVec2F(lightX-lightRadius, lightY-lightRadius); orthoCamera(fboOccluders.tex.width, fboOccluders.tex.height); - drawAtXY(fboDistMap[lightRadius].tex.tid, 0, 0, lightSize, lightSize); - /* + //drawAtXY(fboDistMap[lightRadius].tex.tid, 0, 0, lightSize, lightSize); + glBindTexture(GL_TEXTURE_2D, fboDistMap.ptr[lightRadius].tex.tid); glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2i(x, y); // top-left - glTexCoord2f(1.0f, 0.0f); glVertex2i(w, y); // top-right - glTexCoord2f(1.0f, 1.0f); glVertex2i(w, h); // bottom-right - glTexCoord2f(0.0f, 1.0f); glVertex2i(x, h); // bottom-left + glTexCoord2f(0.0f, 0.0f); glVertex2i(0, 0); // top-left + glTexCoord2f(1.0f, 0.0f); glVertex2i(lightSize, 0); // top-right + glTexCoord2f(1.0f, 1.0f); glVertex2i(lightSize, lightSize); // bottom-right + glTexCoord2f(0.0f, 1.0f); glVertex2i(0, lightSize); // bottom-left glEnd(); - */ }); }); @@ -484,21 +482,30 @@ void renderLight() (int lightX, int lightY, in auto ref SVec4F lcol, int lightRa //glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE); orthoCamera(fboLevelLight.tex.width, fboLevelLight.tex.height); - //drawAtXY(fboOccluders.tex, 0, 0, mirrorY:true); - drawAtXY(fboOccluders.tex, lightX-lightRadius, lightY-lightRadius, mirrorY:true); - /* - float occe = 1.0f*lightSize/MaxLightRadius; + //drawAtXY(fboOccluders.tex, lightX-lightRadius, lightY-lightRadius, mirrorY:true); + float occs = 1.0f-1.0f*lightSize/(MaxLightRadius*2); + float occe = 1.0f*lightSize/(MaxLightRadius*2); + //occe = 1.0f; int x0 = lightX-lightRadius+0; int y1 = lightY-lightRadius+0; - int x1 = lightX+lightRadius-1; - int y0 = lightY+lightRadius-1; + int x1 = lightX+lightRadius-1+1; + int y0 = lightY+lightRadius-1+1; glBindTexture(GL_TEXTURE_2D, fboOccluders.tex.tid); glBegin(GL_QUADS); + /* glTexCoord2f(0.0f, 0.0f); glVertex2i(x0, y0); // top-left glTexCoord2f(occe, 0.0f); glVertex2i(x1, y0); // top-right glTexCoord2f(occe, occe); glVertex2i(x1, y1); // bottom-right glTexCoord2f(0.0f, occe); 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(); + /* + glBindTexture(GL_TEXTURE_2D, 0); + glRectf(x0, y0, x1, y1); */ // and blend it again, with the shader that will touch only occluders /* -- 2.11.4.GIT