diff --git a/shader/floor/arrayPos.frag b/shader/floor/arrayPos.frag index 941c24958..3a698ccd6 100644 --- a/shader/floor/arrayPos.frag +++ b/shader/floor/arrayPos.frag @@ -2,7 +2,7 @@ in vec4 vTexPosRot; in vec2 vPos; layout (location=0) out vec4 fCol; -layout (location=1) out vec4 fPos; +layout (location=1) out vec3 fPos; layout (location=2) out vec4 normal; layout (binding=40) uniform sampler2DArray diffuseSampler; layout (binding=41) uniform sampler2DArray normalSampler; @@ -15,9 +15,9 @@ void main() vec3 vTexPos = vTexPosRot.xyz; float rot = vTexPosRot.w; fCol = vec4(texture(diffuseSampler,vTexPos)); - fPos = vec4(vPos,0,1); + fPos = vec3(vPos,0); vec4 bn = vec4(texture(normalSampler,vTexPos) - 0.5); vec3 nmap1 = vec3(rotateV2(rot,bn.xy), bn.z); - normal = vec4(-nmap1 ,0); + normal = vec4(-nmap1.xyz ,0); //normal = vec4(0,0,-1 ,0); } diff --git a/shader/lighting/texture.frag b/shader/lighting/texture.frag index f901f38ff..387554cc3 100644 --- a/shader/lighting/texture.frag +++ b/shader/lighting/texture.frag @@ -13,13 +13,22 @@ void main() { // if (dist > rad) { // discard; // } + float t = texture(normals, vTexPos).w; vec3 norm = texture(normals, vTexPos).xyz; - float y1 = dot(norm, distVec); + float y1 = dot(normalize(norm), normalize(distVec)); float y2 = float(y1 > 0 ? 1 : 0); - float x = 1 - (pow(dist / rad,4)); + //float y2x = y2; + float y4 = float(y1 > 0 && y1 < 0.5 ? 0.5 : y2); + float y5 = max(0,y1); + //float y4 = smoothstep(-1,1,y1); + //float y4 = 0.25*pow(y1+1,2); + float y3 = float(t > 0 + ? y2 + : (t == 0 ? y4 : y4)); //float x = 1 - (dist / rad); //float x = 1; //float x = (dist > rad ? 0 : 1); - vec3 c = y2* x * lumRad.rgb; + float x = 1 - (pow(dist / rad,4)); + vec3 c = y3* x * lumRad.rgb; fColor = vec4(c, 0); } diff --git a/shader/pull/wall.frag b/shader/pull/wall.frag index 1e0a58d26..167a999f4 100644 --- a/shader/pull/wall.frag +++ b/shader/pull/wall.frag @@ -1,6 +1,6 @@ #version 450 core layout (location=0) out vec4 fCol; -layout (location=1) out vec4 fPos; +layout (location=1) out vec3 fPos; layout (location=2) out vec4 fNorm; in vec3 vTexCoords; in vec4 vPos; @@ -12,7 +12,7 @@ vec2 rotateV2 (float a, vec2 v) void main() { fCol = texture(diffuseSampler,vTexCoords); - fPos = vPos; + fPos = vPos.xyz; vec4 basenorm = texture(normalSampler,vTexCoords) - 0.5; vec2 n1 = rotateV2(vAng,vec2(basenorm.x,basenorm.z)); fNorm = vec4(-vec3(n1,basenorm.y),0); diff --git a/shader/shape/basic.frag b/shader/shape/basic.frag index c672dd6d8..29ea15f0f 100644 --- a/shader/shape/basic.frag +++ b/shader/shape/basic.frag @@ -4,10 +4,11 @@ in vec4 vPos; in vec4 vNorm; layout (location=0) out vec4 fCol; layout (location=1) out vec3 fPos; -layout (location=2) out vec3 fNorm; +layout (location=2) out vec4 fNorm; void main() { fCol = vCol; fPos = vPos.xyz; - fNorm = vNorm.xyz; + //fNorm = vec4(vNorm.xyz,1); + fNorm = vNorm; } diff --git a/shader/texture/antia.frag b/shader/texture/antia.frag new file mode 100644 index 000000000..e477069d9 --- /dev/null +++ b/shader/texture/antia.frag @@ -0,0 +1,21 @@ +#version 450 core +in vec2 vTexPos; +out vec4 fColor; +layout (location = 0) uniform vec2 screensize; +layout(binding = 0) uniform sampler2D screenTexture; +float xoff = 2 / screensize.x; +float yoff = 2 / screensize.y; +vec3 f (float x, float y) +{ return texture(screenTexture, vTexPos + vec2(x*xoff,y*yoff)).xyz; +} +void main() +{ +vec3 tl = f(-1, 1); +vec3 tt = f( 0, 1); +vec3 tr = f( 1, 1); +vec3 mr = f( 1, 0); +vec3 br = f( 1,-1); + if (tl == tt && tt == tr && tr == mr && mr == br) + { fColor = vec4(tl,1);} + else {fColor = texture(screenTexture, vTexPos); } +} diff --git a/shader/texture/antia.vert b/shader/texture/antia.vert new file mode 100644 index 000000000..71b7184d1 --- /dev/null +++ b/shader/texture/antia.vert @@ -0,0 +1,7 @@ +#version 450 core +layout (std140, binding = 2) uniform PosTex { vec4 posTex[3]; }; +out vec2 vTexPos; +void main() { + gl_Position = vec4(posTex[gl_VertexID].xy,0,1); + vTexPos = posTex[gl_VertexID].zw ; +} diff --git a/shader/texture/arrayPos.frag b/shader/texture/arrayPos.frag deleted file mode 100644 index 067651581..000000000 --- a/shader/texture/arrayPos.frag +++ /dev/null @@ -1,16 +0,0 @@ -#version 450 core -in vec3 vTexPos; -in vec3 vPos; -layout (location=0) out vec4 fCol; -layout (location=1) out vec4 fPos; -layout (location=2) out vec4 normal; -//layout (binding=0) uniform sampler2DArray tilesetSampler; -layout (binding=1) uniform sampler2D normalSampler; -void main() -{ - //fCol = texture(tilesetSampler, vec3(0.3,0.1,0) + vTexPos); - fCol = vec4(0.2,0.3,0.6,1); - //fCol = vec4(0.6,0.4,0.3,1); - fPos = vec4(vPos,1); - normal = vec4(vec3(0.5) - texture(normalSampler,2*vTexPos.xy).xyz,0); -} diff --git a/shader/texture/arrayPos.vert b/shader/texture/arrayPos.vert deleted file mode 100644 index 511ce08fa..000000000 --- a/shader/texture/arrayPos.vert +++ /dev/null @@ -1,12 +0,0 @@ -#version 450 core -layout (location = 0) in vec3 pos; -layout (location = 1) in vec3 texPos; -layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -out vec3 vTexPos; -out vec3 vPos; -void main() -{ - gl_Position = theMat * vec4(pos,1.0) ; - vTexPos = texPos; - vPos = pos; -} diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index 48a237302..005a7383e 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -21,6 +21,7 @@ data RenderData = RenderData , _windowPullShader :: GLuint , _pullWallShader :: GLuint , _fullscreenShader :: GLuint + , _textureAntiaShader :: GLuint , _bloomBlurShader :: GLuint , _barrelShader :: (GLuint,VBO) , _shapeShader :: GLuint diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index 2d9725c49..05eb7ef6c 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -367,7 +367,8 @@ doDrawing' win pdata u = do [] -> do glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO glBindFramebuffer GL_FRAMEBUFFER 0 - glUseProgram (pdata ^. fullscreenShader) + glUseProgram (pdata ^. textureAntiaShader) + glUniform2f 0 (windowXFloat cfig) (windowYFloat cfig) --glDrawArrays GL_TRIANGLES 0 6 glDrawArrays GL_TRIANGLES 0 3 rs' -> do diff --git a/src/Framebuffer/Update.hs b/src/Framebuffer/Update.hs index de84fd8b3..c45a120cc 100644 --- a/src/Framebuffer/Update.hs +++ b/src/Framebuffer/Update.hs @@ -21,17 +21,29 @@ import Unsafe.Coerce sizeFBOs :: Config -> RenderData -> IO RenderData sizeFBOs cfig rdata = uncurryV (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _gr_world_res cfig) - >> updateFBOTO3 +-- >> updateFBOTO3 +-- (getWindowSize _gr_world_res cfig) +-- GL_NEAREST +-- GL_NEAREST +-- GL_RGB16F -- RGBAF not sure if the alpha is necessary here +-- GL_RGB16F -- could possibly recover using depth in a clever way +-- -- but probably not, because the projection matrix is +-- -- not always on-center +-- GL_RGBA8_SNORM +-- rdata +-- fboBase + >> fboBase (resizeFBOTO3' (getWindowSize _gr_world_res cfig) GL_NEAREST GL_NEAREST - GL_RGBA16F -- not sure if the alpha is necessary here + GL_NEAREST + GL_NEAREST + GL_RGB16F -- RGBAF not sure if the alpha is necessary here GL_RGB16F -- could possibly recover using depth in a clever way -- but probably not, because the projection matrix is -- not always on-center - GL_RGB8_SNORM + GL_RGBA8_SNORM) rdata - fboBase >>= flip ( updateFBOTO3 @@ -181,8 +193,39 @@ resizeFBOTO3 (fbo, (told1, told2, told3)) xsize ysize minfilt magfilt form1 form to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form1 to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2 to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3 - withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ \ptr -> - glNamedFramebufferDrawBuffers (_unFBO fbo) 3 ptr + withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ + glNamedFramebufferDrawBuffers (_unFBO fbo) 3 + checkFBO fbo + return (fbo, (TO to1, TO to2, TO to3)) + +resizeFBOTO3' :: + V2 Int -> + -- | minification filter + GLenum -> + -- | magnification filter + GLenum -> + -- | minification filter + GLenum -> + -- | magnification filter + GLenum -> + -- | internal color format1 + GLenum -> + -- | internal color format2 + GLenum -> + -- | internal color format3 + GLenum -> + (FBO, (TO, TO, TO)) -> + IO (FBO, (TO, TO, TO)) +resizeFBOTO3' (V2 xsize ysize) min1 mag1 minfilt magfilt form1 form2 form3 (fbo, (told1, told2, told3)) = do + glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) + mglDelete glDeleteTextures $ _unTO told1 + mglDelete glDeleteTextures $ _unTO told2 + mglDelete glDeleteTextures $ _unTO told3 + to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize min1 mag1 form1 + to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2 + to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3 + withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ + glNamedFramebufferDrawBuffers (_unFBO fbo) 3 checkFBO fbo return (fbo, (TO to1, TO to2, TO to3)) diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index fdadcaa92..9ef2f7be9 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -133,6 +133,7 @@ preloadRender = do putStrLn "Setup full screen shaders" alphadivideshader <- makeSourcedShader "texture2D/alphaDivide" [vert, frag] fsShad <- makeSourcedShader "texture/simple" [vert, frag] + textureantiashad <- makeSourcedShader "texture/antia" [vert,frag] bloomBlurShad <- makeSourcedShader "texture/bloomBlur" [vert, frag] lightingTextureShad <- makeSourcedShader "lighting/texture" [vert, frag] lightingCloudShad <- makeSourcedShader "lighting/cloud" [vert, frag] @@ -150,8 +151,9 @@ preloadRender = do flptr <- mallocArray (8 * 65536) let floorvbo = VBO flvbo flptr (8 * floatSize) floorshader <- makeSourcedShader "floor/arrayPos" [vert, frag] - initTexture2DArraySquare 40 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/diffuseArray.png" - initTexture2DArraySquare 41 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png" + initTexture2DArraySquare 40 5 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/diffuseArray.png" + initTexture2DArraySquare 41 5 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png" +-- initTexture2DArraySquare 41 3 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png" putStrLn "Setup chasm VBO, shader" chvbo <- mglCreate glCreateBuffers @@ -196,6 +198,7 @@ preloadRender = do , _ceilingStencilShader = ceilingstencilshader , _windowPullShader = winpull , _pullWallShader = wallpull + , _textureAntiaShader = textureantiashad , _fullscreenShader = fsShad , _alphaDivideShader = alphadivideshader , _lightingTextureShader = lightingTextureShad diff --git a/src/Shader/Poke.hs b/src/Shader/Poke.hs index d8d20ff7c..e4a30303a 100644 --- a/src/Shader/Poke.hs +++ b/src/Shader/Poke.hs @@ -455,7 +455,7 @@ pokeFlatV :: {-# INLINE pokeFlatV #-} pokeFlatV xdata pnorm col ptr nv sh = do pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata) - pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz 1) + pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz (-1)) pokeByteOff ptr (nv *shapeVerxSize + 5 * floatSize) (toColor8 col) return (nv + 1) where @@ -463,7 +463,7 @@ pokeFlatV xdata pnorm col ptr nv sh = do V3 nx ny nz = (sh - pnorm) - V3 x y z normalTo8 :: Point4 -> V4 Int8 -normalTo8 = over each f . normalize +normalTo8 = over each f . over _xyz normalize where f x = floor $ x * 127