Implement low res shadows
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
in vec2 cenPosT;
|
|
||||||
in float lum;
|
in float lum;
|
||||||
|
|
||||||
in vec2 dField;
|
in vec2 dField;
|
||||||
|
|||||||
+12
-11
@@ -1,33 +1,34 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
layout (points) in;
|
layout (points) in;
|
||||||
layout (triangle_strip, max_vertices = 4) out;
|
layout (triangle_strip, max_vertices = 4) out;
|
||||||
in vec2 vParams [];
|
|
||||||
out float lum;
|
out float lum;
|
||||||
out vec2 cenPosT;
|
|
||||||
out vec2 dField;
|
out vec2 dField;
|
||||||
|
|
||||||
uniform vec2 winSize;
|
uniform vec2 winSize;
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
|
uniform mat4 worldMat;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
lum = vParams[0].y;
|
lum = gl_in[0].gl_Position.w;
|
||||||
vec3 cenPos = gl_in[0].gl_Position.xyz;
|
vec2 cenPos = vec2( gl_in[0].gl_Position.x / 2, gl_in[0].gl_Position.y / 2);
|
||||||
float gRad = vParams[0].x * zoom * 2;
|
float gRad = gl_in[0].gl_Position.z * zoom * 2;
|
||||||
|
|
||||||
cenPosT = vec2 ( (cenPos.x + 1) * 0.5 * winSize.x , (cenPos.y + 1) * 0.5 * winSize.y);
|
|
||||||
|
|
||||||
dField = vec2 ( 1, 1);
|
dField = vec2 ( 1, 1);
|
||||||
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
|
gl_Position
|
||||||
|
= vec4 (cenPos.x + gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
dField = vec2 (-1, 1);
|
dField = vec2 (-1, 1);
|
||||||
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
|
gl_Position
|
||||||
|
= vec4 (cenPos.x - gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
dField = vec2 ( 1,-1);
|
dField = vec2 ( 1,-1);
|
||||||
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
|
gl_Position
|
||||||
|
= vec4 (cenPos.x + gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
dField = vec2 (-1,-1);
|
dField = vec2 (-1,-1);
|
||||||
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
|
gl_Position
|
||||||
|
= vec4 (cenPos.x - gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
layout (location = 0) in vec4 position;
|
layout (location = 0) in vec4 position;
|
||||||
out vec2 vParams;
|
//out vec2 vParams;
|
||||||
|
|
||||||
uniform vec2 winSize;
|
uniform vec2 winSize;
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
@@ -10,6 +10,5 @@ uniform mat4 worldMat;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(position.xy,0,1);
|
gl_Position = position;
|
||||||
vParams = position.zw;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ module Dodge.Config.Data (
|
|||||||
, volume_master
|
, volume_master
|
||||||
, volume_sound
|
, volume_sound
|
||||||
, volume_music
|
, volume_music
|
||||||
|
, wall_textured
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Aeson
|
import Data.Aeson
|
||||||
@@ -21,6 +22,7 @@ data Configuration = Configuration
|
|||||||
{ _volume_master :: Float
|
{ _volume_master :: Float
|
||||||
, _volume_sound :: Float
|
, _volume_sound :: Float
|
||||||
, _volume_music :: Float
|
, _volume_music :: Float
|
||||||
|
, _wall_textured :: Bool
|
||||||
}
|
}
|
||||||
deriving (Generic, Show)
|
deriving (Generic, Show)
|
||||||
|
|
||||||
@@ -35,5 +37,6 @@ defaultConfig = Configuration
|
|||||||
{ _volume_master = 1
|
{ _volume_master = 1
|
||||||
, _volume_sound = 1
|
, _volume_sound = 1
|
||||||
, _volume_music = 1
|
, _volume_music = 1
|
||||||
|
, _wall_textured = False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ handlePressedKeyInMenu mState scode w = case mState of
|
|||||||
ScancodeM -> Just $ sw & config . volume_music %~ inc
|
ScancodeM -> Just $ sw & config . volume_music %~ inc
|
||||||
_ -> popMenu $ w & sideEffects %~ (saveConfig (_config w) :)
|
_ -> popMenu $ w & sideEffects %~ (saveConfig (_config w) :)
|
||||||
GraphicsOptionMenu -> case scode of
|
GraphicsOptionMenu -> case scode of
|
||||||
_ -> popMenu w
|
ScancodeW -> Just $ w & config . wall_textured %~ not
|
||||||
|
_ -> popMenu $ w & sideEffects %~ (saveConfig (_config w) :)
|
||||||
ControlList -> Just $ w & menuLayers %~ tail
|
ControlList -> Just $ w & menuLayers %~ tail
|
||||||
_ -> Just w
|
_ -> Just w
|
||||||
where
|
where
|
||||||
@@ -60,8 +61,6 @@ handlePressedKeyInMenu mState scode w = case mState of
|
|||||||
inc x = min 1 (x + 0.1)
|
inc x = min 1 (x + 0.1)
|
||||||
pushMenu ml w = Just $ w & menuLayers %~ (ml :)
|
pushMenu ml w = Just $ w & menuLayers %~ (ml :)
|
||||||
popMenu w = Just $ w & menuLayers %~ tail
|
popMenu w = Just $ w & menuLayers %~ tail
|
||||||
goToOptionMenu w = Just $ w & menuLayers %~ (OptionMenu :)
|
|
||||||
goToControls w = Just $ w & menuLayers %~ (ControlList :)
|
|
||||||
sw = w & sideEffects %~ (setVol (_config w) : )
|
sw = w & sideEffects %~ (setVol (_config w) : )
|
||||||
startNewGame = Just $ generateFromList levx
|
startNewGame = Just $ generateFromList levx
|
||||||
$ initialWorld
|
$ initialWorld
|
||||||
|
|||||||
+49
-12
@@ -4,6 +4,7 @@ module Dodge.Render
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
import Dodge.Data
|
||||||
|
import Dodge.Config.Data
|
||||||
import Dodge.Base
|
import Dodge.Base
|
||||||
import Dodge.Render.HUD
|
import Dodge.Render.HUD
|
||||||
import Dodge.Render.MenuScreen
|
import Dodge.Render.MenuScreen
|
||||||
@@ -15,22 +16,23 @@ import Picture.Render
|
|||||||
import Picture.Preload
|
import Picture.Preload
|
||||||
import Shader
|
import Shader
|
||||||
|
|
||||||
import Data.Graph.Inductive.Query.DFS
|
import Foreign (Word32)
|
||||||
import Data.Graph.Inductive.Graph
|
import Control.Applicative
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
|
import Control.Lens
|
||||||
|
import qualified Control.Foldl as F
|
||||||
|
import Data.Maybe
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.Function
|
import Data.Function
|
||||||
import Foreign (Word32)
|
|
||||||
import Control.Applicative
|
|
||||||
import Control.Lens
|
|
||||||
import Data.Maybe
|
|
||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Graphics.Rendering.OpenGL hiding (color,scale,translate,rotate)
|
import Graphics.Rendering.OpenGL hiding (color,scale,translate,rotate)
|
||||||
import qualified SDL
|
import qualified SDL
|
||||||
|
|
||||||
|
halfwindow = over windowX ( / 2) . over windowY ( / 2)
|
||||||
|
|
||||||
doDrawing :: RenderData -> World -> IO (Word32)
|
doDrawing :: RenderData -> World -> IO (Word32)
|
||||||
doDrawing pdata w = do
|
doDrawing pdata w = do
|
||||||
sTicks <- SDL.ticks
|
sTicks <- SDL.ticks
|
||||||
@@ -47,28 +49,33 @@ doDrawing pdata w = do
|
|||||||
wallPoints = map fst wallPointsCol
|
wallPoints = map fst wallPointsCol
|
||||||
setCommonUniforms pdata rot zoom trans wins
|
setCommonUniforms pdata rot zoom trans wins
|
||||||
depthFunc $= Just Less
|
depthFunc $= Just Less
|
||||||
pmat <- (newMatrix RowMajor $ perspectiveMatrix w) :: IO (GLmatrix GLfloat)
|
pmat <- (newMatrix RowMajor $ perspectiveMatrix rot zoom trans wins viewFroms)
|
||||||
|
:: IO (GLmatrix GLfloat)
|
||||||
|
-- pmat2 <- (newMatrix RowMajor $ perspectiveMatrix $ halfwindow w) :: IO (GLmatrix GLfloat)
|
||||||
createLightMap pdata rot zoom trans wins wallPoints lightPoints viewFroms pmat
|
createLightMap pdata rot zoom trans wins wallPoints lightPoints viewFroms pmat
|
||||||
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
||||||
-- clear [DepthBuffer]
|
-- clear [DepthBuffer]
|
||||||
depthFunc $= Just Always
|
depthFunc $= Just Always
|
||||||
renderBackground pdata rot zoom trans wins
|
renderBackground pdata rot zoom trans wins
|
||||||
depthFunc $= Just Lequal
|
depthFunc $= Just Less
|
||||||
-- depthFunc $= Just Less
|
if w ^. config . wall_textured
|
||||||
renderWalls pdata wallPointsCol pmat
|
then renderTextureWalls pdata wallPointsCol pmat
|
||||||
setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat
|
else renderBlankWalls pdata wallPointsCol pmat
|
||||||
|
-- I believe a more apt name would be setCeilingDepth
|
||||||
|
-- setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat
|
||||||
-- depthFunc $= Just Lequal
|
-- depthFunc $= Just Lequal
|
||||||
renderFoldable pdata $ picToLTree (Just 0) pic
|
renderFoldable pdata $ picToLTree (Just 0) pic
|
||||||
-- reset blend so that light map doesn't apply
|
-- reset blend so that light map doesn't apply
|
||||||
-- blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
-- blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
||||||
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha) , (Zero,One))
|
blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha) , (Zero,One))
|
||||||
-- blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
-- blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
|
||||||
|
depthFunc $= Just Lequal
|
||||||
renderFoldable pdata $ picToLTree (Just 1) pic
|
renderFoldable pdata $ picToLTree (Just 1) pic
|
||||||
-- set drawing for on top
|
-- set drawing for on top
|
||||||
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
|
||||||
renderFoldable pdata $ picToLTree (Just 2) pic
|
renderFoldable pdata $ picToLTree (Just 2) pic
|
||||||
depthMask $= Disabled
|
depthMask $= Disabled
|
||||||
renderWalls pdata windowPoints pmat
|
renderBlankWalls pdata windowPoints pmat
|
||||||
depthMask $= Enabled
|
depthMask $= Enabled
|
||||||
resetShaderUniforms (map extractProgAndUnis $ _pictureShaders pdata)
|
resetShaderUniforms (map extractProgAndUnis $ _pictureShaders pdata)
|
||||||
----------------------
|
----------------------
|
||||||
@@ -76,3 +83,33 @@ doDrawing pdata w = do
|
|||||||
renderFoldable pdata (picToLTree Nothing $ fixedCoordPictures w)
|
renderFoldable pdata (picToLTree Nothing $ fixedCoordPictures w)
|
||||||
eTicks <- SDL.ticks
|
eTicks <- SDL.ticks
|
||||||
return (eTicks - sTicks)
|
return (eTicks - sTicks)
|
||||||
|
|
||||||
|
renderBlankWalls
|
||||||
|
:: RenderData
|
||||||
|
-> [((Point2,Point2),Point4)] -- ^ List: wall positions and color
|
||||||
|
-> GLmatrix GLfloat
|
||||||
|
-> IO ()
|
||||||
|
renderBlankWalls pdata wps pmat = do
|
||||||
|
n <- F.foldM (pokeShader $ _wallBlankShader pdata) wps
|
||||||
|
bindShaderBuffers [_wallBlankShader pdata] [n]
|
||||||
|
currentProgram $= Just (_shaderProgram $ _wallBlankShader pdata)
|
||||||
|
uniform (head (fromJust $ _shaderCustomUnis $ _wallBlankShader pdata) )
|
||||||
|
$= pmat
|
||||||
|
cullFace $= Just Back
|
||||||
|
drawShader (_wallBlankShader pdata) n
|
||||||
|
cullFace $= Nothing
|
||||||
|
|
||||||
|
renderTextureWalls
|
||||||
|
:: RenderData
|
||||||
|
-> [((Point2,Point2),Point4)] -- ^ List: wall positions and color
|
||||||
|
-> GLmatrix GLfloat
|
||||||
|
-> IO ()
|
||||||
|
renderTextureWalls pdata wps pmat = do
|
||||||
|
n <- F.foldM (pokeShader $ _wallTextureShader pdata) wps
|
||||||
|
bindShaderBuffers [_wallTextureShader pdata] [n]
|
||||||
|
currentProgram $= Just (_shaderProgram $ _wallTextureShader pdata)
|
||||||
|
uniform (head (fromJust $ _shaderCustomUnis $ _wallTextureShader pdata) )
|
||||||
|
$= pmat
|
||||||
|
cullFace $= Just Back
|
||||||
|
drawShader (_wallTextureShader pdata) n
|
||||||
|
cullFace $= Nothing
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ menuScreen cfig hw hh mLays = case mLays of
|
|||||||
,"n - MUSIC VOLUME + m : " ++ muvol
|
,"n - MUSIC VOLUME + m : " ++ muvol
|
||||||
]
|
]
|
||||||
(GraphicsOptionMenu : _) -> optionsList hw hh "OPTIONS:GRAPHICS"
|
(GraphicsOptionMenu : _) -> optionsList hw hh "OPTIONS:GRAPHICS"
|
||||||
["w - WALL TEXTURES"
|
["w - WALL TEXTURES:" ++ show (_wall_textured cfig)
|
||||||
]
|
]
|
||||||
(ControlList : _) -> pictures
|
(ControlList : _) -> pictures
|
||||||
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
|
[color (withAlpha 0.5 black) $ polygon $ screenBox hw hh
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
module Dodge.Render.PerspectiveMatrix
|
module Dodge.Render.PerspectiveMatrix
|
||||||
where
|
where
|
||||||
import Dodge.Data
|
|
||||||
|
|
||||||
import Geometry
|
import Geometry
|
||||||
|
|
||||||
import Linear.Matrix
|
import Linear.Matrix
|
||||||
import Linear.V4
|
import Linear.V4
|
||||||
import Graphics.Rendering.OpenGL (GLfloat)
|
import Graphics.Rendering.OpenGL (GLfloat)
|
||||||
|
|
||||||
perspectiveMatrix :: World -> [GLfloat]
|
perspectiveMatrix
|
||||||
perspectiveMatrix w =
|
:: Float -- ^ Rotation
|
||||||
let rot = _cameraRot w
|
-> Float -- ^ Zoom
|
||||||
zoom = _cameraZoom w
|
-> Point2 -- ^ Translation
|
||||||
(tranx,trany) = _cameraCenter w
|
-> Point2 -- ^ Window size
|
||||||
(winx,winy) = (_windowX w,_windowY w)
|
-> Point2 -- ^ View froms
|
||||||
(viewFromx,viewFromy) = _cameraViewFrom w
|
-> [GLfloat]
|
||||||
scalMat = Linear.Matrix.transpose $ V4
|
perspectiveMatrix rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
|
||||||
|
let scalMat = Linear.Matrix.transpose $ V4
|
||||||
(V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
(V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
||||||
(V4 0 (2*zoom/winy) 0 0)
|
(V4 0 (2*zoom/winy) 0 0)
|
||||||
(V4 0 0 0.5 0) --scaled to make walls shorter
|
(V4 0 0 0.5 0) --scaled to make walls shorter
|
||||||
|
|||||||
+11
-4
@@ -21,7 +21,8 @@ data RenderData = RenderData
|
|||||||
{ _lightingFloorShader :: FullShader (Float,Float,Float,Float)
|
{ _lightingFloorShader :: FullShader (Float,Float,Float,Float)
|
||||||
, _lightingOccludeShader :: FullShader (Point2,Point2)
|
, _lightingOccludeShader :: FullShader (Point2,Point2)
|
||||||
, _lightingWallShader :: FullShader (Point2,Point2)
|
, _lightingWallShader :: FullShader (Point2,Point2)
|
||||||
, _wallFaceShader :: FullShader ((Point2,Point2),Point4)
|
, _wallBlankShader :: FullShader ((Point2,Point2),Point4)
|
||||||
|
, _wallTextureShader :: FullShader ((Point2,Point2),Point4)
|
||||||
, _backgroundShader :: FullShader (Point2,Point2,Point2,Point2)
|
, _backgroundShader :: FullShader (Point2,Point2,Point2,Point2)
|
||||||
, _fullscreenShader :: FullShader ()
|
, _fullscreenShader :: FullShader ()
|
||||||
, _pictureShaders :: [FullShader RenderType]
|
, _pictureShaders :: [FullShader RenderType]
|
||||||
@@ -68,8 +69,12 @@ preloadRender = do
|
|||||||
bgShad <- makeShader "background" [vert,geom,frag] [(0,4),(1,2)] Points pokeBGStrat
|
bgShad <- makeShader "background" [vert,geom,frag] [(0,4),(1,2)] Points pokeBGStrat
|
||||||
>>= addTexture "data/texture/smudgedDirt.png"
|
>>= addTexture "data/texture/smudgedDirt.png"
|
||||||
|
|
||||||
-- wallShader
|
-- blank wallShader
|
||||||
wlFace <- makeShader "wall/blank" [vert,geom,frag] [(0,4),(1,4)] Points pokeWPColStrat
|
wlBlank <- makeShader "wall/blank" [vert,geom,frag] [(0,4),(1,4)] Points pokeWPColStrat
|
||||||
|
-- >>= addTexture "data/texture/grayscaleDirt.png"
|
||||||
|
>>= addUniforms ["perpMat"]
|
||||||
|
-- textured wallShader
|
||||||
|
wlTexture <- makeShader "wall/texture" [vert,geom,frag] [(0,4),(1,4)] Points pokeWPColStrat
|
||||||
>>= addTexture "data/texture/grayscaleDirt.png"
|
>>= addTexture "data/texture/grayscaleDirt.png"
|
||||||
>>= addUniforms ["perpMat"]
|
>>= addUniforms ["perpMat"]
|
||||||
|
|
||||||
@@ -84,7 +89,8 @@ preloadRender = do
|
|||||||
, _lightingFloorShader = lsShad
|
, _lightingFloorShader = lsShad
|
||||||
, _lightingOccludeShader = wsShad
|
, _lightingOccludeShader = wsShad
|
||||||
, _lightingWallShader = wlLightShad
|
, _lightingWallShader = wlLightShad
|
||||||
, _wallFaceShader = wlFace
|
, _wallBlankShader = wlBlank
|
||||||
|
, _wallTextureShader = wlTexture
|
||||||
, _backgroundShader = bgShad
|
, _backgroundShader = bgShad
|
||||||
, _fullscreenShader = fsShad
|
, _fullscreenShader = fsShad
|
||||||
, _spareFBO = fbo
|
, _spareFBO = fbo
|
||||||
@@ -113,6 +119,7 @@ setupFramebuffer = do
|
|||||||
fboTO <- genObjectName
|
fboTO <- genObjectName
|
||||||
textureBinding Texture2D $= Just fboTO
|
textureBinding Texture2D $= Just fboTO
|
||||||
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D 800 600) 0 (PixelData RGBA UnsignedByte nullPtr)
|
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D 800 600) 0 (PixelData RGBA UnsignedByte nullPtr)
|
||||||
|
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D 8 6) 0 (PixelData RGBA UnsignedByte nullPtr)
|
||||||
textureFilter Texture2D $= ((Linear',Just Linear') , Nearest)
|
textureFilter Texture2D $= ((Linear',Just Linear') , Nearest)
|
||||||
generateMipmap' Texture2D
|
generateMipmap' Texture2D
|
||||||
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D fboTO 0
|
framebufferTexture2D Framebuffer (ColorAttachment 0) Texture2D fboTO 0
|
||||||
|
|||||||
+45
-19
@@ -25,17 +25,12 @@ import Data.Maybe (fromJust)
|
|||||||
import qualified Data.IntMap.Strict as IM
|
import qualified Data.IntMap.Strict as IM
|
||||||
import qualified SDL
|
import qualified SDL
|
||||||
|
|
||||||
|
setWallDepth
|
||||||
renderWalls :: RenderData -> [((Point2,Point2),Point4)] -> GLmatrix GLfloat -> IO ()
|
:: RenderData
|
||||||
renderWalls pdata wps pmat = do
|
-> [(Point2,Point2)] -- ^ Wall points
|
||||||
n <- F.foldM (pokeShader $ _wallFaceShader pdata) wps
|
-> (Float,Float) -- ^ View from point
|
||||||
bindShaderBuffers [_wallFaceShader pdata] [n]
|
-> GLmatrix GLfloat
|
||||||
currentProgram $= Just (_shaderProgram $ _wallFaceShader pdata)
|
-> IO Word32
|
||||||
uniform (head (fromJust $ _shaderCustomUnis $ _wallFaceShader pdata) )
|
|
||||||
$= pmat
|
|
||||||
drawShader (_wallFaceShader pdata) n
|
|
||||||
|
|
||||||
setWallDepth :: RenderData -> [(Point2,Point2)] -> (Float,Float) -> GLmatrix GLfloat -> IO Word32
|
|
||||||
setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat = do
|
setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat = do
|
||||||
startTicks <- SDL.ticks
|
startTicks <- SDL.ticks
|
||||||
colorMask $= Color4 Disabled Disabled Disabled Disabled
|
colorMask $= Color4 Disabled Disabled Disabled Disabled
|
||||||
@@ -55,6 +50,8 @@ setWallDepth pdata wallPoints (viewFromx,viewFromy) pmat = do
|
|||||||
endTicks <- SDL.ticks
|
endTicks <- SDL.ticks
|
||||||
return $ endTicks - startTicks
|
return $ endTicks - startTicks
|
||||||
|
|
||||||
|
halfSize (Size x y) = Size (div x 2) (div y 2)
|
||||||
|
|
||||||
createLightMap
|
createLightMap
|
||||||
:: RenderData
|
:: RenderData
|
||||||
-> Float -- Rotation
|
-> Float -- Rotation
|
||||||
@@ -66,8 +63,13 @@ createLightMap
|
|||||||
-> (Float,Float) -- View from position
|
-> (Float,Float) -- View from position
|
||||||
-> GLmatrix GLfloat
|
-> GLmatrix GLfloat
|
||||||
-> IO ()
|
-> IO ()
|
||||||
createLightMap pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
|
createLightMap pdata rot zoom (tranx,trany) (winx',winy') wallPoints lightPoints
|
||||||
(viewFromx,viewFromy) pmat = do
|
(viewFromx,viewFromy) pmat = do
|
||||||
|
let winx = winx' / 2
|
||||||
|
winy = winy' / 2
|
||||||
|
|
||||||
|
(vppos,vpsize) <- get viewport
|
||||||
|
viewport $= (vppos, halfSize vpsize)
|
||||||
|
|
||||||
bindFramebuffer Framebuffer $= _spareFBO pdata
|
bindFramebuffer Framebuffer $= _spareFBO pdata
|
||||||
-- store wall and light positions into buffer
|
-- store wall and light positions into buffer
|
||||||
@@ -140,6 +142,7 @@ createLightMap pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
|
|||||||
cullFace $= Nothing
|
cullFace $= Nothing
|
||||||
stencilTest $= Disabled
|
stencilTest $= Disabled
|
||||||
blend $= Disabled
|
blend $= Disabled
|
||||||
|
viewport $= (vppos, vpsize)
|
||||||
bindFramebuffer Framebuffer $= defaultFramebufferObject
|
bindFramebuffer Framebuffer $= defaultFramebufferObject
|
||||||
colorMask $= Color4 Disabled Disabled Disabled Enabled
|
colorMask $= Color4 Disabled Disabled Disabled Enabled
|
||||||
bindShaderBuffers [_fullscreenShader pdata] [4]
|
bindShaderBuffers [_fullscreenShader pdata] [4]
|
||||||
@@ -148,7 +151,13 @@ createLightMap pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
|
|||||||
colorMask $= Color4 Enabled Enabled Enabled Enabled
|
colorMask $= Color4 Enabled Enabled Enabled Enabled
|
||||||
blend $= Enabled
|
blend $= Enabled
|
||||||
|
|
||||||
renderBackground :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> IO ()
|
renderBackground
|
||||||
|
:: RenderData
|
||||||
|
-> Float -- Rotation
|
||||||
|
-> Float -- Zoom
|
||||||
|
-> (Float,Float) -- Translation
|
||||||
|
-> (Float,Float) -- Window size
|
||||||
|
-> IO ()
|
||||||
renderBackground pdata rot zoom (tranx,trany) (winx,winy) = do
|
renderBackground pdata rot zoom (tranx,trany) (winx,winy) = do
|
||||||
-- depthFunc $= Just Less
|
-- depthFunc $= Just Less
|
||||||
-- set drawing for on top
|
-- set drawing for on top
|
||||||
@@ -164,7 +173,13 @@ renderBackground pdata rot zoom (tranx,trany) (winx,winy) = do
|
|||||||
textureBinding Texture2D $= _textureObject <$> _shaderTexture (_backgroundShader pdata)
|
textureBinding Texture2D $= _textureObject <$> _shaderTexture (_backgroundShader pdata)
|
||||||
drawArrays Points 0 1
|
drawArrays Points 0 1
|
||||||
|
|
||||||
setCommonUniforms :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> IO ()
|
setCommonUniforms
|
||||||
|
:: RenderData
|
||||||
|
-> Float -- ^ Rotation
|
||||||
|
-> Float -- ^ Zoom
|
||||||
|
-> (Float,Float) -- ^ Translation
|
||||||
|
-> (Float,Float) -- ^ Window size
|
||||||
|
-> IO ()
|
||||||
setCommonUniforms pdata rot zoom (tranx,trany) (winx,winy) = do
|
setCommonUniforms pdata rot zoom (tranx,trany) (winx,winy) = do
|
||||||
setShaderUniforms rot zoom (tranx,trany) (winx,winy)
|
setShaderUniforms rot zoom (tranx,trany) (winx,winy)
|
||||||
( extractProgAndUnis (_lightingFloorShader pdata)
|
( extractProgAndUnis (_lightingFloorShader pdata)
|
||||||
@@ -174,7 +189,11 @@ setCommonUniforms pdata rot zoom (tranx,trany) (winx,winy) = do
|
|||||||
: map extractProgAndUnis (_pictureShaders pdata)
|
: map extractProgAndUnis (_pictureShaders pdata)
|
||||||
)
|
)
|
||||||
|
|
||||||
renderFoldable :: Foldable f => RenderData -> f RenderType -> IO Word32
|
renderFoldable
|
||||||
|
:: Foldable f
|
||||||
|
=> RenderData
|
||||||
|
-> f RenderType
|
||||||
|
-> IO Word32
|
||||||
renderFoldable pdata tree = do
|
renderFoldable pdata tree = do
|
||||||
pokeStartTicks <- SDL.ticks
|
pokeStartTicks <- SDL.ticks
|
||||||
|
|
||||||
@@ -183,7 +202,7 @@ renderFoldable pdata tree = do
|
|||||||
-- poke data, returns list of number of vertices for each shader
|
-- poke data, returns list of number of vertices for each shader
|
||||||
is <- F.foldM (pokeShaders slist) tree
|
is <- F.foldM (pokeShaders slist) tree
|
||||||
|
|
||||||
-- the idea of doing as binding of buffers at once, rather than interweaving with draw
|
-- the idea of binding many buffers at once, rather than interweaving with draw
|
||||||
-- calls, is to prevent opengl from waiting for a draw call to finish
|
-- calls, is to prevent opengl from waiting for a draw call to finish
|
||||||
-- before it performs another state change
|
-- before it performs another state change
|
||||||
bindShaderBuffers slist is
|
bindShaderBuffers slist is
|
||||||
@@ -194,13 +213,20 @@ renderFoldable pdata tree = do
|
|||||||
return $ pokeEndTicks - pokeStartTicks
|
return $ pokeEndTicks - pokeStartTicks
|
||||||
------------------------------end renderFoldable
|
------------------------------end renderFoldable
|
||||||
|
|
||||||
|
pokeTwoOff
|
||||||
pokeTwoOff :: Ptr Float -> Int -> (Float,Float) -> IO ()
|
:: Ptr Float
|
||||||
|
-> Int
|
||||||
|
-> (Float,Float)
|
||||||
|
-> IO ()
|
||||||
{-# INLINE pokeTwoOff #-}
|
{-# INLINE pokeTwoOff #-}
|
||||||
pokeTwoOff ptr n (x,y) = do
|
pokeTwoOff ptr n (x,y) = do
|
||||||
pokeElemOff ptr (2*n+0) x
|
pokeElemOff ptr (2*n+0) x
|
||||||
pokeElemOff ptr (2*n+1) y
|
pokeElemOff ptr (2*n+1) y
|
||||||
pokeThreeOff :: Ptr Float -> Int -> (Float,Float,Float) -> IO ()
|
pokeThreeOff
|
||||||
|
:: Ptr Float
|
||||||
|
-> Int
|
||||||
|
-> (Float,Float,Float)
|
||||||
|
-> IO ()
|
||||||
{-# INLINE pokeThreeOff #-}
|
{-# INLINE pokeThreeOff #-}
|
||||||
pokeThreeOff ptr n (x,y,z) = do
|
pokeThreeOff ptr n (x,y,z) = do
|
||||||
pokeElemOff ptr (3*n+0) x
|
pokeElemOff ptr (3*n+0) x
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ resizeSpareFBO xsize ysize pdata = do
|
|||||||
fboName = _spareFBO rdata
|
fboName = _spareFBO rdata
|
||||||
fboTO = _fboTexture rdata
|
fboTO = _fboTexture rdata
|
||||||
fboRBO = _fboRenderbufferObject rdata
|
fboRBO = _fboRenderbufferObject rdata
|
||||||
xsize' = fromIntegral xsize
|
xsize' = fromIntegral $ xsize `div` 2
|
||||||
ysize' = fromIntegral ysize
|
ysize' = fromIntegral $ ysize `div` 2
|
||||||
bindFramebuffer Framebuffer $= fboName
|
bindFramebuffer Framebuffer $= fboName
|
||||||
textureBinding Texture2D $= Just fboTO
|
textureBinding Texture2D $= Just fboTO
|
||||||
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D xsize' ysize') 0 (PixelData RGBA UnsignedByte nullPtr)
|
texImage2D Texture2D NoProxy 0 RGBA8 (TextureSize2D xsize' ysize') 0 (PixelData RGBA UnsignedByte nullPtr)
|
||||||
|
|||||||
Reference in New Issue
Block a user