diff --git a/shader/wallFace.frag b/shader/wallFace.frag new file mode 100644 index 000000000..a4e0a29a7 --- /dev/null +++ b/shader/wallFace.frag @@ -0,0 +1,12 @@ +#version 430 core +in vec2 tPos; +in vec4 gColor; + +uniform sampler2D tex; + +out vec4 fColor; + +void main() +{ + fColor = gColor * texture(tex,tPos); +} diff --git a/shader/wallFace.geom b/shader/wallFace.geom new file mode 100644 index 000000000..7f2cc9b7d --- /dev/null +++ b/shader/wallFace.geom @@ -0,0 +1,36 @@ +#version 430 core +layout (points) in; +layout (triangle_strip, max_vertices = 4) out; + +in vec4 vColor []; +out vec4 gColor; +out vec2 tPos; + +uniform mat4 perpMat; + +// consider using isLHS to check if the wall is facing the center +float isLHS (vec2 startV, vec2 testV) +{ + return sign( -startV.x * testV.y + startV.y * testV.x); +} + +void main() +{ + gColor = vColor[0]; + +vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); +vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); +vec4 p3 = vec4 (p1.xy,-0.5,1); +vec4 p4 = vec4 (p2.xy,-0.5,1); + +vec4 a1 = perpMat * p1; +vec4 a2 = perpMat * p2; +vec4 a3 = perpMat * p3; +vec4 a4 = perpMat * p4; + + tPos = vec2 ( 1,-1) ; gl_Position = a1; EmitVertex(); + tPos = vec2 ( 1, 1) ; gl_Position = a3; EmitVertex(); + tPos = vec2 (-1,-1) ; gl_Position = a2; EmitVertex(); + tPos = vec2 (-1, 1) ; gl_Position = a4; EmitVertex(); + EndPrimitive(); +} diff --git a/shader/wallFace.vert b/shader/wallFace.vert new file mode 100644 index 000000000..0456509f9 --- /dev/null +++ b/shader/wallFace.vert @@ -0,0 +1,11 @@ +#version 430 core +layout (location = 0) in vec4 poss; +layout (location = 1) in vec4 color; + +out vec4 vColor; + +void main() +{ + gl_Position = poss; + vColor = color; +} diff --git a/shader/wallFace.vet b/shader/wallFace.vet new file mode 100644 index 000000000..0456509f9 --- /dev/null +++ b/shader/wallFace.vet @@ -0,0 +1,11 @@ +#version 430 core +layout (location = 0) in vec4 poss; +layout (location = 1) in vec4 color; + +out vec4 vColor; + +void main() +{ + gl_Position = poss; + vColor = color; +} diff --git a/src/Picture/Render.hs b/src/Picture/Render.hs index 106b19b9c..5fd2ea0be 100644 --- a/src/Picture/Render.hs +++ b/src/Picture/Render.hs @@ -31,19 +31,8 @@ import qualified Data.IntMap.Strict as IM import qualified SDL as SDL -renderPicture' :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> - [(Point2,Point2)] -> [Point4] -> - (Float,Float) -> Picture -> IO (Word32,Word32) -renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints - (viewFromx,viewFromy) pic = do - wallPokeStart <- SDL.ticks - --- setting the depth function to less, instead of lequal, --- seems to stop a lot of unecessary drawing --- of wall shadows when creating the light map - depthFunc $= Just Less - --- set common uniforms +setCommonUniforms :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> IO () +setCommonUniforms pdata rot zoom (tranx,trany) (winx,winy) = do setShaderUniforms rot zoom (tranx,trany) (winx,winy) ( (extractProgAndUnis $ _lightSourceShader pdata) : (extractProgAndUnis $ _wallShadowShader pdata) @@ -52,6 +41,36 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints : (map extractProgAndUnis $ _listShaders pdata) ) +createLightMap :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> + [(Point2,Point2)] -> [Point4] -> + (Float,Float) -> Picture -> IO () +createLightMap pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints + (viewFromx,viewFromy) pic = do + return () + +renderPicture' :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> + [(Point2,Point2)] -> [Point4] -> + (Float,Float) -> Picture -> IO (Word32,Word32) +renderPicture' pdata rot zoom trans wins wallPoints lightPoints + viewFroms pic = do + startTicks <- SDL.ticks + setCommonUniforms pdata rot zoom trans wins + renderPicture pdata rot zoom trans wins wallPoints lightPoints viewFroms pic + endTicks <- SDL.ticks + return (startTicks, endTicks - startTicks) + +renderPicture :: RenderData -> Float -> Float -> (Float,Float) -> (Float,Float) -> + [(Point2,Point2)] -> [Point4] -> + (Float,Float) -> Picture -> IO (Word32,Word32) +renderPicture pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints + (viewFromx,viewFromy) pic = do + wallPokeStart <- SDL.ticks + +-- setting the depth function to less, instead of lequal, +-- seems to stop a lot of unecessary drawing +-- of wall shadows when creating the light map + depthFunc $= Just Less + -- draw lightmap bindFramebuffer Framebuffer $= (_spareFBO pdata)