diff --git a/shader/shadow/cap.geom b/shader/shadow/cap.geom index 3e5fdaa7d..a686a9450 100644 --- a/shader/shadow/cap.geom +++ b/shader/shadow/cap.geom @@ -9,6 +9,7 @@ layout (std140, binding = 1) uniform LightsBlock } ; uniform int lightID; vec3 lightPos = posBool[lightID].xyz ; +float theBool = posBool[gl_InvocationID].w; // this code is duplicated in lineShadow.geom, should not be changed on its own vec4 projNear (vec4 pos) { @@ -29,6 +30,7 @@ void main() ( p0.z - lightPos.z > 0 ) && ( p1.z - lightPos.z > 0 ) && ( p2.z - lightPos.z > 0 ) + && theBool == 1 ) { // the front cap diff --git a/shader/shadow/combine.frag b/shader/shadow/combine.frag new file mode 100644 index 000000000..2544b52d9 --- /dev/null +++ b/shader/shadow/combine.frag @@ -0,0 +1,9 @@ +#version 450 core +uniform sampler2DArray screenTexture; +in vec3 gTexPos; +out vec4 fColor; +void main() +{ + fColor = texture(screenTexture,gTexPos); + //fColor = vec4(0.05,0.01,0,1); +} diff --git a/shader/shadow/combine.geom b/shader/shadow/combine.geom new file mode 100644 index 000000000..137f7612f --- /dev/null +++ b/shader/shadow/combine.geom @@ -0,0 +1,30 @@ +#version 450 core +layout (points) in; +layout (triangle_strip, max_vertices = 4) out; +layout (invocations = 20) in; +layout (std140, binding = 1) uniform LightsBlock +{ + vec4 posBool[20]; + vec4 colRad[20]; +} ; +out vec3 gTexPos; +float theBool = posBool[gl_InvocationID].w; +float l = gl_InvocationID; +void main() +{ + if (theBool == 1){ + gTexPos = vec3(0,1,l); + gl_Position = vec4(-1,1,0,1) ; + EmitVertex(); + gTexPos = vec3(0,0,l); + gl_Position = vec4(-1,-1,0,1) ; + EmitVertex(); + gTexPos = vec3(1,1,l); + gl_Position = vec4(1,1,0,1) ; + EmitVertex(); + gTexPos = vec3(1,0,l); + gl_Position = vec4(1,-1,0,1) ; + EmitVertex(); + EndPrimitive(); + }else {} +} diff --git a/shader/shadow/combine.vert b/shader/shadow/combine.vert new file mode 100644 index 000000000..92b639316 --- /dev/null +++ b/shader/shadow/combine.vert @@ -0,0 +1,4 @@ +#version 450 core +void main() +{ +} diff --git a/shader/shadow/edge.geom b/shader/shadow/edge.geom index af9aa0c80..669392067 100644 --- a/shader/shadow/edge.geom +++ b/shader/shadow/edge.geom @@ -1,5 +1,6 @@ #version 450 core layout (lines_adjacency) in; +layout (invocations = 20) in; layout (triangle_strip, max_vertices = 4) out; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 1) uniform LightsBlock @@ -7,9 +8,8 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -uniform int lightID; -vec3 lightPos1 = posBool[lightID].xyz; -float theBool = posBool[lightID].w; +vec3 lightPos1 = posBool[gl_InvocationID].xyz; +float theBool = posBool[gl_InvocationID].w; vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos1)), 1));} ; vec4 shiftBy (float x,vec4 p) { return (vec4 (lightPos1 + (x*normalize(p.xyz-lightPos1)), 1));} ; // copied from lighting/cap.geom, should not be changed on its own @@ -34,7 +34,7 @@ void main() { if (theBool == 1){ // float ru2 = radiusUniform * radiusUniform ; - float ru = colRad[lightID].w ; + float ru = colRad[gl_InvocationID].w ; float ru2 = ru * ru; vec4 p0 = gl_in[0].gl_Position; vec4 p1 = gl_in[1].gl_Position; @@ -59,17 +59,17 @@ void main() vec4 p3 = shiftNear(p1); if ( dot(n0 , lightDir) > 0) { - gl_Position = f(p0); EmitVertex(); - gl_Position = f(p1); EmitVertex(); - gl_Position = f(p2); EmitVertex(); - gl_Position = f(p3); EmitVertex(); + gl_Position = f(p0); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p1); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p2); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p3); gl_Layer = gl_InvocationID; EmitVertex(); } else { - gl_Position = f(p1); EmitVertex(); - gl_Position = f(p0); EmitVertex(); - gl_Position = f(p3); EmitVertex(); - gl_Position = f(p2); EmitVertex(); + gl_Position = f(p1); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p0); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p3); gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = f(p2); gl_Layer = gl_InvocationID; EmitVertex(); } EndPrimitive(); } diff --git a/shader/shadow/light.frag b/shader/shadow/light.frag index 545bf4bca..cd16acbcf 100644 --- a/shader/shadow/light.frag +++ b/shader/shadow/light.frag @@ -8,14 +8,15 @@ uniform int lightID; vec3 lightPos = posBool[lightID].xyz; vec4 lumRad = colRad[lightID]; uniform sampler2D screenTexture; -in vec2 vTexPos; +in vec2 gTexPos; out vec4 fColor; void main() { - vec3 distVec = texture(screenTexture,vTexPos).xyz - lightPos; + vec3 distVec = texture(screenTexture,gTexPos).xyz - lightPos; float dist = dot(distVec,distVec); if (dist > lumRad.a) {discard;} float x = 1 - dist / lumRad.a ; vec3 c = (x * x * x) * lumRad.rgb ; - fColor = vec4(c,0); + //fColor = vec4(c,0); + fColor = vec4(1,0,0,0); } diff --git a/shader/shadow/light.geom b/shader/shadow/light.geom new file mode 100644 index 000000000..f7aaf004d --- /dev/null +++ b/shader/shadow/light.geom @@ -0,0 +1,25 @@ +#version 450 core +layout (triangles) in; +layout (triangle_strip, max_vertices = 3) out; +layout (invocations = 20) in; +layout (std140, binding = 1) uniform LightsBlock +{ + vec4 posBool[20]; + vec4 colRad[20]; +} ; +float theBool = posBool[gl_InvocationID].w; +in vec2 vTexPos[]; +out vec2 gTexPos; +void main() +{ + if (theBool == 1){ + for (int i = 0; i < 3; i++) + { + gTexPos = vTexPos[i]; + gl_Layer = gl_InvocationID; + gl_Position = gl_in[i].gl_Position; + EmitVertex(); + } + EndPrimitive(); + }else {} +} diff --git a/shader/shadow/wallShadow.geom b/shader/shadow/wallShadow.geom index 85e4f8863..fb7d19fe9 100644 --- a/shader/shadow/wallShadow.geom +++ b/shader/shadow/wallShadow.geom @@ -1,5 +1,6 @@ #version 450 core layout (points) in; +layout (invocations = 20) in; layout (triangle_strip, max_vertices = 8) out; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 1) uniform LightsBlock @@ -7,8 +8,8 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -uniform int lightID; -vec3 lightPos = posBool[lightID].xyz; +vec3 lightPos = posBool[gl_InvocationID].xyz; +float theBool = posBool[gl_InvocationID].w; vec4 shift (vec4 p) { return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0 , 1); } @@ -21,7 +22,7 @@ void main() { vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); -if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) +if (theBool==1 && isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) { vec4 p3 = vec4 (p1.xy,100,1); vec4 p4 = vec4 (p2.xy,100,1); @@ -39,35 +40,14 @@ vec4 a6 = theMat * p6; vec4 a7 = theMat * p7; vec4 a8 = theMat * p8; - //gl_Position = a4; EmitVertex(); - //gl_Position = a3; EmitVertex(); - //gl_Position = a7; EmitVertex(); - //gl_Position = a8; EmitVertex(); - //gl_Position = a5; EmitVertex(); - //gl_Position = a3; EmitVertex(); - //gl_Position = a1; EmitVertex(); - //gl_Position = a4; EmitVertex(); - //gl_Position = a2; EmitVertex(); - //gl_Position = a7; EmitVertex(); - //gl_Position = a6; EmitVertex(); - - gl_Position = a1; EmitVertex(); - gl_Position = a5; EmitVertex(); - gl_Position = a3; EmitVertex(); - gl_Position = a8; EmitVertex(); - gl_Position = a4; EmitVertex(); - gl_Position = a7; EmitVertex(); - gl_Position = a2; EmitVertex(); - gl_Position = a6; EmitVertex(); - - //gl_Position = a5; EmitVertex(); - //gl_Position = a1; EmitVertex(); - //gl_Position = a8; EmitVertex(); - //gl_Position = a3; EmitVertex(); - //gl_Position = a7; EmitVertex(); - //gl_Position = a4; EmitVertex(); - //gl_Position = a6; EmitVertex(); - //gl_Position = a2; EmitVertex(); + gl_Position = a1; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a5; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a3; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a8; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a4; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a7; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a2; gl_Layer = gl_InvocationID; EmitVertex(); + gl_Position = a6; gl_Layer = gl_InvocationID; EmitVertex(); EndPrimitive(); } else {} diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index 428e9adfa..8dcf1e6ba 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -23,6 +23,7 @@ data RenderData = RenderData , _shadowCapShader :: FullShader , _shadowWallShader :: FullShader , _shadowLightShader :: FullShader + , _shadowCombineShader :: FullShader , _positionalBlankShader :: FullShader , _wallBlankShader :: FullShader , _windowShader :: FullShader diff --git a/src/Dodge/Data/Input.hs b/src/Dodge/Data/Input.hs index f2538d1fe..00d4f7ada 100644 --- a/src/Dodge/Data/Input.hs +++ b/src/Dodge/Data/Input.hs @@ -27,7 +27,8 @@ data Input = Input , _rSelect :: Point2 , _clickMousePos :: Point2 , _textInput :: String - , _scrollTestValue :: Float + , _scrollTestFloat :: Float + , _scrollTestInt :: Int } makeLenses ''Input diff --git a/src/Dodge/Default/World.hs b/src/Dodge/Default/World.hs index 7ee9fe939..232af41a7 100644 --- a/src/Dodge/Default/World.hs +++ b/src/Dodge/Default/World.hs @@ -26,7 +26,8 @@ defaultInput = , _rLine = (0, 0) , _lSelect = 0 , _rSelect = 0 - , _scrollTestValue = 1 + , _scrollTestFloat = 1 + , _scrollTestInt = 0 } defaultWorld :: World diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index ccd249321..c9a7e7dd6 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -3,6 +3,7 @@ module Dodge.Render ( doDrawing, ) where +import qualified Data.Map.Strict as M import Picture.Base import qualified SDL import qualified Data.Vector as V @@ -31,8 +32,18 @@ import Shader.Parameters import Shader.Poke doDrawing :: SDL.Window -> RenderData -> Universe -> IO () -doDrawing win pdata u = do +doDrawing window rdata u + | SDL.ScancodeT `M.member` (u ^. uvWorld . input . pressedKeys) = doTestDrawing rdata u + | otherwise = doDrawing' window rdata u + +doTestDrawing :: RenderData -> Universe -> IO () +doTestDrawing _ _ = do + return () + +doDrawing' :: SDL.Window -> RenderData -> Universe -> IO () +doDrawing' win pdata u = do --sTicks <- SDL.ticks + checkGLError let w = _uvWorld u cfig = _uvConfig u rot = w ^. cWorld . camPos . camRot @@ -139,6 +150,7 @@ doDrawing win pdata u = do --bindFramebuffer Framebuffer $= fst (_fboLighting pdata) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) createLightMap + cfig pdata lightPoints nWalls @@ -212,6 +224,7 @@ doDrawing win pdata u = do --bindFramebuffer Framebuffer $= fst (_fboLighting pdata) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) createLightMap + cfig pdata lightPoints nWalls @@ -352,3 +365,9 @@ renderTextureWalls pdata nWalls = do glDisable GL_CULL_FACE --cullFace $= Nothing +checkGLError :: IO () +checkGLError = do + err <- glGetError + case err of + 0 -> return () + i -> error $ "OpenGL error: " ++ show i diff --git a/src/Dodge/ScrollValue.hs b/src/Dodge/ScrollValue.hs index f0a9ecbd4..c637f5112 100644 --- a/src/Dodge/ScrollValue.hs +++ b/src/Dodge/ScrollValue.hs @@ -4,6 +4,8 @@ import Dodge.Data.Input import LensHelp updateScrollTestValue :: Input -> Input -updateScrollTestValue theinput = theinput & scrollTestValue +~ theamount +updateScrollTestValue theinput = theinput & scrollTestFloat +~ theamount + & scrollTestInt +~ i where - theamount = fromIntegral (theinput ^. scrollAmount) / 100 + i = theinput ^. scrollAmount + theamount = fromIntegral i / 100 diff --git a/src/Dodge/TestString.hs b/src/Dodge/TestString.hs index 50bc4d42c..51fa5ad69 100644 --- a/src/Dodge/TestString.hs +++ b/src/Dodge/TestString.hs @@ -15,7 +15,9 @@ testStringInit :: Universe -> [String] testStringInit u = [show $ length $ lightsToRender (u ^. uvConfig) (u ^. uvWorld . cWorld . camPos) (u ^. uvWorld . cWorld . lWorld) , show $ length $ fst $ worldSPic (u ^. uvConfig) (u ^. uvWorld) - , show $ length $ snd $ worldSPic (u ^. uvConfig) (u ^. uvWorld) ] + , show $ length $ snd $ worldSPic (u ^. uvConfig) (u ^. uvWorld) + , show $ u ^. uvWorld . input . scrollTestInt + ] --[show $ u ^? uvWorld . hud . hudElement . diSections . sssExtra . sssSelPos . _Just] -- [show $ fmap IM.keys $ u ^? uvWorld . hud . hudElement . subInventory . ciSections . sssSections] diff --git a/src/Framebuffer/Update.hs b/src/Framebuffer/Update.hs index fa7d5fd03..6b34dc815 100644 --- a/src/Framebuffer/Update.hs +++ b/src/Framebuffer/Update.hs @@ -110,9 +110,9 @@ resizeShadowFBO (fbo, (oldto1, oldto2)) x y = do glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) mglDelete glDeleteTextures $ _unTO oldto1 mglDelete glDeleteTextures $ _unTO oldto2 - to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 10 GL_NEAREST GL_NEAREST GL_RGBA8 + to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 20 GL_NEAREST GL_NEAREST GL_RGBA8 to2 <- initializeTexture2DArray - fbo GL_DEPTH_STENCIL_ATTACHMENT x y 10 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8 + fbo GL_DEPTH_STENCIL_ATTACHMENT x y 20 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8 checkFBO fbo return (fbo, (TO to1, TO to2)) diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index fde18438d..21f8e1f98 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -141,15 +141,15 @@ preloadRender = do shadowedgeshader <- makeShaderUsingVAO "shadow/edge" [vert, geom] ELinesAdjacency shEdgeVAO - >>= addUniforms ["lightID"] - -- >>= addUniforms ["lightPos", "radiusUniform","lightID"] shadowcapshader <- makeShaderUsingVAO "shadow/cap" [vert, geom] ETriangles shPosVAO - >>= addUniforms [ "lightID"] - -- >>= addUniforms ["lightPos"] shadowwallshader <- makeShaderUsingVAO "shadow/wallShadow" [vert, geom] EPoints wpVAO - >>= addUniforms ["lightID"] + shadowlightshader <- makeShaderSized "shadow/light" [vert, geom, frag] + [1] 1 + EPoints + shadowcombineshader <- makeShaderSized "shadow/combine" [vert,geom,frag] [1] 1 EPoints + pokeArray (shadVBOptr' shadowlightshader) $ concat cornerListForTriangles -- positional shader positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] ETriangles @@ -181,17 +181,15 @@ preloadRender = do lightingTextureShad <- makeShaderUsingVAO "lighting/texture" [vert, frag] ETriangleStrip fsshadvao >>= addUniforms ["lightPos", "lumRad"] - shadowlightshader <- - makeShaderUsingVAO "shadow/light" [vert, frag] ETriangleStrip fsshadvao -- >>= addUniforms ["lightPos", "lumRad"] - >>= addUniforms ["lightID"] +-- >>= addUniforms ["lightID"] barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] EPoints -- blank wallShader wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] EPoints wpColVAO -- textured wallShader wallTextureShad <- makeShaderUsingVAO "wall/texture" [vert, geom, frag] EPoints wpColVAO - >>= addTexture "data/texture/grayscaleDirt.png" + >>= addSamplerTexture2D "data/texture/grayscaleDirt.png" ---- texture array shader textArrayShad <- makeShader "texture/arrayPos" [vert, frag] [3, 3] ETriangles @@ -254,6 +252,7 @@ preloadRender = do , _shadowCapShader = shadowcapshader , _shadowWallShader = shadowwallshader , _shadowLightShader = shadowlightshader + , _shadowCombineShader = shadowcombineshader , _positionalBlankShader = positionalBlankShad , _wallBlankShader = wallBlankShad , _wallTextureShader = wallTextureShad @@ -292,6 +291,15 @@ cornerList = , [1, 1, 1, 1] , [1, -1, 1, 0] ] +cornerListForTriangles :: [[Float]] +cornerListForTriangles = + [ [-1, 1, 0, 1] + , [-1, -1, 0, 0] + , [1, 1, 1, 1] + , [-1, -1, 0, 0] + , [1, 1, 1, 1] + , [1, -1, 1, 0] + ] cleanUpRenderPreload :: RenderData -> IO () cleanUpRenderPreload pd = do diff --git a/src/Render.hs b/src/Render.hs index 48ad9838e..2552cbf1b 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -7,6 +7,8 @@ module Render ( bindFBO, ) where +import Control.Monad +import Dodge.WindowSize import Control.Lens import Control.Monad.Primitive import Data.Preload.Render @@ -28,6 +30,7 @@ import Shader.ExtraPrimitive -- think of the produced texture as showing what RGB values should be "taken -- away" from the shape colors. createLightMap :: + Configuration -> RenderData -> [(Point3, Float, Point3)] -> -- Lights -- | number of walls @@ -42,8 +45,8 @@ createLightMap :: TO -> (Point3 -> Float -> IO ()) -> -- attempt at drawing shadow not using geo shader IO () -createLightMap pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of - InstancingShads -> instanceLightMap pdata lightPoints nWalls nSils nCaps toPos +createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of + InstancingShads -> instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos _ -> do let llinesShad = _lightingLineShadowShader pdata lcapShad = _lightingCapShader pdata @@ -146,6 +149,7 @@ lightsToArray xs = concat (take 20 $ map t xs ++ repeat [0,0,0,0]) --t (V3 a b c,d,V3 e f g) = [a,b,c,1] instanceLightMap :: + Configuration -> RenderData -> [(Point3, Float, Point3)] -> -- Lights -- | number of walls @@ -157,99 +161,101 @@ instanceLightMap :: -- | the texture object giving positions TO -> IO () -instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do +instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do let llinesShad = _shadowEdgeShader pdata lcapShad = _shadowCapShader pdata lwallShad = _shadowWallShader pdata - --llinesShad = _lightingLineShadowShader pdata - ltextShad = _shadowLightShader pdata + (xsize,ysize) = getWindowSize cfig withArray (lightsToArray lightPoints) $ \ptr -> glNamedBufferSubData (pdata ^. lightsUBO) 0 620 ptr - -- we assume that the renderbuffer's depth has been correctly set elsewhere - -- we will not be changing that here + + forM_ [0..19] $ \i -> glCopyImageSubData + (pdata ^. rboBaseBloom) + GL_RENDERBUFFER + 0 + 0 0 0 + (pdata ^. fboShadow . _2 . _2 . unTO) + GL_TEXTURE_2D_ARRAY 0 0 0 i (fromIntegral xsize) (fromIntegral ysize) + 1 + glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboShadow pdata))) glDepthMask GL_FALSE -- clearColor is specified differently in preloadRender -- the colors are inverted - glClearColor 1 1 1 1 - glClear GL_COLOR_BUFFER_BIT + glClearColor 0 0 0 0 + glClear $ GL_COLOR_BUFFER_BIT + GL_STENCIL_BUFFER_BIT -- for each of the lights: -- 1. stencil out the shadows from this light's point of view -- 2. calculate lighting based on each fragment's position -- to consider: adding normals/a "material" for each fragment - glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR glEnable GL_STENCIL_TEST - --stencilTest $= Enabled glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP - --stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap) - --stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap) glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP - flip VFSM.mapM_ (VFSM.fromList (zip lightPoints [(0::Int)..])) $ \(_,i) -> do - glDepthFunc GL_LESS - -- setup stencil - glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE - glClear GL_STENCIL_BUFFER_BIT - glDisable GL_CULL_FACE - --cullFace $= Nothing - glStencilFunc GL_ALWAYS 0 255 - --draw wall shadows - --currentProgram $= Just (_shadProg lwallShad) - glUseProgram (_shadProg' lwallShad) - --uniform (_shadUnis lwallShad V.! 0) - -- $= Vector3 x y z - --glUniform3f (_shadUnis' lwallShad V.! 0) x y z - glUniform1i (_shadUnis' lwallShad V.! 0) (fromIntegral i) - --bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) - glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) - glDrawArrays - (marshalEPrimitiveMode $ _shadPrim' lwallShad) - 0 - (fromIntegral nWalls) - --draw silhouette shadows - glUseProgram (_shadProg' llinesShad) - glUniform1i (_shadUnis' llinesShad V.! 0) (fromIntegral i) - glBindVertexArray (_vaoName $ _shadVAO' llinesShad) - glDrawElements - (marshalEPrimitiveMode $ _shadPrim' llinesShad) - (fromIntegral nSils) - GL_UNSIGNED_SHORT - nullPtr - --draw caps on the near plane as required - glEnable GL_CULL_FACE - glCullFace GL_BACK - glUseProgram (_shadProg' lcapShad) - --glUniform3f (_shadUnis' lcapShad V.! 0) x y z - glUniform1i (_shadUnis' lcapShad V.! 0) (fromIntegral i) - glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad) - glDrawElements - (marshalEPrimitiveMode $ _shadPrim' lcapShad) - (fromIntegral nCaps) - GL_UNSIGNED_SHORT - nullPtr - --draw lightmap itself - glEnable GL_DEPTH_TEST - glDepthFunc GL_ALWAYS - --depthFunc $= Just Always - -- bind world position texture - bindTO toPos - glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE - --stencilOp $= (OpKeep, OpKeep, OpKeep) - glStencilFunc GL_EQUAL 0 255 - --currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad) - --uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z - --uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad - glUseProgram (ltextShad ^. shadProg') --Just (_shadProg ltextShad) - glUniform1i (_shadUnis' ltextShad V.! 0) $ fromIntegral i - --glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad - --bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad) - glBindVertexArray $ ltextShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad) - glDrawArrays - (marshalEPrimitiveMode (_shadPrim' ltextShad)) - 0 - (fromIntegral (4 :: Int)) - --cleanup: may not be necessary, depending on what comes after... + -- this was a loop + glDepthFunc GL_LESS + -- setup stencil + glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE + glDisable GL_CULL_FACE + glStencilFunc GL_ALWAYS 0 255 + --draw wall shadows + glUseProgram (_shadProg' lwallShad) + glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) +-- glDrawArrays +-- (marshalEPrimitiveMode $ _shadPrim' lwallShad) +-- 0 +-- (fromIntegral nWalls) + --draw silhouette shadows + glUseProgram (_shadProg' llinesShad) + glBindVertexArray (_vaoName $ _shadVAO' llinesShad) +-- glDrawElements +-- (marshalEPrimitiveMode $ _shadPrim' llinesShad) +-- (fromIntegral nSils) +-- GL_UNSIGNED_SHORT +-- nullPtr + --draw caps on the near plane as required + glEnable GL_CULL_FACE + glCullFace GL_BACK + glUseProgram (_shadProg' lcapShad) + glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad) +-- glDrawElements +-- (marshalEPrimitiveMode $ _shadPrim' lcapShad) +-- (fromIntegral nCaps) +-- GL_UNSIGNED_SHORT +-- nullPtr + -- --draw lightmap itself + glEnable GL_DEPTH_TEST + glDepthFunc GL_ALWAYS + glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE + glStencilFunc GL_EQUAL 0 255 + -- delete vvvv + glDisable GL_STENCIL_TEST + -- delete ^^^^ + glUseProgram (pdata ^. shadowLightShader . shadProg') + -- bind world position texture + bindTO toPos + glDisable GL_BLEND + glBindVertexArray $ pdata ^. shadowLightShader . shadVAO' . vaoName + glDrawArrays + (marshalEPrimitiveMode $ pdata ^. shadowLightShader . shadPrim') + 0 + (fromIntegral (4 :: Int)) + + -- this was the end of the loop glDisable GL_CULL_FACE glDisable GL_STENCIL_TEST + --draw to the lighting framebuffer here + glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) + glClearColor 1 1 1 1 + glClear GL_COLOR_BUFFER_BIT + glBindTexture GL_TEXTURE_2D_ARRAY (pdata ^. fboShadow . _2 . _1 . unTO) + glEnable GL_BLEND + glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR + glUseProgram (pdata ^. shadowCombineShader . shadProg') --Just (_shadProg ltextShad) + glDrawArrays + (marshalEPrimitiveMode EPoints) + 0 + 1 + -- assumes that vertices have already been sent to the shader pingPongBetween :: (FBO, TO) -> diff --git a/src/Shader/AuxAddition.hs b/src/Shader/AuxAddition.hs index 167326c6c..b3b556368 100644 --- a/src/Shader/AuxAddition.hs +++ b/src/Shader/AuxAddition.hs @@ -1,5 +1,5 @@ module Shader.AuxAddition - ( addTexture + ( addSamplerTexture2D , vaddTextureNoFilter , addTextureArray , addUniforms @@ -20,8 +20,8 @@ import GLHelp -- I am not sure if this assumes that the shader is constructed directly before -- the texture is added... -addTexture :: String -> FullShader -> IO FullShader -addTexture = addTexture2D 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR +addSamplerTexture2D :: String -> FullShader -> IO FullShader +addSamplerTexture2D = addTexture2D 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR vaddTextureNoFilter :: String -> FullShader -> IO FullShader vaddTextureNoFilter = addTexture2D 1 GL_NEAREST GL_NEAREST