Try to improve instancing shadows
This commit is contained in:
@@ -89,6 +89,8 @@ data ObjectShadows = GeoObjShads
|
||||
| InstancingShads
|
||||
| CPUObjShads
|
||||
| NoObjShads
|
||||
| NoShadows
|
||||
| NoLighting
|
||||
deriving (Show, Eq, Ord, Enum, Bounded)
|
||||
|
||||
data RoomClipping = NoRoomClipBoundaries | AllRoomClipBoundaries | IntersectingRoomClipBoundaries
|
||||
|
||||
+28
-39
@@ -3,26 +3,27 @@ module Dodge.Render (
|
||||
doDrawing,
|
||||
) where
|
||||
|
||||
import qualified Data.Map.Strict as M
|
||||
import Picture.Base
|
||||
import qualified SDL
|
||||
import qualified Data.Vector as V
|
||||
import Dodge.Render.Shadow
|
||||
--import qualified Data.Vector as V
|
||||
|
||||
import Control.Lens
|
||||
import Control.Monad
|
||||
import qualified Control.Monad.Parallel as MP
|
||||
import qualified Data.Map.Strict as M
|
||||
import Data.Preload.Render
|
||||
import qualified Data.Vector.Unboxed.Mutable as UMV
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.Render.Lights
|
||||
import Dodge.Render.Picture
|
||||
import Dodge.Render.Shadow
|
||||
import Dodge.Render.ShapePicture
|
||||
import Dodge.Render.Walls
|
||||
import Foreign
|
||||
import Geometry
|
||||
import Graphics.GL.Core45
|
||||
import MatrixHelper
|
||||
import Picture.Base
|
||||
import Render
|
||||
import qualified SDL
|
||||
--import qualified SDL
|
||||
import Shader
|
||||
import Shader.Bind
|
||||
@@ -55,13 +56,11 @@ doDrawing' win pdata u = do
|
||||
lightPoints = lightsToRender cfig (w ^. cWorld . camPos) (w ^. cWorld . lWorld)
|
||||
viewFroms@(V2 vfx vfy) = w ^. cWorld . camPos . camViewFrom
|
||||
shadV = _pictureShaders pdata
|
||||
lwShad = _lightingWallShadShader pdata
|
||||
-- bind as much data into vbos as feasible at this point
|
||||
-- count mutable vectors setup
|
||||
layerCounts <- UMV.replicate (numLayers * 6) 0
|
||||
-- attempt to poke in parallel
|
||||
let (ws, wp) = wallSPics <> worldSPic cfig w
|
||||
--( (nWalls, nWins , nFls),(nShapeVs, nIndices, nSilIndices) )
|
||||
((nWalls, nWins, nFls), (nShapeVs, nIndices, nSilIndices)) <-
|
||||
MP.bindM3
|
||||
(\_ a b -> return (a, b))
|
||||
@@ -109,21 +108,18 @@ doDrawing' win pdata u = do
|
||||
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr ->
|
||||
glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
|
||||
setViewportSize (round winx `div` resFact) (round winy `div` resFact)
|
||||
--bindFramebuffer Framebuffer $= fst (_fboBase pdata)
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboBase pdata)))
|
||||
glDepthMask GL_TRUE
|
||||
glClearColor 0 0 0 1
|
||||
glClear $ sum [GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT]
|
||||
glDepthFunc GL_LESS
|
||||
-- draw wall occlusions from the camera's point of view
|
||||
-- currentProgram $= lwShad ^? shadProg -- Just (_shadProg lwShad)
|
||||
-- uniform (_shadUnis lwShad V.! 0) $= viewFrom3d
|
||||
glUseProgram (lwShad ^. shadProg')
|
||||
glUniform3f (_shadUnis' lwShad V.! 0) vfx vfy 20
|
||||
--bindVertexArrayObject $= lwShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwShad)
|
||||
glBindVertexArray $ lwShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwShad)
|
||||
glUseProgram (pdata ^. lightingWallShadShader . shadProg')
|
||||
glUniform3f (pdata ^?! lightingWallShadShader . shadUnis' . ix 0) vfx vfy 20
|
||||
glBindVertexArray $ pdata ^. lightingWallShadShader . shadVAO' . vaoName
|
||||
unless (debugOn Remove_LOS cfig) $
|
||||
glDrawArrays
|
||||
(marshalEPrimitiveMode $ _shadPrim' lwShad)
|
||||
(marshalEPrimitiveMode $ pdata ^. lightingWallShadShader . shadPrim')
|
||||
0
|
||||
(fromIntegral nWalls)
|
||||
--draw walls onto base buffer
|
||||
@@ -134,20 +130,16 @@ doDrawing' win pdata u = do
|
||||
renderLayer BottomLayer shadV layerCounts
|
||||
--draw object shapes onto base buffer
|
||||
let fs = _shapeShader pdata
|
||||
--currentProgram $= Just (_shadProg fs)
|
||||
glUseProgram (_shadProg' fs)
|
||||
--bindVertexArrayObject $= fs ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO fs)
|
||||
glBindVertexArray $ fs ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO fs)
|
||||
glBindVertexArray $ fs ^. shadVAO' . vaoName
|
||||
glDrawElements
|
||||
(marshalEPrimitiveMode $ _shadPrim' fs)
|
||||
(fromIntegral nIndices)
|
||||
GL_UNSIGNED_SHORT
|
||||
nullPtr
|
||||
--draw floor onto base buffer
|
||||
-- nTextArrayVs <- pokePoint33s (shadVBOptr $ _textureArrayShader pdata) (_floorTiles w)
|
||||
drawShader (_textureArrayShader pdata) nFls
|
||||
--draw lightmap into its own buffer
|
||||
--bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
|
||||
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
|
||||
createLightMap
|
||||
cfig
|
||||
@@ -156,23 +148,18 @@ doDrawing' win pdata u = do
|
||||
nWalls
|
||||
nSilIndices
|
||||
nIndices
|
||||
--(_graphics_object_shadows $ _uvConfig u)
|
||||
(u ^. uvConfig . graphics_object_shadows)
|
||||
(snd $ snd $ pdata ^. fboBase)
|
||||
(drawCPUShadows pdata ws)
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glClearColor 0 0 0 0
|
||||
--apply lightmap to base buffer
|
||||
--bindFramebuffer Framebuffer $= pdata ^. fboBase . _1 --fst (_fboBase pdata)
|
||||
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
|
||||
--textureBinding Texture2D $= Just (snd $ _fboLighting pdata)
|
||||
--textureBinding Texture2D $= pdata ^? fboLighting . _2 -- Just (snd $ _fboLighting pdata)
|
||||
glBindTexture GL_TEXTURE_2D (pdata ^. fboLighting . _2 . unTO) -- Just (snd $ _fboLighting pdata)
|
||||
glBindTexture GL_TEXTURE_2D (pdata ^. fboLighting . _2 . unTO)
|
||||
glEnable GL_BLEND
|
||||
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
|
||||
drawShader (_fullscreenShader pdata) 4
|
||||
--draw bloom onto bloom buffer
|
||||
--bindFramebuffer Framebuffer $= pdata ^. fboBloom . _1 --fst (_fboBloom pdata)
|
||||
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBloom . _1 . unFBO)
|
||||
glClear GL_COLOR_BUFFER_BIT
|
||||
glDepthFunc GL_LESS
|
||||
@@ -233,7 +220,7 @@ doDrawing' win pdata u = do
|
||||
(_graphics_object_shadows $ _uvConfig u)
|
||||
(snd $ snd $ _fboCloud pdata)
|
||||
(drawCPUShadows pdata ws)
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
|
||||
glClearColor 0 0 0 0
|
||||
--apply lightmap to cloud buffer
|
||||
glClearColor 0 0 0 0
|
||||
@@ -307,14 +294,15 @@ doDrawing' win pdata u = do
|
||||
renderFoldable shadV $ fixedCoordPictures u
|
||||
glDepthMask GL_TRUE
|
||||
when (debugOn Show_ms_frame $ _uvConfig u) $
|
||||
renderFoldable
|
||||
(_pictureShaders pdata)
|
||||
( setDepth (-1)
|
||||
. translate (-0.5) (-0.8)
|
||||
. scale 0.0005 0.0005
|
||||
$ fpsText (u ^. uvFrameTicks - u ^. uvLastFrameTicks)
|
||||
)
|
||||
renderFoldable
|
||||
(_pictureShaders pdata)
|
||||
( setDepth (-1)
|
||||
. translate (-0.5) (-0.8)
|
||||
. scale 0.0005 0.0005
|
||||
$ fpsText (u ^. uvFrameTicks - u ^. uvLastFrameTicks)
|
||||
)
|
||||
SDL.glSwapWindow win
|
||||
|
||||
-- eTicks <- SDL.ticks
|
||||
-- return (eTicks - sTicks)
|
||||
|
||||
@@ -328,7 +316,6 @@ fpsText x = color col $ text $ "ms/frame " ++ show x
|
||||
| x < 50 = orange
|
||||
| otherwise = red
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- note: currently assume there is only one UBO, we only bind it once at setup
|
||||
--bufferUBO :: GLuint -> [Float] -> IO ()
|
||||
@@ -350,7 +337,8 @@ renderBlankWalls pdata nWalls = do
|
||||
--cullFace $= Just Back
|
||||
drawShader (_wallBlankShader pdata) nWalls
|
||||
glDisable GL_CULL_FACE
|
||||
--cullFace $= Nothing
|
||||
|
||||
--cullFace $= Nothing
|
||||
|
||||
renderTextureWalls ::
|
||||
RenderData ->
|
||||
@@ -363,11 +351,12 @@ renderTextureWalls pdata nWalls = do
|
||||
glCullFace GL_BACK
|
||||
drawShader (_wallTextureShader pdata) nWalls
|
||||
glDisable GL_CULL_FACE
|
||||
--cullFace $= Nothing
|
||||
|
||||
--cullFace $= Nothing
|
||||
|
||||
checkGLError :: IO ()
|
||||
checkGLError = do
|
||||
err <- glGetError
|
||||
err <- glGetError
|
||||
case err of
|
||||
0 -> return ()
|
||||
i -> error $ "OpenGL error: " ++ show i
|
||||
|
||||
Reference in New Issue
Block a user