From ebeec417ce9d056cab4b48e572252cbf7d2ec9db Mon Sep 17 00:00:00 2001 From: jgk Date: Sun, 4 Jul 2021 22:51:40 +0200 Subject: [PATCH] Lap warming commit---gpu needs optimisation --- shader/lighting/wall.geom | 51 ++++++++++++--------------------------- shader/wall/texture.geom | 27 ++++++++------------- src/Dodge/Render.hs | 37 ++++++++++++++-------------- src/Render.hs | 1 + 4 files changed, 46 insertions(+), 70 deletions(-) diff --git a/shader/lighting/wall.geom b/shader/lighting/wall.geom index dc745ca37..ff622cd32 100644 --- a/shader/lighting/wall.geom +++ b/shader/lighting/wall.geom @@ -7,45 +7,26 @@ uniform vec2 radLum; out vec3 dField; out float lum; float isLHS (vec2 startV, vec2 testV) -{ - return sign( -startV.x * testV.y + startV.y * testV.x); -} -vec4 shiftCloser (vec4 v) -{ return vec4 (v.xy , v.z , v.w) ; } -//{ return vec4 (v.xy , v.z-0.0001 , v.w) ; } +{ return sign( -startV.x * testV.y + startV.y * testV.x); } void main() { vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) -{ - lum = radLum.y; - float rad = radLum.x; - - vec4 p3 = vec4 (p1.xy,100,1); - vec4 p4 = vec4 (p2.xy,100,1); - - vec2 d1 = p1.xy - lightPos.xy; - vec2 d2 = p2.xy - lightPos.xy; - - vec4 a1 = shiftCloser( theMat * p1 ); - vec4 a2 = shiftCloser( theMat * p2 ); - vec4 a3 = shiftCloser( theMat * p3 ); - vec4 a4 = shiftCloser( theMat * p4 ); - - dField = (p1.xyz - lightPos) / rad; - gl_Position = a1; - EmitVertex(); - dField = (p3.xyz - lightPos) / rad; - gl_Position = a3; - EmitVertex(); - dField = (p2.xyz - lightPos) / rad; - gl_Position = a2; - EmitVertex(); - dField = (p4.xyz - lightPos) / rad; - gl_Position = a4; - EmitVertex(); - - EndPrimitive(); +{ lum = radLum.y; + float rad = radLum.x; + vec4 p3 = vec4 (p1.xy,100,1); + vec4 p4 = vec4 (p2.xy,100,1); + vec2 d1 = p1.xy - lightPos.xy; + vec2 d2 = p2.xy - lightPos.xy; + vec4 a1 = theMat * p1; + vec4 a2 = theMat * p2; + vec4 a3 = theMat * p3; + vec4 a4 = theMat * p4; + dField = (p1.xyz - lightPos) / rad; gl_Position = a1; EmitVertex(); + dField = (p3.xyz - lightPos) / rad; gl_Position = a3; EmitVertex(); + dField = (p2.xyz - lightPos) / rad; gl_Position = a2; EmitVertex(); + dField = (p4.xyz - lightPos) / rad; gl_Position = a4; EmitVertex(); + EndPrimitive(); } else {} } diff --git a/shader/wall/texture.geom b/shader/wall/texture.geom index ef3e54c49..c0adb5991 100644 --- a/shader/wall/texture.geom +++ b/shader/wall/texture.geom @@ -7,24 +7,17 @@ out vec4 gColor; out vec2 tPos; // consider using isLHS to check if the wall is facing the center float isLHS (vec2 startV, vec2 testV) -{ - return sign( -startV.x * testV.y + startV.y * testV.x); -} - +{ return sign( -startV.x * testV.y + startV.y * testV.x); } void main() -{ - gColor = vColor[0]; - -vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); -vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); -vec4 p3 = vec4 (p1.xy,100,1); -vec4 p4 = vec4 (p2.xy,100,1); - -vec4 a1 = theMat * p1; -vec4 a2 = theMat * p2; -vec4 a3 = theMat * p3; -vec4 a4 = theMat * p4; - +{ gColor = vColor[0]; + vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); + vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); + vec4 p3 = vec4 (p1.xy,100,1); + vec4 p4 = vec4 (p2.xy,100,1); + vec4 a1 = theMat * p1; + vec4 a2 = theMat * p2; + vec4 a3 = theMat * p3; + vec4 a4 = theMat * p4; tPos = vec2 ( 1,-1) ; gl_Position = a1; EmitVertex(); tPos = vec2 ( 1, 1) ; gl_Position = a3; EmitVertex(); tPos = vec2 (-1,-1) ; gl_Position = a2; EmitVertex(); diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index ace0b5dba..72939020c 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -49,7 +49,7 @@ doDrawing pdata w = do trans = _cameraCenter w wins = (getWindowX w,getWindowY w) wallPointsCol = wallsPointsAndCols w - --windowPoints = wallsWindows w + windowPoints = wallsWindows w lightPoints = lightsForGloom w --viewFroms@(viewFromx,viewFromy) = _cameraViewFrom w viewFroms = _cameraViewFrom w @@ -77,20 +77,6 @@ doDrawing pdata w = do _ <- renderFoldable pdata $ picToLTree (Just 3) pic _ <- renderFoldable pdata $ picToLTree (Just 4) pic _ <- renderFoldable pdata $ picToLTree (Just 5) pic - --depthFunc $= Just Always - --bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata) - --clear [ColorBuffer] - --bindShaderBuffers [_boxBlurShader pdata] [4] - --textureBinding Texture2D $= Just (snd $ (fst $ _fbos pdata) !! 1) - --textureFilter Texture2D $= ((Linear',Just Linear') , Linear') - --generateMipmap' Texture2D - --drawShader (_boxBlurShader pdata) 4 - --replicateM_ 3 $ pingPongBlur pdata - --bindFramebuffer Framebuffer $= (fst $ (fst $ _fbos pdata) !! 1) - --textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata) - --blendFunc $= (One,Zero) - --drawShader (_boxBlurShader pdata) 4 - --depthFunc $= Just Less depthMask $= Enabled @@ -104,13 +90,18 @@ doDrawing pdata w = do bindShaderBuffers [_fullscreenShader pdata] [4] - bindFramebuffer Framebuffer $= defaultFramebufferObject + --bindFramebuffer Framebuffer $= defaultFramebufferObject blend $= Disabled depthFunc $= Just Always - textureBinding Texture2D $= Just (snd $ head $ fst $ _fbos pdata) - drawShader (_fullscreenShader pdata) 4 + --textureBinding Texture2D $= Just (snd $ head $ fst $ _fbos pdata) + --drawShader (_fullscreenShader pdata) 4 + + bindFramebuffer Framebuffer $= (fst $ head $ fst $ _fbos pdata) + --drawShader (_fullscreenShader pdata) 4 --textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata) textureBinding Texture2D $= Just (snd $ (fst $ _fbos pdata) !! 2) + textureFilter Texture2D $= ((Linear',Just Linear') , Linear') + generateMipmap' Texture2D blend $= Enabled blendFunc $= (Zero, OneMinusSrcAlpha) drawShader (_fullscreenShader pdata) 4 @@ -118,6 +109,16 @@ doDrawing pdata w = do textureBinding Texture2D $= Just (snd $ (fst $ _fbos pdata) !! 1) drawShader (_fullscreenShader pdata) 4 + depthFunc $= Just Less + --_ <- renderFoldable pdata $ picToLTree (Just 2) pic + renderBlankWalls pdata windowPoints + + depthFunc $= Just Always + bindFramebuffer Framebuffer $= defaultFramebufferObject + clear [ColorBuffer] + textureBinding Texture2D $= Just (snd $ head $ fst $ _fbos pdata) + drawShader (_fullscreenShader pdata) 4 + -- draw overlay bufferUBO $ isoMatrix 0 1 (0,0) (2,2) --depthFunc $= Just Always diff --git a/src/Render.hs b/src/Render.hs index efc20ba92..01dde607f 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -67,6 +67,7 @@ createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do let vsize = divideSize resDiv vpsize viewport $= (vppos, vsize) textureBinding Texture2D $= Just (snd $ (fst $ _fbos pdata) !! 2) + -- this is a problem! it should be resized once on screen/parameter resize texImage2D Texture2D NoProxy 0 RGBA8 (sizeToTexSize vsize) 0 (PixelData RGBA UnsignedByte nullPtr) textureFilter Texture2D $= ((Linear',Just Linear') , Linear') generateMipmap' Texture2D