From 5bdd6469006449dfb1827f4f6ac0139812fb8ae8 Mon Sep 17 00:00:00 2001 From: jgk Date: Tue, 23 Feb 2021 13:14:23 +0100 Subject: [PATCH] Slight improvement to light sources and shadows --- shader/fadeCircle.frag | 2 +- shader/wallShadow.geom | 24 ++++++++++++------------ src/Dodge/LightSources.hs | 4 ++-- src/Dodge/Rooms.hs | 11 ++++++++++- src/Picture/Render.hs | 14 +++++++++----- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/shader/fadeCircle.frag b/shader/fadeCircle.frag index 6e4b77e78..53299d66a 100644 --- a/shader/fadeCircle.frag +++ b/shader/fadeCircle.frag @@ -8,7 +8,7 @@ void main() vec2 pos = gl_FragCoord.xy; float dist = min(1 , 2*distance(pos,cenPosT) / (gParams.x)); //float c = pow(gParams.y*dist,2); - float c = pow(1-dist,2); + float c = gParams.y * pow(1-dist,2); fColor = vec4( c,c,c ,c ); // fColor = vec4( 1,0,0 , 1); // fColor = vec4( 1,0,0 , pow(dist,2) ); diff --git a/shader/wallShadow.geom b/shader/wallShadow.geom index 7432fa7d3..e28c150c3 100644 --- a/shader/wallShadow.geom +++ b/shader/wallShadow.geom @@ -12,18 +12,18 @@ void main() vec2 posc = vBackPoss[0].xy; vec2 posd = vBackPoss[0].zw; - gl_Position = vec4 (posa, 0 , 1); - EmitVertex(); - gl_Position = vec4 (posa + (200 * (posa - lightPos)), 0 , 1); - EmitVertex(); - gl_Position = vec4 (posb, 0 , 1); - EmitVertex(); - gl_Position = vec4 (posb + (200 * (posb - lightPos)), 0 , 1); - EmitVertex(); - gl_Position = vec4 (posb + (200 * (posb - lightPos)), 0 , 1); - EmitVertex(); - gl_Position = vec4 (posd, 0 , 1); - EmitVertex(); +// gl_Position = vec4 (posa, 0 , 1); +// EmitVertex(); +// gl_Position = vec4 (posa + (200 * (posa - lightPos)), 0 , 1); +// EmitVertex(); +// gl_Position = vec4 (posb, 0 , 1); +// EmitVertex(); +// gl_Position = vec4 (posb + (200 * (posb - lightPos)), 0 , 1); +// EmitVertex(); +// gl_Position = vec4 (posb + (200 * (posb - lightPos)), 0 , 1); +// EmitVertex(); +// gl_Position = vec4 (posd, 0 , 1); +// EmitVertex(); gl_Position = vec4 (posd, 0 , 1); EmitVertex(); gl_Position = vec4 (posd + (200 * (posd - lightPos)), 0 , 1); diff --git a/src/Dodge/LightSources.hs b/src/Dodge/LightSources.hs index 92d98db04..d2b236bb1 100644 --- a/src/Dodge/LightSources.hs +++ b/src/Dodge/LightSources.hs @@ -16,8 +16,8 @@ lightAt p i = LS {_lsID = i ,_lsPos = p ,_lsDir = 0 - ,_lsRad = 300 - ,_lsIntensity = 0.5 + ,_lsRad = 600 + ,_lsIntensity = 0.75 } basicLS = PutLS ls dec diff --git a/src/Dodge/Rooms.hs b/src/Dodge/Rooms.hs index 5fd2f8e9b..52de3a4af 100644 --- a/src/Dodge/Rooms.hs +++ b/src/Dodge/Rooms.hs @@ -63,7 +63,7 @@ lev1 = do -- $ roomRect 300 300] ++ [randomiseLinks =<< shooterRoom] ++ (replicate 3 $ randomiseLinks corridor) - ++ [return $ connectRoom corridor] + ++ [return $ connectRoom (set rmPS [PS (20,40) 0 basicLS] corridor)] -- ++ [randomiseLinks =<< longRoom] ++ [return $ connectRoom corridor] ++ firstWeapon @@ -364,6 +364,7 @@ miniRoom1 = do ,PS (0,0) 0 $ PutWindowBlock (wth-wllen,40+4*hf) (60,40+4*hf) ,PS (crx,cry) 0 $ PutCrit miniGunCrit ,PS (wth-20,hgt/2+40) 0 $ randC + ,PS (wth/2,hgt/2) 0 basicLS ] ++ putWallBlocks ( 0, 40+1*hf) (wllen,40+1*hf) ++ putWallBlocks (wth-wllen, 40+2*hf) ( wth,40+2*hf) @@ -412,6 +413,7 @@ miniRoom3 = do ,PS cp (pi/8+5*pi/4) b ,PS cp (pi/8+6*pi/4) b ,PS cp (pi/8+7*pi/4) b + ,PS (w/2,h/2) 0 basicLS ] randomiseLinks $ set rmPS plmnts $ roomRect w h @@ -451,6 +453,9 @@ roomCenterPillar = changeLinkTo ((\p -> dist p (120,0) < 10) . fst) $ set rmPS plmnts $ roomRect' 240 240 2 2 where plmnts = putWallBlocks (110,110) (110,130) ++ putWallBlocks (130,110) (130,130) + ++ [PS (40,120) 0 basicLS + ,PS (200,120) 0 basicLS + ] roomOctogon :: Room roomOctogon = Room @@ -512,6 +517,7 @@ weaponEmptyRoom = do let plmnts = [PS (w/2,h-40) 0 $ RandPS randFirstWeapon ,PS (20,20) (pi/2) $ randC1 ,PS (w-20,20) (pi/2) $ randC1 + ,PS (w/2,h/2) 0 $ basicLS ] randomiseLinks =<< (changeLinkTo ((\p -> dist p (w/2,0) < 10) . fst) $ set rmPS plmnts $ roomRect' w h 2 2) @@ -750,6 +756,7 @@ shooterRoom = do ,PS ( 75,h-60) 0 $ PutCrit explosiveBarrel ,PS ( 85,h-10) 0 $ PutCrit explosiveBarrel ,PS ( 85,h-45) 0 $ PutCrit explosiveBarrel + ,PS ( 75,h-80) 0 basicLS ] ) $ roomRect' 100 h 1 1 @@ -771,6 +778,7 @@ shootersRoom1 = do let blv x y = putBlockV (x+25) (x-25) (y+10) (y) let plmnts = bln x1 y1 ++ bln x2 y2 ++ bln x3 y3 ++ blv x4 y4 ++ [PS p (-pi/2) $ PutCrit autoCrit + ,PS (w/2,200) 0 basicLS ] return $ set rmPS plmnts $ roomRect w 600 @@ -791,6 +799,7 @@ shootersRoom = do ++ [PS (x1,y1-10) (-pi/2) $ PutCrit autoCrit ,PS (x2,y2-10) (-pi/2) $ PutCrit autoCrit ,PS (x3,y3-10) (-pi/2) $ PutCrit autoCrit + ,PS (w/2,200) 0 basicLS ] return $ set rmPS plmnts $ roomRect w 600 diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index abc4340f9..cea443c06 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -315,11 +315,6 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p bindVertexArrayObject $= Just (_vao $ _triVAO pdata) bindArrayBuffers nTriVs $ _vaoBufferTargets $ _triVAO pdata drawArrays Triangles (fromIntegral firstIndex) (fromIntegral $ nTriVs) --- draw lines, don't need to change the program or vaos, just need to bind the --- vbos and draw - bindVertexArrayObject $= Just (_vao $ _lineVAO pdata) - bindArrayBuffers nTriVs $ _vaoBufferTargets $ _lineVAO pdata - drawArrays Lines (fromIntegral firstIndex) (fromIntegral $ nLineVs) -- draw circles currentProgram $= Just (_circShader pdata) uniform (_uniWinSize pdata) $= Vector2 winx winy @@ -334,6 +329,15 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints p bindVertexArrayObject $= Just (_vao $ _arcVAO pdata) bindArrayBuffers nArcVs $ _vaoBufferTargets $ _arcVAO pdata drawArrays Points (fromIntegral firstIndex) (fromIntegral $ nArcVs) + +-- reset blend so that light map doesn't apply + blendFunc $= (SrcAlpha,OneMinusSrcAlpha) + +-- draw lines + currentProgram $= Just (_basicShader pdata) + bindVertexArrayObject $= Just (_vao $ _lineVAO pdata) + bindArrayBuffers nTriVs $ _vaoBufferTargets $ _lineVAO pdata + drawArrays Lines (fromIntegral firstIndex) (fromIntegral $ nLineVs) -- draw text currentProgram $= Just (_textShader pdata) bindVertexArrayObject $= Just (_vao $ _textVAO pdata)