diff --git a/shader/shadow/cap.geom b/shader/shadow/cap.geom deleted file mode 100644 index 6614bb1d5..000000000 --- a/shader/shadow/cap.geom +++ /dev/null @@ -1,47 +0,0 @@ -#version 450 core -layout (triangles) in; -layout (invocations = 20) in; -layout (triangle_strip, max_vertices = 3) out; -layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -layout (std140, binding = 1) uniform LightsBlock -{ - vec4 posBool[20]; - vec4 colRad[20]; -} ; -vec3 lightPos = posBool[gl_InvocationID].xyz ; -float theBool = posBool[gl_InvocationID].w; -// this code is duplicated in shadow/edge.geom, should not be changed on its own -vec4 projNear (vec4 pos) -{ - // note we project to a specific height - // this is quite brittle, not ideal - vec3 dir = pos.xyz - lightPos ; - float a = (100 - pos.z) / dir.z ; - vec2 xy = (pos.xyz + a * dir).xy ; - return vec4 ( xy, 100 , 1) ; -} -void main() -{ - vec4 p0 = gl_in[0].gl_Position ; - vec4 p1 = gl_in[1].gl_Position ; - vec4 p2 = gl_in[2].gl_Position ; - if ( //if Light Source is below all vertices, draw cap - // TODO think about when LS is beside the object - ( p0.z - lightPos.z > 0 ) - && ( p1.z - lightPos.z > 0 ) - && ( p2.z - lightPos.z > 0 ) - && theBool == 1 - ) - { - // the front cap - vec4 v1 = vec4 (0,0,1,0) ; - gl_Layer = gl_InvocationID; - gl_Position = theMat * projNear(p0); EmitVertex(); - gl_Layer = gl_InvocationID; - gl_Position = theMat * projNear(p1); EmitVertex(); - gl_Layer = gl_InvocationID; - gl_Position = theMat * projNear(p2); EmitVertex(); - EndPrimitive(); - } - else {} -} diff --git a/shader/shadow/cap.vert b/shader/shadow/cap.vert deleted file mode 100644 index d9bfcbd08..000000000 --- a/shader/shadow/cap.vert +++ /dev/null @@ -1,7 +0,0 @@ -#version 450 core -layout (location = 0) in vec3 position; -layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -void main() -{ - gl_Position = vec4(position,1); -} diff --git a/shader/shadow/combine.frag b/shader/shadow/combine.frag deleted file mode 100644 index 2544b52d9..000000000 --- a/shader/shadow/combine.frag +++ /dev/null @@ -1,9 +0,0 @@ -#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 deleted file mode 100644 index 137f7612f..000000000 --- a/shader/shadow/combine.geom +++ /dev/null @@ -1,30 +0,0 @@ -#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 deleted file mode 100644 index 92b639316..000000000 --- a/shader/shadow/combine.vert +++ /dev/null @@ -1,4 +0,0 @@ -#version 450 core -void main() -{ -} diff --git a/shader/shadow/edge.geom b/shader/shadow/edge.geom deleted file mode 100644 index 6bc64ff6e..000000000 --- a/shader/shadow/edge.geom +++ /dev/null @@ -1,85 +0,0 @@ -#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 { - vec4 posBool[20]; - vec4 colRad[20]; -}; -vec3 lightPos = posBool[gl_InvocationID].xyz; -float theBool = posBool[gl_InvocationID].w; -float rad = colRad[gl_InvocationID].w; -vec4 shift(vec4 p) { return (vec4(p.xyz + (100000 * (p.xyz - lightPos)), 1)); }; -vec4 shiftBy(float x, vec4 p) { - return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1)); -}; -vec4 shift1(vec4 p) { - return (vec4(lightPos + (rad * normalize(p.xyz - lightPos)), 1)); -}; -// copied from shadow/cap.geom, should not be changed on its own -vec4 projNear(vec4 pos) { - // note we project to a specific height - // this is quite brittle, not ideal - vec3 dir = pos.xyz - lightPos; - float a = (100 - pos.z) / dir.z; - vec2 xy = (pos.xyz + a * dir).xy; - return vec4(xy, 100, 1); -}; -vec4 shiftNear(vec4 pos) { - vec4 sp = shift(pos); - if (sp.z > 100) { - return projNear(pos); - } else { - return sp; - } -}; -void main() { - if (theBool == 1) { - vec4 p0 = gl_in[0].gl_Position; - vec4 p1 = gl_in[1].gl_Position; - vec4 mid = 0.5 * (p0 + p1); - vec3 n0a = gl_in[2].gl_Position.xyz; - vec3 n1a = gl_in[3].gl_Position.xyz; - vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz); - vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz); - vec3 lightDir = p0.xyz - lightPos.xyz; - vec3 lightDir2 = p1.xyz - lightPos.xyz; - // test if the edge is part of the silhouette - // that is, if the normals of the faces connected by the edge point are in - // "different directions" wrt the light direction - if (dot(n0, lightDir) * dot(n1, lightDir) <= 0 && - (dot(lightDir, lightDir) < rad * rad || - dot(lightDir2, lightDir2) < rad * rad)) - // using <= rather than < seems to get rid of overlapping shadow - // artefacts - { - vec4 p2 = shiftNear(p0); - vec4 p3 = shiftNear(p1); - gl_Position = theMat * p0; - gl_Layer = gl_InvocationID; - EmitVertex(); - if (dot(n0, lightDir) > 0) { - gl_Position = theMat * p1; - gl_Layer = gl_InvocationID; - EmitVertex(); - gl_Position = theMat * p2; - gl_Layer = gl_InvocationID; - EmitVertex(); - } else { - gl_Position = theMat * p2; - gl_Layer = gl_InvocationID; - EmitVertex(); - gl_Position = theMat * p1; - gl_Layer = gl_InvocationID; - EmitVertex(); - } - gl_Position = theMat * p3; - gl_Layer = gl_InvocationID; - EmitVertex(); - EndPrimitive(); - } else { - } - } else { - } -} diff --git a/shader/shadow/edge.vert b/shader/shadow/edge.vert deleted file mode 100644 index 42d10dba1..000000000 --- a/shader/shadow/edge.vert +++ /dev/null @@ -1,6 +0,0 @@ -#version 450 core -layout (location = 0) in vec3 pos; -void main() -{ - gl_Position = vec4(pos,1); -} diff --git a/shader/shadow/light.frag b/shader/shadow/light.frag deleted file mode 100644 index 6b38fe6ed..000000000 --- a/shader/shadow/light.frag +++ /dev/null @@ -1,36 +0,0 @@ -#version 450 core -layout (std140, binding = 1) uniform LightsBlock -{ - vec4 posBool[20]; - vec4 colRad[20]; -} ; -//uniform int lightID; -vec3 lightPos = posBool[gl_Layer].xyz; -vec4 lumRad = colRad[gl_Layer]; -layout (binding = 0) uniform sampler2D screenTexture; -layout (binding = 1) uniform sampler2D normals; -in vec2 gTexPos; -out vec4 fColor; -void main() -{ -float rad = lumRad.a; - 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(0.05,0,0,0); - vec4 normbit = texture(normals, gTexPos); - vec3 norm = normbit.xyz; - float y1 = dot(normalize(norm), normalize(distVec)); - float y2 = float(y1 > 0 ? 1 : 0); - //float y3 = clamp(0.5 * (y1 + 1),0,1) ; - float y3 = clamp(2*y1 + 1,0,1) ; - //float y3 = clamp(0.5 * (y1 + 2),0,1) ; - //float y = float(normbit.w == 0 ? y3 : y2); - float y = y2; - float x = 1 - dist / rad; - vec3 c = y* (x * x * x) * lumRad.rgb; - fColor = vec4(c, 1); -} diff --git a/shader/shadow/light.geom b/shader/shadow/light.geom deleted file mode 100644 index bfa4c6ff8..000000000 --- a/shader/shadow/light.geom +++ /dev/null @@ -1,33 +0,0 @@ -#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]; -} ; -float theBool = posBool[gl_InvocationID].w; -out vec2 gTexPos; -void main() -{ - if (theBool == 1){ - gTexPos = vec2(0,1); - gl_Position = vec4(-1,1,0,1) ; - gl_Layer = gl_InvocationID; - EmitVertex(); - gTexPos = vec2(0,0); - gl_Position = vec4(-1,-1,0,1) ; - gl_Layer = gl_InvocationID; - EmitVertex(); - gTexPos = vec2(1,1); - gl_Position = vec4(1,1,0,1) ; - gl_Layer = gl_InvocationID; - EmitVertex(); - gTexPos = vec2(1,0); - gl_Position = vec4(1,-1,0,1) ; - gl_Layer = gl_InvocationID; - EmitVertex(); - EndPrimitive(); - }else {} -} diff --git a/shader/shadow/light.vert b/shader/shadow/light.vert deleted file mode 100644 index 92b639316..000000000 --- a/shader/shadow/light.vert +++ /dev/null @@ -1,4 +0,0 @@ -#version 450 core -void main() -{ -} diff --git a/shader/shadow/wallShadow.geom b/shader/shadow/wallShadow.geom deleted file mode 100644 index 81f640e8f..000000000 --- a/shader/shadow/wallShadow.geom +++ /dev/null @@ -1,78 +0,0 @@ -#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 { - vec4 posBool[20]; - vec4 colRad[20]; -}; -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); } -float isLHS(vec2 startV, vec2 testV) { - return sign(-startV.x * testV.y + startV.y * testV.x); -} -// Preprocessed to include ../functions.glsl -float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) { - return dot(p - a,b-a) / dot(b-a,b-a); -} -vec2 closestPointOnSeg (vec2 a,vec2 b, vec2 p) { - float x = closestPointOnLineParam(a,b,p); - if (x < 0) { - return a; - } else{ if (x > 1) { return b; } - { return a + (x * (b- a));} - } -} -// End include 2023-03-13 15:33:44.454374887 UTC -// construct a box with openings on bottom face and face away from wall -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 (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); - vec4 p5 = shift(p1); - vec4 p6 = shift(p2); - vec4 p7 = vec4(p6.xy, 100, 1); - vec4 p8 = vec4(p5.xy, 100, 1); - - vec4 a1 = theMat * p1; - vec4 a2 = theMat * p2; - vec4 a3 = theMat * p3; - vec4 a4 = theMat * p4; - vec4 a5 = theMat * p5; - vec4 a6 = theMat * p6; - vec4 a7 = theMat * p7; - vec4 a8 = theMat * p8; - - 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/shader/shadow/wallShadow.vert b/shader/shadow/wallShadow.vert deleted file mode 100644 index ffb827dbb..000000000 --- a/shader/shadow/wallShadow.vert +++ /dev/null @@ -1,6 +0,0 @@ -#version 450 core -layout (location = 0) in vec4 poss; -void main() -{ - gl_Position = poss; -} diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index ab6a2d182..5a7c679d0 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -16,11 +16,6 @@ data RenderData = RenderData , _lightingCapShader :: Shader , _lightingTextureShader :: Shader , _alphaDivideShader :: Shader - , _shadowEdgeShader :: Shader - , _shadowCapShader :: Shader - , _shadowWallShader :: Shader - , _shadowLightShader :: Shader - , _shadowCombineShader :: Shader , _windowShader :: Shader , _fullscreenShader :: Shader , _bloomBlurShader :: Shader diff --git a/src/Dodge/Data/Config.hs b/src/Dodge/Data/Config.hs index a822127e7..1b52f1516 100644 --- a/src/Dodge/Data/Config.hs +++ b/src/Dodge/Data/Config.hs @@ -96,11 +96,9 @@ data ResFactor = DoubleRes | FullRes | HalfRes | QuarterRes | EighthRes | Sixtee data ShadowRendering = GeoObjShads - | InstancingShads | NoObjShads | NoShadows | NoLighting - | ComputeShader deriving (Show, Eq, Ord, Enum, Bounded) data RoomClipping = NoRoomClipBoundaries | AllRoomClipBoundaries | IntersectingRoomClipBoundaries diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index f11756b66..8ba52be29 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -95,21 +95,6 @@ preloadRender = do makeShaderUsingVAO "lighting/cap" [vert, geom] pmTriangles shPosVAO lightingLineShadowShad <- makeShaderUsingVAO "lighting/lineShadow" [vert, geom] pmLinesAdjacency shedgevao - shadowedgeshader <- - makeShaderUsingVAO "shadow/edge" [vert, geom] pmLinesAdjacency shedgevao - shadowcapshader <- - makeShaderUsingVAO "shadow/cap" [vert, geom] pmTriangles shPosVAO - shadowwallshader <- - makeShaderUsingVBO "shadow/wallShadow" [vert, geom] (toFloatVAs [4]) pmPoints wallvbo - shadowlightshader <- - makeStaticShader - "shadow/light" - [vert, geom, frag] - [VertexAttribute 1 GL_BYTE GL_FALSE 0] - ([1] :: [GLbyte]) - pmPoints - shadowcombineshader <- makeShaderUsingVAO "shadow/combine" [vert, geom, frag] pmPoints - (shadowlightshader ^. shaderVAO) putStrLn "Setup 2D shaders" bslist <- makeShaderVBO "dualTwoD/basic" [vert, frag] (toFloatVAs [3, 4]) pmTriangles @@ -193,11 +178,6 @@ preloadRender = do , _lightingCapShader = lightingCapShad , _lightingLineShadowShader = lightingLineShadowShad , _lightingWallShadShader = lightingWallShadShad - , _shadowEdgeShader = shadowedgeshader - , _shadowCapShader = shadowcapshader - , _shadowWallShader = shadowwallshader - , _shadowLightShader = shadowlightshader - , _shadowCombineShader = shadowcombineshader , _windowShader = windowshader , _fullscreenShader = fsShad , _alphaDivideShader = alphadivideshader diff --git a/src/Render.hs b/src/Render.hs index dde92c525..d26380d75 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -6,14 +6,12 @@ module Render ( ) where import Control.Lens -import Control.Monad import Control.Monad.Primitive import Data.Preload.Render import qualified Data.Vector.Fusion.Stream.Monadic as VFSM import qualified Data.Vector.Mutable as MV import qualified Data.Vector.Unboxed.Mutable as UMV import Dodge.Data.Config -import Dodge.WindowSize import Foreign hiding (rotate) import Geometry.Data import Graphics.GL.Core45 @@ -41,7 +39,6 @@ createLightMap :: RenderData -> IO () createLightMap cfig = case shadrendertype of - InstancingShads -> instanceLightMap cfig NoShadows -> const . const . const renderLightingNoShadows NoLighting -> const . const . const . const . const . const renderFlatLighting _ -> renderShadows shadrendertype @@ -219,136 +216,6 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li glDisable GL_STENCIL_TEST glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE -lightsToArray :: [(Point3, Float, Point3)] -> [Float] -lightsToArray xs = - concat (take 20 $ map t xs ++ repeat [0, 0, 0, 0]) - ++ concat (take 20 $ map s xs ++ repeat [0, 0, 0, 0]) - where - t (V3 a b c, _, _) = [a, b, c, 1] - s (_, d, V3 e f g) = [e, f, g, d] - -instanceLightMap :: - Configuration -> - -- | number of walls - GLsizei -> - -- | number of silhoutte lines to draw - Int -> - -- | number of "caps" to attempt to draw - Int -> - -- | the texture object giving positions - TO -> - TO -> - [(Point3, Float, Point3)] -> -- Lights - RenderData -> - IO () -instanceLightMap cfig nWalls nSils nCaps toPos tanormals lightPoints pdata = do - let lcapShad = _shadowCapShader pdata - (xsize, ysize) = getWindowSize _graphics_world_resolution cfig - withArray (lightsToArray lightPoints) $ \ptr -> - glNamedBufferSubData (pdata ^. lightsUBO) 0 620 ptr - 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 - xsize - ysize - 1 - glBindFramebuffer GL_FRAMEBUFFER $ pdata ^. fboShadow . _1 . unFBO - glDepthMask GL_FALSE - withArray [0, 0, 0, 0] $ \ptr -> - glClearNamedFramebufferfv - (pdata ^. fboShadow . _1 . unFBO) - GL_COLOR - 0 - ptr - with 0 $ \ptr -> - glClearNamedFramebufferiv - (pdata ^. fboShadow . _1 . unFBO) - GL_STENCIL - 0 - ptr - -- stencil out the shadows from each light's point of view - -- setup stencil - glEnable GL_STENCIL_TEST - glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP - glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP - glDepthFunc GL_LESS - glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE - glDisable GL_BLEND - glDisable GL_CULL_FACE - glStencilFunc GL_ALWAYS 0 255 - --draw wall shadows - glUseProgram $ pdata ^. shadowWallShader . shaderUINT - glBindVertexArray $ pdata ^. shadowWallShader . shaderVAO . vaoName - glDrawArrays - (_unPrimitiveMode $ pdata ^. shadowWallShader . shaderPrimitive) - 0 - nWalls - --draw silhouette shadows - glUseProgram $ pdata ^. shadowEdgeShader . shaderUINT - glBindVertexArray $ pdata ^. shadowEdgeShader . shaderVAO . vaoName - glDrawElements - (_unPrimitiveMode $ pdata ^. shadowEdgeShader . shaderPrimitive) - (fromIntegral nSils) - GL_UNSIGNED_SHORT - nullPtr - --draw caps on the near plane as required - glEnable GL_CULL_FACE - glCullFace GL_BACK - --glCullFace GL_FRONT - glUseProgram (_shaderUINT lcapShad) - glBindVertexArray $ lcapShad ^. shaderVAO . vaoName - glDrawElements - (_unPrimitiveMode $ _shaderPrimitive lcapShad) - (fromIntegral nCaps) - GL_UNSIGNED_SHORT - nullPtr - --draw lightmap itself - glDepthFunc GL_ALWAYS - glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE - glStencilFunc GL_EQUAL 0 255 - glUseProgram (pdata ^. shadowLightShader . shaderUINT) - -- bind world position texture - glBindTextureUnit 0 (toPos ^. unTO) - glBindTextureUnit 1 (tanormals ^. unTO) - glDrawArrays - (_unPrimitiveMode $ pdata ^. shadowLightShader . shaderPrimitive) - 0 - 1 - glDisable GL_CULL_FACE - glDisable GL_STENCIL_TEST - --draw to the lighting framebuffer here - glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) - withArray [1, 1, 1, 1] $ \ptr -> - glClearNamedFramebufferfv - (pdata ^. fboLighting . _1 . unFBO) - GL_COLOR - 0 - ptr - glBindTextureUnit 0 (pdata ^. fboShadow . _2 . _1 . unTO) - glEnable GL_BLEND - glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR - glUseProgram (pdata ^. shadowCombineShader . shaderUINT) - glDrawArrays - GL_POINTS - 0 - 1 - withArray [GL_COLOR_ATTACHMENT0, GL_DEPTH_STENCIL_ATTACHMENT] $ \ptr -> - glInvalidateNamedFramebufferData - (pdata ^. fboShadow . _1 . unFBO) - 2 - ptr - -- assumes that vertices have already been sent to the shader pingPongBetween :: (FBO, TO) ->