Allow to change menu options with rclick, move towards shader experiment

This commit is contained in:
2023-02-24 15:03:06 +00:00
parent 774316372f
commit ed9a46a18d
9 changed files with 71 additions and 42 deletions
+7 -3
View File
@@ -3,8 +3,10 @@ layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 4) out; layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos; uniform vec3 lightPos;
//vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos)), 1));} uniform vec4 lumRad;
vec4 shift (vec4 p) { return (vec4 (p.xyz + (1000*(p.xyz-lightPos)), 1));} //vec4 shift (vec4 p) { return (vec4 (p.xyz + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos)), 1));}
//vec4 shift (vec4 p) { return (vec4 (lightPos + (lumRad.a*normalize(p.xyz-lightPos)), 1));}
// copied from lighting/cap.geom, should not be changed on its own // copied from lighting/cap.geom, should not be changed on its own
vec4 projNear (vec4 pos) vec4 projNear (vec4 pos)
{ {
@@ -27,6 +29,7 @@ void main()
{ {
vec4 p0 = gl_in[0].gl_Position; vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position; vec4 p1 = gl_in[1].gl_Position;
vec4 mid = 0.5*(p0 + p1);
vec3 n0a = gl_in[2].gl_Position.xyz; vec3 n0a = gl_in[2].gl_Position.xyz;
vec3 n1a = gl_in[3].gl_Position.xyz; vec3 n1a = gl_in[3].gl_Position.xyz;
vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz) ; vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz) ;
@@ -34,10 +37,11 @@ void main()
//vec3 n2 = n0 + n1; // assumes the summands are normalized //vec3 n2 = n0 + n1; // assumes the summands are normalized
vec3 lightDir = p0.xyz - lightPos.xyz; vec3 lightDir = p0.xyz - lightPos.xyz;
vec3 lightDir2 = p1.xyz - lightPos.xyz;
// first test if the edge is part of the silhouette // first test if the edge is part of the silhouette
// that is, if the normals of the faces connected by the edge point are in // that is, if the normals of the faces connected by the edge point are in
// "different directions" wrt the light direction // "different directions" wrt the light direction
if ( dot(n0 , lightDir) * dot(n1 , lightDir) <= 0 ) if ( dot(n0 , lightDir) * dot(n1 , lightDir) <= 0 )
// using <= rather than < seems to get rid of overlapping shadow // using <= rather than < seems to get rid of overlapping shadow
// artefacts // artefacts
{ {
+1
View File
@@ -14,6 +14,7 @@ import Control.Monad.Primitive
data RenderData = RenderData data RenderData = RenderData
{ _lightingWallShadShader :: FullShader { _lightingWallShadShader :: FullShader
, _lightingLineShadowShader :: FullShader , _lightingLineShadowShader :: FullShader
, _positionalBlankShader :: FullShader
, _lightingCapShader :: FullShader , _lightingCapShader :: FullShader
, _wallBlankShader :: FullShader , _wallBlankShader :: FullShader
, _windowShader :: FullShader , _windowShader :: FullShader
+7 -3
View File
@@ -16,7 +16,7 @@ data Configuration = Configuration
, _volume_music :: Float , _volume_music :: Float
, _graphics_wall_textured :: Bool , _graphics_wall_textured :: Bool
, _graphics_cloud_shadows :: Bool , _graphics_cloud_shadows :: Bool
, _graphics_object_shadows :: Bool , _graphics_object_shadows :: ObjectShadows
, _graphics_resolution_factor :: ResFactor , _graphics_resolution_factor :: ResFactor
, _windowX :: Float , _windowX :: Float
, _windowY :: Float , _windowY :: Float
@@ -60,6 +60,9 @@ data DebugBool
data ResFactor = FullRes | HalfRes | QuarterRes data ResFactor = FullRes | HalfRes | QuarterRes
deriving (Show, Eq, Ord, Enum, Bounded) deriving (Show, Eq, Ord, Enum, Bounded)
data ObjectShadows = GeoObjShads | CPUObjShads | NoObjShads
deriving (Show, Eq, Ord, Enum, Bounded)
data RoomClipping = NoRoomClipBoundaries | AllRoomClipBoundaries | IntersectingRoomClipBoundaries data RoomClipping = NoRoomClipBoundaries | AllRoomClipBoundaries | IntersectingRoomClipBoundaries
deriving (Show, Eq, Ord, Enum, Bounded) deriving (Show, Eq, Ord, Enum, Bounded)
@@ -74,10 +77,10 @@ defaultConfig =
Configuration Configuration
{ _volume_master = 1 { _volume_master = 1
, _volume_sound = 1 , _volume_sound = 1
, _volume_music = 1 , _volume_music = 0
, _graphics_wall_textured = True , _graphics_wall_textured = True
, _graphics_cloud_shadows = True , _graphics_cloud_shadows = True
, _graphics_object_shadows = True , _graphics_object_shadows = GeoObjShads
, _graphics_resolution_factor = FullRes , _graphics_resolution_factor = FullRes
, _windowX = 800 , _windowX = 800
, _windowY = 600 , _windowY = 600
@@ -93,6 +96,7 @@ debugOn db = S.member db . _debug_booleans
makeLenses ''Configuration makeLenses ''Configuration
deriveJSON defaultOptions ''ResFactor deriveJSON defaultOptions ''ResFactor
deriveJSON defaultOptions ''ObjectShadows
deriveJSON defaultOptions ''RoomClipping deriveJSON defaultOptions ''RoomClipping
deriveJSON defaultOptions ''DebugBool deriveJSON defaultOptions ''DebugBool
deriveJSON defaultOptions ''Configuration deriveJSON defaultOptions ''Configuration
+1 -1
View File
@@ -60,7 +60,7 @@ data ScreenLayer
, _scOffset :: Int , _scOffset :: Int
, _scPositionedMenuOption :: PositionedMenuOption , _scPositionedMenuOption :: PositionedMenuOption
, _scOptionFlag :: OptionScreenFlag , _scOptionFlag :: OptionScreenFlag
, _scSelectionList :: SelectionList (Universe -> Universe) , _scSelectionList :: SelectionList (Universe -> Universe,Universe->Universe)
, _scAvailableLines :: Int , _scAvailableLines :: Int
, _scListDisplayParams :: ListDisplayParams , _scListDisplayParams :: ListDisplayParams
} }
+1 -1
View File
@@ -184,7 +184,7 @@ graphicsMenuOptions :: [MenuOption]
graphicsMenuOptions = graphicsMenuOptions =
[ makeEnumOption graphics_resolution_factor "RESOLUTION" (uvIOEffects .~ updateFramebufferSize) [ makeEnumOption graphics_resolution_factor "RESOLUTION" (uvIOEffects .~ updateFramebufferSize)
, makeBoolOption graphics_wall_textured "WALL TEXTURES" , makeBoolOption graphics_wall_textured "WALL TEXTURES"
, makeBoolOption graphics_object_shadows "OBJECT SHADOWS" , makeEnumOption graphics_object_shadows "OBJECT SHADOWS" id
, makeBoolOption graphics_cloud_shadows "CLOUD SHADOWS" , makeBoolOption graphics_cloud_shadows "CLOUD SHADOWS"
] ]
+9 -5
View File
@@ -1,5 +1,6 @@
module Dodge.Menu.Option where module Dodge.Menu.Option where
import Control.Applicative
--import Dodge.ScodeToChar --import Dodge.ScodeToChar
import Dodge.Default.SelectionList import Dodge.Default.SelectionList
import Data.Maybe import Data.Maybe
@@ -61,14 +62,15 @@ makeOptionsSelectionList ::
Universe -> Universe ->
[MenuOption] -> [MenuOption] ->
PositionedMenuOption -> PositionedMenuOption ->
SelectionList (Universe -> Universe) SelectionList (Universe -> Universe,Universe -> Universe)
makeOptionsSelectionList maxlines mselpos u mos pmo = makeOptionsSelectionList maxlines mselpos u mos pmo =
defaultSelectionList defaultSelectionList
{ _slItems = optionsToSelections maxlines u mos pmo { _slItems = optionsToSelections maxlines u mos pmo
, _slSelPos = mselpos , _slSelPos = mselpos
} }
optionsToSelections :: Int -> Universe -> [MenuOption] -> PositionedMenuOption -> [SelectionItem (Universe -> Universe)] optionsToSelections :: Int -> Universe -> [MenuOption] -> PositionedMenuOption
-> [SelectionItem (Universe -> Universe,Universe -> Universe)]
optionsToSelections maxlines u allops pmo = case pmo of optionsToSelections maxlines u allops pmo = case pmo of
NoPositionedMenuOption -> map (menuOptionToSelectionItem u maxOptionLength) ops NoPositionedMenuOption -> map (menuOptionToSelectionItem u maxOptionLength) ops
TopMenuOption mo -> map (menuOptionToSelectionItem u maxOptionLength) (mo : ops) TopMenuOption mo -> map (menuOptionToSelectionItem u maxOptionLength) (mo : ops)
@@ -115,7 +117,8 @@ optionValueOffset u mo = case _moString mo u of
MODStringOption s _ -> length s MODStringOption s _ -> length s
_ -> 0 _ -> 0
menuOptionToSelectionItem :: Universe -> Int -> MenuOption -> SelectionItem (Universe -> Universe) menuOptionToSelectionItem :: Universe -> Int -> MenuOption
-> SelectionItem (Universe -> Universe,Universe -> Universe)
menuOptionToSelectionItem w padAmount mo = menuOptionToSelectionItem w padAmount mo =
SelectionItem SelectionItem
{ _siPictures = [optionText] { _siPictures = [optionText]
@@ -124,13 +127,14 @@ menuOptionToSelectionItem w padAmount mo =
--, _siWidth = length optionText --, _siWidth = length optionText
, _siColor = thecol , _siColor = thecol
, _siOffX = 0 , _siOffX = 0
, _siPayload = f , _siPayload = (f,g)
} }
where where
isselectable = case _moString mo w of isselectable = case _moString mo w of
MODBlockedString{} -> False MODBlockedString{} -> False
_ -> True _ -> True
f = fromMaybe id $ mo ^? moEff f = fromMaybe id $ mo ^? moEff <|> mo ^? moEff1
g = fromMaybe id $ mo ^? moEff2
thecol = case _moString mo w of thecol = case _moString mo w of
MODBlockedString{} -> greyN 0.5 MODBlockedString{} -> greyN 0.5
_ -> white _ -> white
+11 -4
View File
@@ -38,7 +38,7 @@ optionScreenUpdate ::
ScreenLayer -> ScreenLayer ->
PositionedMenuOption -> PositionedMenuOption ->
ListDisplayParams -> ListDisplayParams ->
SelectionList (Universe -> Universe) -> SelectionList (Universe -> Universe,Universe -> Universe) ->
Universe -> Universe ->
Universe Universe
optionScreenUpdate screen mop ldps sl u = optionScreenUpdate screen mop ldps sl u =
@@ -55,17 +55,24 @@ optionScreenDefaultEffect f u = case u ^. uvWorld . input . pressedKeys . at Sca
Just InitialPress -> fromMaybe id (f ^? pmoMenuOption . moEff) u Just InitialPress -> fromMaybe id (f ^? pmoMenuOption . moEff) u
_ -> u _ -> u
-- ouch this is not good
mouseClickOptionsList :: ScreenLayer -> Universe -> Universe mouseClickOptionsList :: ScreenLayer -> Universe -> Universe
mouseClickOptionsList screen u = fromMaybe u $ do mouseClickOptionsList screen u = fromMaybe u $ do
sl <- screen ^? scSelectionList sl <- screen ^? scSelectionList
Just $ case u ^. uvWorld . input . mouseButtons . at ButtonLeft of Just $ case u ^. uvWorld . input . mouseButtons . at ButtonLeft of
Just False -> fromMaybe u $ do Just False -> fromMaybe u $ do
i <- sl ^. slSelPos i <- sl ^. slSelPos
f <- sl ^? slItems . ix i . siPayload f <- sl ^? slItems . ix i . siPayload . _1
return $ f u return $ f u
_ -> u _ -> case u ^. uvWorld . input . mouseButtons . at ButtonRight of
Just False -> fromMaybe u $ do
i <- sl ^. slSelPos
f <- sl ^? slItems . ix i . siPayload . _2
return $ f u
_ -> u
mouseOverSelectionList :: ListDisplayParams -> SelectionList (Universe -> Universe) -> Universe -> Universe mouseOverSelectionList :: ListDisplayParams
-> SelectionList a -> Universe -> Universe
mouseOverSelectionList ldps sl u mouseOverSelectionList ldps sl u
| x > xl && x < xr | x > xl && x < xr
&& ylower == yupper && ylower == yupper
+5 -1
View File
@@ -121,7 +121,10 @@ preloadRender = do
>>= addUniforms ["lightPos"] >>= addUniforms ["lightPos"]
lightingLineShadowShad lightingLineShadowShad
<- makeShaderUsingVAO "lighting/lineShadow" [vert,geom,frag] ELinesAdjacency shEdgeVAO <- makeShaderUsingVAO "lighting/lineShadow" [vert,geom,frag] ELinesAdjacency shEdgeVAO
>>= addUniforms ["lightPos"] >>= addUniforms ["lightPos","lumRad"]
-- positional shader
positionalBlankShad <- makeShader "positional/blank" [vert,frag] [3] ETriangles
-- 2D draw shaders -- 2D draw shaders
bslist <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles bslist <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles
bslista <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles bslista <- makeShader "dualTwoD/basic" [vert,frag] [3,4] ETriangles
@@ -199,6 +202,7 @@ preloadRender = do
, _silhouetteEBO = silEBO , _silhouetteEBO = silEBO
, _lightingCapShader = lightingCapShad , _lightingCapShader = lightingCapShad
, _lightingLineShadowShader = lightingLineShadowShad , _lightingLineShadowShader = lightingLineShadowShad
, _positionalBlankShader = positionalBlankShad
, _lightingWallShadShader = lightingWallShadShad , _lightingWallShadShader = lightingWallShadShad
, _wallBlankShader = wallBlankShad , _wallBlankShader = wallBlankShad
, _wallTextureShader = wallTextureShad , _wallTextureShader = wallTextureShad
+29 -24
View File
@@ -7,6 +7,7 @@ module Render
, bindTO , bindTO
, bindFBO , bindFBO
) where ) where
import Dodge.Data.Config
import Shader import Shader
import Shader.ExtraPrimitive import Shader.ExtraPrimitive
import Shader.Data import Shader.Data
@@ -20,7 +21,7 @@ import qualified Data.Vector.Unboxed.Mutable as UMV
import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Mutable as MV
import Control.Monad.Primitive import Control.Monad.Primitive
import Graphics.GL.Core43 import Graphics.GL.Core43
import Control.Monad --import Control.Monad
import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Fusion.Stream.Monadic as VFSM
divideSize :: Int -> Size -> Size divideSize :: Int -> Size -> Size
@@ -33,7 +34,7 @@ createLightMap
-> Int -- ^ number of walls -> Int -- ^ number of walls
-> Int -- ^ number of silhoutte lines to draw -> Int -- ^ number of silhoutte lines to draw
-> Int -- ^ number of "caps" to attempt to draw -> Int -- ^ number of "caps" to attempt to draw
-> Bool -- ^ whether to draw object shadows or not -> ObjectShadows -- ^ whether to draw object shadows or not
-> TextureObject -- ^ the texture object giving positions -> TextureObject -- ^ the texture object giving positions
-> IO () -> IO ()
createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos = do createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos = do
@@ -71,28 +72,32 @@ createLightMap pdata lightPoints nWalls nSils nCaps drawObjShads toPos = do
(marshalEPrimitiveMode $ _shadPrim lwShad) (marshalEPrimitiveMode $ _shadPrim lwShad)
0 0
(fromIntegral nWalls) (fromIntegral nWalls)
when drawObjShads $ do case drawObjShads of
--draw silhouette shadows GeoObjShads -> do
currentProgram $= Just (_shadProg llsShad) --draw silhouette shadows
uniform (head $ _shadUnis $ _lightingLineShadowShader pdata) currentProgram $= Just (_shadProg llsShad)
$= Vector3 x y z uniform (head $ _shadUnis $ _lightingLineShadowShader pdata)
bindVertexArrayObject $= Just (_vao $ _shadVAO llsShad) $= Vector3 x y z
glDrawElements uniform (_shadUnis ltShad !! 1)
(marshalEPrimitiveMode $ _shadPrim llsShad) $= Vector4 r g b rad
(fromIntegral nSils) bindVertexArrayObject $= Just (_vao $ _shadVAO llsShad)
GL_UNSIGNED_SHORT glDrawElements
nullPtr (marshalEPrimitiveMode $ _shadPrim llsShad)
cullFace $= Just Back (fromIntegral nSils)
--draw caps on the near plane as required GL_UNSIGNED_SHORT
currentProgram $= Just (_shadProg lcShad) nullPtr
uniform (head $ _shadUnis lcShad) --draw caps on the near plane as required
$= Vector3 x y z cullFace $= Just Back
bindVertexArrayObject $= Just (_vao $ _shadVAO lcShad) currentProgram $= Just (_shadProg lcShad)
glDrawElements uniform (head $ _shadUnis lcShad)
(marshalEPrimitiveMode $ _shadPrim lcShad) $= Vector3 x y z
(fromIntegral nCaps) bindVertexArrayObject $= Just (_vao $ _shadVAO lcShad)
GL_UNSIGNED_SHORT glDrawElements
nullPtr (marshalEPrimitiveMode $ _shadPrim lcShad)
(fromIntegral nCaps)
GL_UNSIGNED_SHORT
nullPtr
_ -> return ()
--draw lightmap itself --draw lightmap itself
depthFunc $= Just Always depthFunc $= Just Always
-- bind world position texture -- bind world position texture