From 5ee8b0b05fc4c35c727043c4eb7fccdbd8e010f2 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Fri, 1 Apr 2016 23:54:14 +0300 Subject: [PATCH] shader renamed --- d2dmap.d | 2 +- data/shaders/srlight_ambient.frag | 1 + data/shaders/srlight_blur.frag | 1 + data/shaders/srlight_blur_occ.frag | 1 + .../{srlight_topolar.frag => srlight_trace.frag} | 0 render.d | 25 ++++++++++++++++++---- 6 files changed, 25 insertions(+), 5 deletions(-) rename data/shaders/{srlight_topolar.frag => srlight_trace.frag} (100%) diff --git a/d2dmap.d b/d2dmap.d index e1c66c7..1073f51 100644 --- a/d2dmap.d +++ b/d2dmap.d @@ -290,7 +290,7 @@ public: writePng("zpng%02s.png".format(type), img); }*/ if (texgl[type] is null) { - texgl[type] = new Texture(img, Texture.Option.Nearest, Texture.Option.Clamp); + texgl[type] = new Texture(img, (type == LightMask ? Texture.Option./*Linear*/Nearest : Texture.Option.Nearest), Texture.Option.Clamp); } else { texgl[type].setFromImage(img, 0, 0); } diff --git a/data/shaders/srlight_ambient.frag b/data/shaders/srlight_ambient.frag index 1b31ab0..4b24006 100644 --- a/data/shaders/srlight_ambient.frag +++ b/data/shaders/srlight_ambient.frag @@ -21,6 +21,7 @@ uniform sampler2D texBg; // background uniform sampler2D texOcc; // occluders +uniform sampler2D texOccSmall; // occluders, small map uniform vec2 mapPixSize; uniform vec4 lightColor; //uniform vec2 lightPos; diff --git a/data/shaders/srlight_blur.frag b/data/shaders/srlight_blur.frag index 9dc5643..2296e84 100644 --- a/data/shaders/srlight_blur.frag +++ b/data/shaders/srlight_blur.frag @@ -25,6 +25,7 @@ uniform sampler2D texDist; // 1D distance uniform sampler2D texBg; // background uniform sampler2D texOcc; // occluders +uniform sampler2D texOccSmall; // occluders, small map uniform vec2 lightTexSize; // x: size of distmap; y: size of this texture uniform vec2 mapPixSize; uniform vec4 lightColor; diff --git a/data/shaders/srlight_blur_occ.frag b/data/shaders/srlight_blur_occ.frag index de47a4f..66205be 100644 --- a/data/shaders/srlight_blur_occ.frag +++ b/data/shaders/srlight_blur_occ.frag @@ -27,6 +27,7 @@ uniform sampler2D texLMap; // light texture of lightTexSize uniform sampler2D texBg; // background uniform sampler2D texOcc; // occluders +uniform sampler2D texOccSmall; // occluders, small map uniform vec2 lightTexSize; // x: lightSize; y: size of this texture uniform vec2 mapPixSize; uniform vec4 lightColor; diff --git a/data/shaders/srlight_topolar.frag b/data/shaders/srlight_trace.frag similarity index 100% rename from data/shaders/srlight_topolar.frag rename to data/shaders/srlight_trace.frag diff --git a/render.d b/render.d index 5aeb66d..a1a1606 100644 --- a/render.d +++ b/render.d @@ -117,7 +117,7 @@ __gshared FBO[MaxLightRadius+1] fboDistMap; __gshared FBO fboOccluders; __gshared Shader shadToPolar, shadBlur, shadBlurOcc, shadAmbient; -__gshared FBO fboLevel, fboLevelLight, fboOrigBack; +__gshared FBO fboLevel, fboLevelLight, fboOrigBack, fboLMaskSmall; __gshared Shader shadScanlines; __gshared Shader shadLiquidDistort; @@ -142,7 +142,7 @@ public void initOpenGL () { }); // lights - shadToPolar = new Shader("light_topolar", loadTextFile("shaders/srlight_topolar.frag")); + shadToPolar = new Shader("light_topolar", loadTextFile("shaders/srlight_trace.frag")); shadToPolar.exec((Shader shad) { shad["texOcc"] = 0; shad["texOccFull"] = 2; @@ -153,6 +153,7 @@ public void initOpenGL () { shad["texDist"] = 0; shad["texBg"] = 1; shad["texOcc"] = 2; + shad["texOccSmall"] = 3; }); shadBlurOcc = new Shader("light_blur_occ", loadTextFile("shaders/srlight_blur_occ.frag")); @@ -160,12 +161,14 @@ public void initOpenGL () { shad["texLMap"] = 0; shad["texBg"] = 1; shad["texOcc"] = 2; + shad["texOccSmall"] = 3; }); shadAmbient = new Shader("light_ambient", loadTextFile("shaders/srlight_ambient.frag")); shadAmbient.exec((Shader shad) { shad["texBg"] = 1; shad["texOcc"] = 2; + shad["texOccSmall"] = 3; }); fboOccluders = new FBO(MaxLightRadius*2, MaxLightRadius*2, Texture.Option.Clamp, Texture.Option.Linear); @@ -201,10 +204,12 @@ void loadMap (string mapname) { if (fboLevel !is null) fboLevel.clear(); if (fboLevelLight !is null) fboLevelLight.clear(); if (fboOrigBack !is null) fboOrigBack.clear(); + if (fboLMaskSmall !is null) fboLMaskSmall.clear(); fboLevel = new FBO(map.width*8, map.height*8, Texture.Option.Nearest); // final level render will be here fboLevelLight = new FBO(map.width*8, map.height*8, Texture.Option.Nearest); // level lights will be rendered here - fboOrigBack = new FBO(map.width*8, map.height*8, Texture.Option.Nearest, Texture.Option.Depth); // background+foreground + fboOrigBack = new FBO(map.width*8, map.height*8, Texture.Option.Nearest/*, Texture.Option.Depth*/); // background+foreground + fboLMaskSmall = new FBO(map.width, map.height, Texture.Option.Nearest); // small lightmask shadToPolar.exec((Shader shad) { shad["mapPixSize"] = SVec2F(map.width*8-1, map.height*8-1); }); shadBlur.exec((Shader shad) { shad["mapPixSize"] = SVec2F(map.width*8, map.height*8); }); @@ -732,6 +737,12 @@ void renderScene (MonoTime curtime) { if (doLighting) { + // make smaller occluder texture, so we can trace faster + fboLMaskSmall.exec({ + orthoCamera(map.width, map.height); + drawAtXY(map.texgl.ptr[map.LightMask].tid, 0, 0, map.width, map.height); + }); + // clear light layer fboLevelLight.exec({ glDisable(GL_BLEND); @@ -747,6 +758,9 @@ void renderScene (MonoTime curtime) { // texture 2 is occluders glActiveTexture(GL_TEXTURE0+2); glBindTexture(GL_TEXTURE_2D, map.texgl.ptr[map.LightMask].tid); + // texture 3 is small occluder map + glActiveTexture(GL_TEXTURE0+3); + glBindTexture(GL_TEXTURE_2D, fboLMaskSmall.tex.tid); // done texture assign glActiveTexture(GL_TEXTURE0+0); @@ -854,11 +868,14 @@ void renderScene (MonoTime curtime) { } +/ + orthoCamera(vlWidth, vlHeight); auto tex = (doLighting ? fboLevelLight.tex.tid : fboOrigBack.tex.tid); //mofsx &= ~1; //mofsy &= ~1; - drawAtXY(tex, -mofsx, -mofsy, map.width*8*scale, map.height*8*scale, mirrorY:true); + //drawAtXY(tex, -mofsx, -mofsy, map.width*8*scale, map.height*8*scale, mirrorY:true); + //drawAtXY(map.texgl.ptr[map.LightMask].tid, -mofsx, -mofsy, map.width*8*scale, map.height*8*scale, mirrorY:true); + drawAtXY(fboLMaskSmall.tex.tid, 0, 0, map.width*8, map.height*8, mirrorY:true); doMessages(curtime); } -- 2.11.4.GIT