diff --git a/shader/shadow/cap.geom b/shader/shadow/cap.geom index a686a9450..103149ea1 100644 --- a/shader/shadow/cap.geom +++ b/shader/shadow/cap.geom @@ -1,5 +1,6 @@ #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 @@ -7,8 +8,7 @@ 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; // this code is duplicated in lineShadow.geom, should not be changed on its own vec4 projNear (vec4 pos) @@ -35,8 +35,11 @@ void main() { // 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(); } diff --git a/shader/shadow/cap.vert b/shader/shadow/cap.vert index af25261ff..d9bfcbd08 100644 --- a/shader/shadow/cap.vert +++ b/shader/shadow/cap.vert @@ -1,10 +1,6 @@ #version 450 core layout (location = 0) in vec3 position; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; -uniform vec3 lightPos; -uniform vec4 lumRad; -out vec3 dField; -out vec3 lum; void main() { gl_Position = vec4(position,1); diff --git a/shader/shadow/light.frag b/shader/shadow/light.frag index cd16acbcf..d4357591f 100644 --- a/shader/shadow/light.frag +++ b/shader/shadow/light.frag @@ -4,9 +4,9 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -uniform int lightID; -vec3 lightPos = posBool[lightID].xyz; -vec4 lumRad = colRad[lightID]; +//uniform int lightID; +vec3 lightPos = posBool[gl_Layer].xyz; +vec4 lumRad = colRad[gl_Layer]; uniform sampler2D screenTexture; in vec2 gTexPos; out vec4 fColor; @@ -17,6 +17,6 @@ void main() if (dist > lumRad.a) {discard;} float x = 1 - dist / lumRad.a ; vec3 c = (x * x * x) * lumRad.rgb ; - //fColor = vec4(c,0); - fColor = vec4(1,0,0,0); + fColor = vec4(c,0); + //fColor = vec4(0.05,0,0,0); } diff --git a/shader/shadow/light.geom b/shader/shadow/light.geom index f7aaf004d..bfa4c6ff8 100644 --- a/shader/shadow/light.geom +++ b/shader/shadow/light.geom @@ -1,6 +1,6 @@ #version 450 core -layout (triangles) in; -layout (triangle_strip, max_vertices = 3) out; +layout (points) in; +layout (triangle_strip, max_vertices = 4) out; layout (invocations = 20) in; layout (std140, binding = 1) uniform LightsBlock { @@ -8,18 +8,26 @@ layout (std140, binding = 1) uniform LightsBlock 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]; + 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; - gl_Position = gl_in[i].gl_Position; EmitVertex(); - } EndPrimitive(); }else {} } diff --git a/shader/shadow/light.vert b/shader/shadow/light.vert index 51ba3304d..92b639316 100644 --- a/shader/shadow/light.vert +++ b/shader/shadow/light.vert @@ -1,9 +1,4 @@ #version 450 core -layout (location = 0) in vec2 pos; -layout (location = 1) in vec2 texPos; -out vec2 vTexPos; void main() { - gl_Position = vec4(pos,0,1); - vTexPos = texPos; } diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 21f8e1f98..9c2a59697 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -149,7 +149,7 @@ preloadRender = do [1] 1 EPoints shadowcombineshader <- makeShaderSized "shadow/combine" [vert,geom,frag] [1] 1 EPoints - pokeArray (shadVBOptr' shadowlightshader) $ concat cornerListForTriangles + poke (shadVBOptr' shadowlightshader) 1 -- positional shader positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] ETriangles @@ -291,15 +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] - ] +--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 2552cbf1b..201c42d30 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -199,36 +199,33 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do --draw wall shadows glUseProgram (_shadProg' lwallShad) glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) --- glDrawArrays --- (marshalEPrimitiveMode $ _shadPrim' lwallShad) --- 0 --- (fromIntegral nWalls) + 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 + 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 + 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 @@ -237,7 +234,7 @@ instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do glDrawArrays (marshalEPrimitiveMode $ pdata ^. shadowLightShader . shadPrim') 0 - (fromIntegral (4 :: Int)) + 1 -- this was the end of the loop glDisable GL_CULL_FACE