Upload wall geometry once per frame (can improve for fixed geometry)

This commit is contained in:
2021-07-11 17:32:23 +02:00
parent 37d3e0ce63
commit 26c6c3e426
4 changed files with 77 additions and 57 deletions
+22 -28
View File
@@ -22,26 +22,26 @@ import Data.Tuple.Extra
--import qualified Data.IntMap.Strict as IM
import qualified SDL
setWallDepth
:: RenderData
-> [(Point2,Point2)] -- ^ Wall points
-> (Float,Float) -- ^ View from point
-> IO Word32
setWallDepth pdata wallPoints (viewFromx,viewFromy) = do
startTicks <- SDL.ticks
colorMask $= Color4 Disabled Disabled Disabled Disabled
nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
-- reseting this uniform appears to be necessary
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 viewFromx viewFromy
-- cullFace $= Just Front
drawShader (_lightingOccludeShader pdata) nWalls
colorMask $= Color4 Enabled Enabled Enabled Enabled
endTicks <- SDL.ticks
return $ endTicks - startTicks
--setWallDepth
-- :: RenderData
-- -> [(Point2,Point2)] -- ^ Wall points
-- -> (Float,Float) -- ^ View from point
-- -> IO Word32
--setWallDepth pdata wallPoints (viewFromx,viewFromy) = do
-- startTicks <- SDL.ticks
-- colorMask $= Color4 Disabled Disabled Disabled Disabled
-- nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
-- bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
--
-- currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
-- -- reseting this uniform appears to be necessary
-- uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
-- $= Vector2 viewFromx viewFromy
---- cullFace $= Just Front
-- drawShader (_lightingOccludeShader pdata) nWalls
-- colorMask $= Color4 Enabled Enabled Enabled Enabled
-- endTicks <- SDL.ticks
-- return $ endTicks - startTicks
divideSize :: Int -> Size -> Size
divideSize i (Size x y) = Size (div x $ fromIntegral i) (div y $ fromIntegral i)
@@ -55,12 +55,12 @@ Determine where light is shining in the world.
createLightMap
:: RenderData
-> Int -- Resolution division
-> [(Point2,Point2)] -- Wall pairs
-> [(Point3,Float,Float)] -- Lights
-> [Polyhedra] -- foreground geometry
-> [Point2]
-> Int -- ^ number of walls
-> IO ()
createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
createLightMap pdata resDiv lightPoints fpics scPol nWalls = do
depthFunc $= Just Less
-- get viewport size so we can reset it later
(vppos,vpsize) <- get viewport
@@ -68,11 +68,6 @@ createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
let vsize = divideSize resDiv vpsize
viewport $= (vppos, vsize)
textureBinding Texture2D $= Just (snd $ _fboLighting 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]
@@ -152,7 +147,6 @@ createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
$= Vector3 x y z
uniform (_shaderCustomUnis (_lightingWallShader pdata) !! 1)
$= Vector2 r lum
--drawShader (_lightingWallShader pdata) nWallLights
drawShader (_lightingWallShader pdata) nWalls
cullFace $= Nothing
stencilTest $= Disabled