diff --git a/data/normalMaps/checkerboard.png b/data/normalMaps/checkerboard.png new file mode 100644 index 000000000..9df11ce2f Binary files /dev/null and b/data/normalMaps/checkerboard.png differ diff --git a/data/normalMaps/floorboardPattern.png b/data/normalMaps/floorboardPattern.png new file mode 100644 index 000000000..1469a323d Binary files /dev/null and b/data/normalMaps/floorboardPattern.png differ diff --git a/data/normalMaps/floorboardPatternThin.png b/data/normalMaps/floorboardPatternThin.png new file mode 100644 index 000000000..9af9a67bf Binary files /dev/null and b/data/normalMaps/floorboardPatternThin.png differ diff --git a/data/normalMaps/squaresPattern.png b/data/normalMaps/squaresPattern.png new file mode 100644 index 000000000..3f6cd2ad2 Binary files /dev/null and b/data/normalMaps/squaresPattern.png differ diff --git a/data/normalMaps/verticalRidge.png b/data/normalMaps/verticalRidge.png new file mode 100644 index 000000000..cff82632c Binary files /dev/null and b/data/normalMaps/verticalRidge.png differ diff --git a/data/texture/ayene_wooden_floor_transformed.png b/data/texture/ayene_wooden_floor_transformed.png index 2d918d980..7b9dc752f 100644 Binary files a/data/texture/ayene_wooden_floor_transformed.png and b/data/texture/ayene_wooden_floor_transformed.png differ diff --git a/shader/lighting/texture.frag b/shader/lighting/texture.frag index 97a1ee072..ce61d93b5 100644 --- a/shader/lighting/texture.frag +++ b/shader/lighting/texture.frag @@ -11,8 +11,11 @@ void main() { vec3 distVec = pos - lightPos; vec4 normbit = texture(normals, vTexPos); vec3 norm = normbit.xyz - pos; - float y1 = float(normbit.w == 0 ? 1 : dot(normalize(norm), normalize(distVec))); - float y = float(y1 > 0 ? 1 : 0); + float y1 = dot(normalize(norm), normalize(distVec)); + float y2 = float(y1 > 0 ? 1 : 0); + //float y = y2; + float y3 = clamp(0.5 * (y1 + 1),0,1) ; + float y = float(normbit.w == 0 ? y2 : y2); float dist = dot(distVec, distVec); if (dist > rad) { discard; diff --git a/shader/texture/arrayPos.frag b/shader/texture/arrayPos.frag index e0adc5ba2..9b5731767 100644 --- a/shader/texture/arrayPos.frag +++ b/shader/texture/arrayPos.frag @@ -4,11 +4,13 @@ in vec3 vPos; layout (location=0) out vec4 fCol; layout (location=1) out vec4 fPos; layout (location=2) out vec4 normal; -uniform sampler2DArray tilesetSampler; +layout (binding=0) uniform sampler2DArray tilesetSampler; +layout (binding=1) uniform sampler2D normalSampler; void main() { - fCol = texture(tilesetSampler, vTexPos); + //fCol = texture(tilesetSampler, vec3(0.3,0.1,0) + vTexPos); + fCol = vec4(0.2,0.3,0.6,1); + //fCol = vec4(0.6,0.4,0.3,1); fPos = vec4(vPos,1); - //normal = vec4(vPos.xy,vPos.z-1,1); - normal = vec4(vPos.xy,vPos.z-1,1); + normal = vec4(vPos + vec3(0.5) - texture(normalSampler,2*vTexPos.xy).xyz,0); } diff --git a/shader/wall/texture.geom b/shader/wall/texture.geom index b70fcc5a5..5699bc0a0 100644 --- a/shader/wall/texture.geom +++ b/shader/wall/texture.geom @@ -17,7 +17,7 @@ void main() vec4 p3 = vec4 (p1.xy,100,1); vec4 p4 = vec4 (p2.xy,100,1); vec2 d = vec2(p1.xy - p2.xy); - vec4 norm = vec4( d.y, -d.x, 0, 1); + vec4 norm = vec4( d.y, -d.x, 0, 0); gNorm = p1 - norm; gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = vec4(theMat * p1); EmitVertex(); gNorm = p1 - norm; diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index db3a52a9d..12f3fc969 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -56,6 +56,7 @@ data RenderData = RenderData , _vboWalls :: VBO , _vboWindows :: VBO , _vboShapes :: VBO + , _toNormalMaps :: TO } makeLenses ''RenderData diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index fb830b13a..485745ca9 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -160,7 +160,16 @@ doDrawing' win pdata u = do nullPtr -- glDisable GL_CULL_FACE --draw floor onto base buffer - drawShader (fst $ _textureArrayShader pdata) nFls + glDisable GL_BLEND + glUseProgram (pdata ^. textureArrayShader . _1 . shadName) + glBindVertexArray $ pdata ^. textureArrayShader . _1 . shadVAO . vaoName + glBindTextureUnit 1 (pdata ^. toNormalMaps . unTO) + glBindTextureUnit 0 $ pdata ^?! textureArrayShader . _1 . shadTex' . _Just . textureObject + glDrawArrays + (marshalEPrimitiveMode $ pdata ^. textureArrayShader . _1 . shadPrim' ) + 0 + (fromIntegral nFls) + glEnable GL_BLEND --draw lightmap into its own buffer createLightMap cfig diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index 42a80a6f2..b5eb7569f 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -5,6 +5,7 @@ module Preload.Render ( cleanUpRenderPreload, ) where +import Shader.AuxAddition import Shape.Data import Geometry.Data import MatrixHelper @@ -16,7 +17,6 @@ import qualified Data.Vector.Mutable as MV import Foreign import Framebuffer.Setup import Shader -import Shader.AuxAddition import Shader.Bind import Shader.Compile import Shader.Data @@ -145,9 +145,6 @@ preloadRender = do >>= _1 (vaddTextureNoFilter "data/texture/charMap.png") -- 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 -- texture shaders, no textures attached fsShad <- makeShaderSized "texture/simple" [vert, frag] [2, 2] 4 ETriangleStrip -- note we directly poke the shader vertex data here @@ -212,6 +209,8 @@ preloadRender = do , eslist ] initializeGLState + + tonormalmap <- initTexture 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/verticalRidge.png" return $ RenderData { _pictureShaders = shadV @@ -255,6 +254,7 @@ preloadRender = do , _vboWalls = wpVBO , _vboWindows = winVBO , _vboShapes = shVBO + , _toNormalMaps = tonormalmap } --------------------end preloadRender diff --git a/src/Shader/AuxAddition.hs b/src/Shader/AuxAddition.hs index 4561b2409..865fbada5 100644 --- a/src/Shader/AuxAddition.hs +++ b/src/Shader/AuxAddition.hs @@ -3,8 +3,10 @@ module Shader.AuxAddition , vaddTextureNoFilter , addTextureArray , addUniforms + , initTexture , tilesToLine -- ^ kept in case it is needed in the future ) where +import Data.Preload.Render import Unsafe.Coerce import Shader.Data import Control.Monad @@ -57,7 +59,24 @@ addTexture2D nlev minfilt magfilt texpath shad = do -- glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) -- return $ shad & shadTex' ?~ ShaderTexture -- {_textureObject = texname } - +initTexture + :: GLint -- number of mipmap levels + -> GLenum -- minfilter + -> GLenum -- magfilter + -> String -> IO TO +initTexture nlev minfilt magfilt fp = do + Right cmap <- readImage fp + let texdata = convertRGBA8 cmap + let wtex = fromIntegral $ imageWidth texdata + htex = fromIntegral $ imageHeight texdata + texname <- mglCreate $ glCreateTextures GL_TEXTURE_2D + glTextureStorage2D texname nlev GL_RGBA8 wtex htex + VS.unsafeWith (imageData texdata) $ \ptr -> do + glTextureSubImage2D texname 0 0 0 wtex htex GL_RGBA GL_UNSIGNED_BYTE ptr + glGenerateTextureMipmap texname + glTextureParameteri texname GL_TEXTURE_MIN_FILTER (unsafeCoerce minfilt) + glTextureParameteri texname GL_TEXTURE_MAG_FILTER (unsafeCoerce magfilt) + return $ TO texname -- | for transforming a 256x256 image containing 64 tiles of 16x16 pixels into -- an image that was directly readable by glTexSubImage3D, used the diff --git a/src/Shader/Data.hs b/src/Shader/Data.hs index 5bf5c9e2a..08e63717d 100644 --- a/src/Shader/Data.hs +++ b/src/Shader/Data.hs @@ -15,6 +15,8 @@ module Shader.Data -- , vaoAttribSizes -- , vaoStride + , textureObject + , vboName , vboPtr , vboVertexSize @@ -90,3 +92,4 @@ makeLenses ''VAO makeLenses ''VBO makeLenses ''FullShader makeLenses ''EBO +makeLenses ''ShaderTexture diff --git a/src/Shader/Poke.hs b/src/Shader/Poke.hs index b0bd2a8ad..ee04c456f 100644 --- a/src/Shader/Poke.hs +++ b/src/Shader/Poke.hs @@ -15,7 +15,6 @@ import qualified Data.Vector.Unboxed as UV import qualified Data.Vector.Unboxed.Mutable as UMV import Foreign import Geometry.Data -import Geometry.Polygon import Graphics.GL.Core45 import Linear.V3 (cross) import Picture.Data @@ -97,12 +96,9 @@ pokeShapeObj :: IO (Int, Int, Int) {-# INLINE pokeShapeObj #-} pokeShapeObj ptr iptr ieptr counts (Surface shtype shVerts col shadfid) = case shtype of - TopPrism size -> pokeTopPrism shadfid midp col size ptr iptr ieptr counts (VFSM.fromList shVerts) FlatFaces size -> pokeBox shadfid col size ptr iptr ieptr counts shVerts RoundedFaces size -> pokeRoundedFaces shadfid col size ptr iptr ieptr counts shVerts Cylinder size -> pokeCylinder shadfid col size ptr iptr ieptr counts shVerts - where - midp = centroidNum shVerts pokeRoundedFaces :: ShadowFidelity -> @@ -224,31 +220,6 @@ boxSurfaces' n = reverse [n .. n * 2 -1] : [ map ((2 * n) +) [4 * i, 4 * i + 1, 4 * i + 2, 4 * i + 3] | i <- [0 .. n -1]] -pokeTopPrism :: - ShadowFidelity -> - Point3 -> - Point4 -> - Int -> - Ptr Float -> - Ptr GLushort -> - Ptr GLushort -> - (Int, Int, Int) -> - VFSM.Stream IO Point3 -> - IO (Int, Int, Int) -{-# INLINE pokeTopPrism #-} -pokeTopPrism sfid cp col size ptr iptr ieptr (nv, nsi, nei) svs = do - nv' <- VFSM.foldlM' (pokeJustV cp col ptr) nv svs - nsi' <- - UV.foldM' - (pokeIndex nv iptr) - nsi - (memoTopPrismIndices V.! (size - 3)) - nei' <- case sfid of - NoShadowFidelity -> return nei - FullShadowFidelity -> UV.foldM' (pokeIndex nv ieptr) nei $ - memoTopPrismEdgeIndices V.! (size - 3) - return (nv', nsi', nei') - pokeIndex :: -- | base index Int -> @@ -263,17 +234,6 @@ pokeIndex nv eiptr ni ioff = do pokeElemOff eiptr ni (fromIntegral $ nv + ioff) return $ ni + 1 ---pokeTopPrismIndex :: --- Int -> --- Ptr GLushort -> --- Int -> --- Int -> --- IO Int ---{-# INLINE pokeTopPrismIndex #-} ---pokeTopPrismIndex nv iptr nshapeindices ioff = do --- pokeElemOff iptr nshapeindices (fromIntegral $ nv + ioff) --- return $ nshapeindices + 1 - triangulate :: [Int] -> [Int] triangulate is = V.toList . V.backpermute (V.fromList is) . V.fromList $ triangulateIndices (length is) @@ -290,6 +250,7 @@ memoFlatIndices = UV.fromList . concatMap triangulate . boxSurfaces' . (+ 3) memoTopPrismIndices :: V.Vector (UV.Vector Int) +{-# INLINE memoTopPrismIndices #-} memoTopPrismIndices = V.generate 10 $ UV.fromList . topPrismIndices . (+ 3) diff --git a/src/Shape/Data.hs b/src/Shape/Data.hs index fd78a0cc7..2a9cdeb15 100644 --- a/src/Shape/Data.hs +++ b/src/Shape/Data.hs @@ -14,8 +14,7 @@ import Data.Aeson.TH import Geometry.Data data ShapeType - = TopPrism { _prismSize :: Int } - | FlatFaces { _topBoxSize :: Int } + = FlatFaces { _topBoxSize :: Int } | RoundedFaces { _shapeHalfSize :: Int } | Cylinder { _cylinderSize :: Int } deriving (Eq, Ord, Show, Read)