Add hard edge to non-visible areas

This commit is contained in:
2021-06-30 13:52:14 +02:00
parent 1cfd1663d1
commit 532f491327
10 changed files with 68 additions and 56 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ import Dodge.WorldEvent.Sound
import Dodge.Creature.Update hiding (CRUpdate)
import Picture
import qualified IntMapHelp as IM
import Geometry
--import Geometry
import Geometry.Vector3D
import Polyhedra
+9 -1
View File
@@ -11,7 +11,7 @@ import Dodge.Base
--import Dodge.Render.MenuScreen
import Dodge.Render.Picture
--import Dodge.Render.PerspectiveMatrix
import Geometry
--import Geometry
import Geometry.Data
--import Picture
import Render
@@ -67,6 +67,14 @@ doDrawing pdata w = do
createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms
(foregroundPics w) scPol
clear [DepthBuffer]
nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 viewFromx viewFromy
drawShader (_lightingOccludeShader pdata) nWalls
depthFunc $= Just Less
-- set blending to depend upon the alpha level already present
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
+1 -4
View File
@@ -51,10 +51,7 @@ diagonalLinesRect pa pb w d ang = zip lhsPoints $ map findDiPoint lhsPoints
highPipe :: Float -> Point2 -> Point2 -> [Polyhedra]
highPipe h x@(xx,xy) y =
[ Polyhedron . map (map ( (,orange) . (+.+.+ (xx,xy,h))))
$ boxABC (a,b,0) (a',b',0) (0,0,10)
-- ,verticalPipe 5 orange x 0 100
-- ,verticalPipe 5 orange y 0 100
-- ,verticalPipe 5 orange (0.5 *.* (x +.+ y)) 50 100
$ boxABC (a,b,0) (a',b',0) (0,0,5)
]
where
(a,b) = y -.- x
+24 -36
View File
@@ -65,54 +65,48 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
-- set the viewport size to that of the render buffer
viewport $= (vppos, divideSize resDiv vpsize)
bindFramebuffer Framebuffer $= _spareFBO pdata
-- store wall and light positions into buffer
nWallLights <- F.foldM (pokeShader $ _lightingWallShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingWallShader pdata] [nWallLights]
nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
-- store foreground silhouette geometry into buffer
nSils <- F.foldM (pokeShader $ _lightingLineShadowShader pdata) (concatMap polyToRender fpics)
bindShaderBuffers [_lightingLineShadowShader pdata] [nSils]
-- store foreground geometry and floor into buffer
let addC (xx,yy) = (xx,yy,0)
nsurfVs <- F.foldM (pokeShader (_lightingSurfaceShader pdata))
$ [Render3 $ polyToTris $ map addC $ scPol ]
++ concatMap polyToGeoRender (fpics)
bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs]
-- clear buffer to full alpha and furthest depth
-- clearColor is specified in preloadRender
clear [ColorBuffer,DepthBuffer]
-- draw walls from your point of view in order to set z buffer
colorMask $= Color4 Disabled Disabled Disabled Disabled
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 viewFromx viewFromy
cullFace $= Just Back
drawShader (_lightingOccludeShader pdata) nWalls
cullFace $= Nothing
-- draw walls from your point of view in order to set z buffer
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
drawShader (_lightingWallShader pdata) nWallLights
--colorMask $= Color4 Disabled Disabled Disabled Disabled
--currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
--uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
-- $= Vector2 viewFromx viewFromy
--drawShader (_lightingOccludeShader pdata) nWalls
---- draw foreground elements to set z buffer
--_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic fpics)
currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata)
drawShader (_lightingSurfaceShader pdata) nsurfVs
-- for each of the lights:
-- stencil out the walls from this light's point of view
-- draw fading lightmap circles on the floor
-- draw fading lightmaps on the walls
--cullFace $= Nothing
depthMask $= Disabled
blendFunc $= (Zero, OneMinusSrcAlpha)
stencilTest $= Enabled
--depthFunc $= Just Less
forM_ lightPoints $ \((x,y,z),r,lum) -> do
-- stencil out walls
depthFunc $= Just Less
-- stencil out shadows
--depthFunc $= Just Less
depthFunc $= Just Lequal
colorMask $= Color4 Disabled Disabled Disabled Disabled
clear [StencilBuffer]
cullFace $= Just Back
@@ -122,7 +116,6 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector3 x y z
drawShader (_lightingOccludeShader pdata) nWalls
--cullFace $= Nothing
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata)
@@ -137,21 +130,20 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
drawShader (_lightingLineShadowShader pdata) nSils
depthFunc $= Just Lequal
-- draw floor light circles
cullFace $= Nothing
-- draw geometry surfaces
cullFace $= Just Back
colorMask $= Color4 Disabled Disabled Disabled Enabled
stencilFunc $= (Equal, 0, 255)
-- draw floor surface
currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata)
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingSurfaceShader pdata) !! 1)
$= Vector2 r lum
drawShader (_lightingSurfaceShader pdata) nsurfVs
-- draw wall light "circles"
-- draw wall light "circles"
--cullFace $= Nothing
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata)
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingWallShader pdata) !! 1)
$= Vector2 r lum
@@ -159,30 +151,26 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
cullFace $= Nothing
stencilTest $= Disabled
blend $= Disabled
-- set the viewport size to that of the window
-- set the viewport size to that of the window
viewport $= (vppos, vpsize)
-- disable depth testing for blurring
-- disable depth testing for blurring
depthFunc $= Just Always
-- draw the lightmap on a full size fbo
-- draw the lightmap on a full size fbo
bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata)
colorMask $= Color4 Disabled Disabled Disabled Enabled
bindShaderBuffers [_boxBlurShader pdata] [4]
textureBinding Texture2D $= Just (_fboTexture pdata)
-- by upscaling the shadowmap texture and using Linear' magnification
-- interpolation, we get a poor mans blur, not sure about performance
-- by upscaling the shadowmap texture and using Linear' magnification
-- interpolation, we get a poor mans blur, not sure about performance
textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
generateMipmap' Texture2D
drawShader (_boxBlurShader pdata) 4
-- ping pong blur between '_fbo2' and '_fbo3' as many times as desired
-- ping pong blur between '_fbo2' and '_fbo3' as many times as desired
replicateM_ 3 $ pingPongBlur pdata
-- reset drawing parameters ready for drawing on top of the light map
-- reset drawing parameters ready for drawing on top of the light map
colorMask $= Color4 Enabled Enabled Enabled Enabled
depthMask $= Enabled
blend $= Enabled
{- |
Blur between two framebuffers.
Assumes no depth testing is done (depthFunc %= Just Always).