diff --git a/shader/shadow/cap.geom b/shader/shadow/cap.geom index 9d40db36c..3e5fdaa7d 100644 --- a/shader/shadow/cap.geom +++ b/shader/shadow/cap.geom @@ -2,13 +2,13 @@ layout (triangles) 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]; -//} ; -uniform vec3 lightPos; +layout (std140, binding = 1) uniform LightsBlock +{ + vec4 posBool[20]; + vec4 colRad[20]; +} ; uniform int lightID; +vec3 lightPos = posBool[lightID].xyz ; // this code is duplicated in lineShadow.geom, should not be changed on its own vec4 projNear (vec4 pos) { diff --git a/shader/shadow/edge.geom b/shader/shadow/edge.geom index bd71be625..af9aa0c80 100644 --- a/shader/shadow/edge.geom +++ b/shader/shadow/edge.geom @@ -7,11 +7,8 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -//uniform vec3 lightPos; -//uniform float radiusUniform; uniform int lightID; vec3 lightPos1 = posBool[lightID].xyz; -//vec3 lightPos1 = lightPos; float theBool = posBool[lightID].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));} ; diff --git a/shader/shadow/light.frag b/shader/shadow/light.frag index 99c590a39..545bf4bca 100644 --- a/shader/shadow/light.frag +++ b/shader/shadow/light.frag @@ -4,8 +4,9 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -uniform vec3 lightPos; -uniform vec4 lumRad; +uniform int lightID; +vec3 lightPos = posBool[lightID].xyz; +vec4 lumRad = colRad[lightID]; uniform sampler2D screenTexture; in vec2 vTexPos; out vec4 fColor; diff --git a/shader/shadow/wallShadow.geom b/shader/shadow/wallShadow.geom index 9a95f4418..85e4f8863 100644 --- a/shader/shadow/wallShadow.geom +++ b/shader/shadow/wallShadow.geom @@ -7,8 +7,8 @@ layout (std140, binding = 1) uniform LightsBlock vec4 posBool[20]; vec4 colRad[20]; } ; -uniform vec3 lightPos; uniform int lightID; +vec3 lightPos = posBool[lightID].xyz; vec4 shift (vec4 p) { return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0 , 1); } diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 614f60ffc..fde18438d 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -145,11 +145,11 @@ preloadRender = do -- >>= addUniforms ["lightPos", "radiusUniform","lightID"] shadowcapshader <- makeShaderUsingVAO "shadow/cap" [vert, geom] ETriangles shPosVAO - >>= addUniforms ["lightPos", "lightID"] + >>= addUniforms [ "lightID"] -- >>= addUniforms ["lightPos"] shadowwallshader <- makeShaderUsingVAO "shadow/wallShadow" [vert, geom] EPoints wpVAO - >>= addUniforms ["lightPos","lightID"] + >>= addUniforms ["lightID"] -- positional shader positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] ETriangles @@ -183,7 +183,8 @@ preloadRender = do >>= addUniforms ["lightPos", "lumRad"] shadowlightshader <- makeShaderUsingVAO "shadow/light" [vert, frag] ETriangleStrip fsshadvao - >>= addUniforms ["lightPos", "lumRad"] + -- >>= addUniforms ["lightPos", "lumRad"] + >>= 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 diff --git a/src/Render.hs b/src/Render.hs index c6ab0169f..48ad9838e 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -183,7 +183,7 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do --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)..])) $ \((V3 x y z, rad, V3 r g b),i) -> do + 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 @@ -196,8 +196,8 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do glUseProgram (_shadProg' lwallShad) --uniform (_shadUnis lwallShad V.! 0) -- $= Vector3 x y z - glUniform3f (_shadUnis' lwallShad V.! 0) x y z - glUniform1i (_shadUnis' lwallShad V.! 1) (fromIntegral i) + --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 @@ -217,8 +217,8 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do glEnable GL_CULL_FACE glCullFace GL_BACK glUseProgram (_shadProg' lcapShad) - glUniform3f (_shadUnis' lcapShad V.! 0) x y z - glUniform1i (_shadUnis' lcapShad V.! 1) (fromIntegral i) + --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) @@ -238,8 +238,8 @@ instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do --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) - glUniform3f (_shadUnis' ltextShad V.! 0) x y z - glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad + 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