diff --git a/shader/lighting/texture.frag b/shader/lighting/texture.frag new file mode 100644 index 000000000..b7bdec738 --- /dev/null +++ b/shader/lighting/texture.frag @@ -0,0 +1,16 @@ +#version 430 core +uniform vec3 lightPos; +uniform vec4 lumRad; +uniform sampler2D screenTexture; +in vec2 vTexPos; +out vec4 fColor; +void main() +{ + //vec3 dField = ( texture(screenTexture,vTexPos).xyz - lightPos ) / lumRad.a; + //vec3 c = pow (1 - min(1, dot(dField,dField)) , 2) * lumRad.rgb ; + vec3 dField = ( texture(screenTexture,vTexPos).xyz - lightPos ) / lumRad.a; + vec3 c = pow (1 - min(1, dot(dField,dField)) , 2) * lumRad.rgb ; + fColor = vec4(c,0); + //fColor = vec4(lumRad.rgb,0); + //fColor = vec4(1,1,1,0); +} diff --git a/shader/lighting/texture.vert b/shader/lighting/texture.vert new file mode 100644 index 000000000..dc9e41d80 --- /dev/null +++ b/shader/lighting/texture.vert @@ -0,0 +1,9 @@ +#version 430 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/shader/texture/arrayPos.frag b/shader/texture/arrayPos.frag new file mode 100644 index 000000000..703d9e112 --- /dev/null +++ b/shader/texture/arrayPos.frag @@ -0,0 +1,11 @@ +#version 430 core +in vec3 vTexPos; +in vec3 vPos; +layout (location=0) out vec4 fCol; +layout (location=1) out vec4 fPos; +uniform sampler2DArray tilesetSampler; +void main() +{ + fCol = texture(tilesetSampler, vTexPos); + fPos = vec4(vPos,1); +} diff --git a/shader/texture/arrayPos.vert b/shader/texture/arrayPos.vert new file mode 100644 index 000000000..a08a96868 --- /dev/null +++ b/shader/texture/arrayPos.vert @@ -0,0 +1,12 @@ +#version 430 core +layout (location = 0) in vec3 pos; +layout (location = 1) in vec3 texPos; +layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; +out vec3 vTexPos; +out vec3 vPos; +void main() +{ + gl_Position = theMat * vec4(pos,1.0) ; + vTexPos = texPos; + vPos = pos; +} diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index 163605fae..06188df05 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -13,8 +13,8 @@ import Control.Monad.Primitive data RenderData = RenderData { _lightingOccludeShader :: FullShader - , _lightingWallShader :: FullShader - , _lightingSurfaceShader :: FullShader + --, _lightingWallShader :: FullShader + --, _lightingSurfaceShader :: FullShader , _lightingLineShadowShader :: FullShader , _lightingCapShader :: FullShader , _wallBlankShader :: FullShader @@ -22,8 +22,7 @@ data RenderData = RenderData , _textureArrayShader :: FullShader , _fullscreenShader :: FullShader , _fullLightingShader :: FullShader - , _fullscreenAlphaHalveShader :: FullShader - --, _boxBlurShader :: FullShader + --, _fullscreenAlphaHalveShader :: FullShader , _bloomBlurShader :: FullShader , _colorBlurShader :: FullShader , _barrelShader :: FullShader @@ -40,7 +39,6 @@ data RenderData = RenderData , _rboBaseBloom :: RenderbufferObject , _fboLighting :: (FramebufferObject, TextureObject) , _fboLightingHigh :: (FramebufferObject, TextureObject) - --, _rboLighting :: RenderbufferObject , _matUBO :: BufferObject } makeLenses ''RenderData diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index 422a79dba..4ff5bb3d2 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -57,18 +57,14 @@ doDrawing pdata w = do $ --youSil w ++ _foregroundEdgeVerx w - -- poke foreground geometry and floor - let addC (V2 xx yy) = V3 xx yy 0 - nsurfVs <- pokePoint3s (shadVBOptr $ _lightingSurfaceShader pdata) - $ - --youBox w ++ - concatMap polyToGeoRender (foregroundPics w) - ++ polyToTris (map addC $ screenPolygon w) + -- poke foreground geometry for caps + nCaps <- pokePoint3s (shadVBOptr $ _lightingCapShader pdata) + $ concatMap polyToGeoRender (foregroundPics w) -- bind wall points, silhouette data, surface geometry uncurry bindShaderBuffers $ unzip [ ( _wallTextureShader pdata, nWalls) , (_lightingLineShadowShader pdata, nSils) - , (_lightingSurfaceShader pdata, nsurfVs) + , (_lightingCapShader pdata, nCaps) ] -- set the coordinate uniform ready for drawing elements using world coordinates bufferUBO $ perspectiveMatrixb rot camzoom trans wins viewFroms @@ -79,15 +75,9 @@ doDrawing pdata w = do clear [ColorBuffer,DepthBuffer] depthFunc $= Just Less -- draw wall occlusions from the camera's point of view - currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata) - uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata) - $= viewFrom3d currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata) uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) $= viewFrom3d - currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata) - uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata) - $= viewFrom3d drawShader (_lightingOccludeShader pdata) nWalls --draw walls onto base buffer if w ^. config . wall_textured @@ -124,23 +114,29 @@ doDrawing pdata w = do viewport $= (Position 0 0 , divideSize (w ^. config . shadow_resolution) $ Size (round $ fstV2 wins) (round $ sndV2 wins)) --- --- depthMask $= Enabled - -- this is not ideal if the original is not divisible by 2 - bindFramebuffer Framebuffer $= fst (_fboLighting pdata) - createLightMap pdata lightPoints nWalls nSils + createLightMap pdata lightPoints nWalls nSils nCaps colorMask $= Color4 Enabled Enabled Enabled Enabled clearColor $= Color4 0 0 0 0 bindFramebuffer Framebuffer $= fst (_fboColor pdata) - clearColor $= Color4 0 0 0 0 - clear [ColorBuffer] depthFunc $= Just Lequal depthMask $= Disabled - blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(SrcAlpha,One)) + --blendFuncSeparate $= ((OneMinusDstAlpha,OneMinusSrcAlpha),(One,OneMinusSrcAlpha)) + --blendFunc $= (One,OneMinusSrcAlpha) --blendFunc $= (SrcAlpha,One) + --blendFunc $= (SrcAlphaSaturate,One) + --blendFunc $= (SrcAlphaSaturate,OneMinusSrcAlpha) + blendColor $= Color4 1 1 1 0.80 + blendFuncSeparate $= ((SrcAlphaSaturate,One),(ConstantAlpha,ConstantAlpha)) + --blendFunc $= (SrcAlphaSaturate,SrcAlphaSaturate) + clearColor $= Color4 0.5 0.5 0.5 0 + clear [ColorBuffer] + blendFunc $= (SrcAlpha,OneMinusSrcAlpha) + blendFuncSeparate $= ((SrcAlpha,OneMinusSrcAlpha),(One,OneMinusSrcAlpha)) + --blendFuncSeparate $= ((SrcAlphaSaturate,OneMinusSrcAlpha),(One,OneMinusSrcAlpha)) renderLayer 2 shadV layerCounts + renderWindows pdata windowPoints clearColor $= Color4 0 0 0 0 depthMask $= Enabled depthMask $= Disabled @@ -179,7 +175,6 @@ doDrawing pdata w = do textureBinding Texture2D $= Just (snd $ _fboColor pdata) drawShader (_fullscreenShader pdata) 4 --renderLayer 2 shadV layerCounts - renderWindows pdata windowPoints depthFunc $= Just Lequal viewport $= (Position 0 0, Size (round $ fstV2 wins) (round $ sndV2 wins)) diff --git a/src/Dodge/WorldEvent/SpawnParticle.hs b/src/Dodge/WorldEvent/SpawnParticle.hs index 38dbf709d..656a8818d 100644 --- a/src/Dodge/WorldEvent/SpawnParticle.hs +++ b/src/Dodge/WorldEvent/SpawnParticle.hs @@ -281,7 +281,7 @@ makeGasCloud pos vel w = w theCloud = Cloud { _clPos = pos , _clVel = vel - , _clPict = \_ -> setLayer 2 . setDepth 30 $ color (withAlpha 0.1 col) + , _clPict = \_ -> setLayer 2 . setDepth 30 $ color (withAlpha 0.05 col) $ circleSolid 20 , _clRad = 10 , _clTimer = 400 diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index aa4df2cb7..fa4945db7 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -51,18 +51,11 @@ preloadRender = do setupVertexAttribPointer 1 4 8 4 let wpVAO = VAO {_vao = wpVAOname, _vaoVBO = wpVBO} wpColVAO = VAO {_vao = wpColVAOname, _vaoVBO = wpVBO} - -- lighting shaders wsShad <- makeShader "lighting/occlude" [vert,geom,frag] [4] EPoints >>= addUniforms ["lightPos"] - wlLightShad - <- makeShaderUsingShaderVAO "lighting/wall" [vert,geom,frag] EPoints wsShad - >>= addUniforms ["lightPos","lumRad"] - lightingSurfaceShad - <- makeShader "lighting/surface" [vert,frag] [3] ETriangles - >>= addUniforms ["lightPos","lumRad"] lightingCapShad - <- makeShaderUsingShaderVAO "lighting/cap" [vert,geom,frag] ETriangles lightingSurfaceShad + <- makeShader "lighting/cap" [vert,geom,frag] [3] ETriangles >>= addUniforms ["lightPos"] lightingLineShadowShad <- makeShader "lighting/lineShadow" [vert,geom,frag] [3] ELinesAdjacency @@ -77,8 +70,8 @@ preloadRender = do -- this should really be a 2d texture array basicTweakZShad <- makeShader "dualTwoD/basicTweakZ" [vert,frag] [4,4] ETriangles -- fullscreen shaders - fullscreenAlphaHalveShad <- makeShaderSized "fullscreen/alphaHalve" [vert,frag] [2] 4 ETriangleStrip - pokeArray (shadVBOptr fullscreenAlphaHalveShad) $ concat cornerListNoCoord + --fullscreenAlphaHalveShad <- makeShaderSized "fullscreen/alphaHalve" [vert,frag] [2] 4 ETriangleStrip + --pokeArray (shadVBOptr fullscreenAlphaHalveShad) $ concat cornerListNoCoord -- texture shaders, no textures attached fsShad <- makeShaderSized "texture/simple" [vert,frag] [2,2] 4 ETriangleStrip -- note we directly poke the shader vertex data here @@ -100,7 +93,7 @@ preloadRender = do >>= addTextureArray "data/texture/ayene_wooden_floor_transformed.png" -- >>= addTextureArray "data/texture/ayene_wooden_floor.png" -- bind fixed vertex data - bindShaderBuffers [fsShad,fullscreenAlphaHalveShad] [4,4] + bindShaderBuffers [fsShad] [4,4] framebuf2 <- setupTextureFramebuffer 800 600 framebuf3 <- setupTextureFramebuffer 800 600 @@ -141,17 +134,17 @@ preloadRender = do return $ RenderData { _pictureShaders = shadV - , _lightingSurfaceShader = lightingSurfaceShad + --, _lightingSurfaceShader = lightingSurfaceShad , _lightingCapShader = lightingCapShad , _lightingLineShadowShader = lightingLineShadowShad , _lightingOccludeShader = wsShad {_shaderVAO = wpVAO} - , _lightingWallShader = wlLightShad {_shaderVAO = wpVAO} + --, _lightingWallShader = wlLightShad {_shaderVAO = wpVAO} , _wallBlankShader = wlBlank { _shaderVAO = wpColVAO } , _wallTextureShader = wlTexture { _shaderVAO = wpColVAO } , _textureArrayShader = textArrayShad , _fullscreenShader = fsShad , _fullLightingShader = fullLightingShad - , _fullscreenAlphaHalveShader = fullscreenAlphaHalveShad + --, _fullscreenAlphaHalveShader = fullscreenAlphaHalveShad , _bloomBlurShader = bloomBlurShad , _colorBlurShader = colorBlurShad , _barrelShader = barrelShad @@ -178,15 +171,6 @@ cornerList = ,[-1,-1,0,0] ,[ 1,-1,1,0] ] -cornerListNoCoord :: [[Float]] -cornerListNoCoord = - [[-1, 1] - ,[ 1, 1] - ,[-1,-1] - ,[ 1,-1] - ] - - cleanUpRenderPreload :: RenderData -> IO () cleanUpRenderPreload pd = do -- TODO fix this diff --git a/src/Render.hs b/src/Render.hs index 72cdd57a7..955c42a74 100644 --- a/src/Render.hs +++ b/src/Render.hs @@ -36,8 +36,9 @@ createLightMap -> [(Point3,Float,Point3)] -- Lights -> Int -- ^ number of walls -> Int -- ^ number of silhoutte lines to draw + -> Int -- ^ number of "caps" to attempt to draw -> IO () -createLightMap pdata lightPoints nWalls nSils = do +createLightMap pdata lightPoints nWalls nSils nCaps = do -- we assume that the renderbuffer's depth has been correctly set elsewhere -- we will not be changing that here depthMask $= Disabled @@ -74,7 +75,7 @@ createLightMap pdata lightPoints nWalls nSils = do currentProgram $= Just (_shaderProgram $ _lightingCapShader pdata) uniform (head $ _shaderCustomUnis $ _lightingCapShader pdata) $= Vector3 x y z - drawShader (_lightingCapShader pdata) (nSils - 6) + drawShader (_lightingCapShader pdata) nCaps --draw lightmap itself depthFunc $= Just Always cullFace $= Nothing diff --git a/src/Tuple.hs b/src/Tuple.hs new file mode 100644 index 000000000..1471aa373 --- /dev/null +++ b/src/Tuple.hs @@ -0,0 +1,16 @@ +module Tuple + ( trip1 + , trip2 + , trip3 + ) + where + +trip1 :: (a,b,c) -> a +{-# INLINE trip1 #-} +trip1 (x,_,_) = x +trip2 :: (a,b,c) -> b +{-# INLINE trip2 #-} +trip2 (_,x,_) = x +trip3 :: (a,b,c) -> c +{-# INLINE trip3 #-} +trip3 (_,_,x) = x