Fix wall normals

This commit is contained in:
2023-03-16 23:31:17 +00:00
parent 100fdc102d
commit 539cbe8b18
11 changed files with 32 additions and 46 deletions
+2 -1
View File
@@ -4,11 +4,12 @@ layout (location=1) out vec4 fPos;
layout (location=2) out vec4 fNorm;
in vec2 tPos;
in vec4 gPos;
in vec4 gNorm;
in vec4 gColor;
uniform sampler2D tex;
void main()
{
fCol = gColor * texture(tex,tPos);
fPos = gPos;
fNorm = gPos + vec4(1,0,0,0);
fNorm = gNorm;
}
+7
View File
@@ -6,6 +6,7 @@ in vec4 vColor [];
out vec4 gColor;
out vec2 tPos;
out vec4 gPos;
out vec4 gNorm;
// 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); }
@@ -15,9 +16,15 @@ void main()
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
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);
gNorm = p1 - norm;
gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = vec4(theMat * p1); EmitVertex();
gNorm = p1 - norm;
gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = vec4(theMat * p3); EmitVertex();
gNorm = p1 - norm;
gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = vec4(theMat * p2); EmitVertex();
gNorm = p1 - norm;
gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = vec4(theMat * p4); EmitVertex();
EndPrimitive();
}
+1 -4
View File
@@ -30,8 +30,7 @@ data RenderData = RenderData
, _wallTextureShader :: FullShader
, _textureArrayShader :: (FullShader,VBO)
, _fullscreenShader :: (FullShader,VBO)
, --, _fullscreenAlphaHalveShader :: (FullShader,VBO)
_bloomBlurShader :: FullShader
, _bloomBlurShader :: FullShader
, _colorBlurShader :: FullShader
, _barrelShader :: (FullShader,VBO)
, _grayscaleShader :: FullShader
@@ -47,10 +46,8 @@ data RenderData = RenderData
, _fboBase :: (FBO, (TO, TO, TO))
, _fboCloud :: (FBO, (TO, TO))
, _fboBloom :: (FBO, TO)
, _fboColor :: (FBO, TO)
, _fboPos :: (FBO, TO)
, _fboLighting :: (FBO, TO)
--, _fboLightingHigh :: (FBO, TO)
, _fboShadow :: (FBO, (TO, TO))
, _rboBaseBloom :: GLuint -- RenderbufferObject id
, _matUBO :: GLuint -- BufferObject id
+2 -2
View File
@@ -127,8 +127,8 @@ doDrawing' win pdata u = do
glDepthFunc GL_LESS
-- draw wall occlusions from the camera's point of view
glUseProgram (pdata ^. lightingWallShadShader . shadName)
glUniform3f (pdata ^?! lightingWallShadShader . shadUnis' . ix 0) vfx vfy 20
glUniform1f (pdata ^?! lightingWallShadShader . shadUnis' . ix 1) 100
glUniform3f (pdata ^?! lightingWallShadShader . shadUnis . ix 0) vfx vfy 20
glUniform1f (pdata ^?! lightingWallShadShader . shadUnis . ix 1) 1000
glBindVertexArray $ pdata ^. lightingWallShadShader . shadVAO . vaoName
unless (debugOn Remove_LOS cfig) $
glDrawArrays
+1 -2
View File
@@ -34,8 +34,7 @@ sizeFBOs xsize ysize xfull yfull rdata = do
foldM (updateFBOTO2 xsize ysize GL_NEAREST GL_NEAREST GL_RGBA8 GL_RGBA16F) rdata1 [fboCloud]
>>= flip
(foldM (updateFBOTO xsize ysize GL_NEAREST GL_NEAREST GL_RGBA8))
[fboColor, fboLighting]
--[fboColor, fboLighting, fboLightingHigh]
[fboLighting]
rdata'' <-
foldM
(updateFBOTO xsize ysize GL_LINEAR_MIPMAP_LINEAR GL_LINEAR GL_RGBA16F)
-13
View File
@@ -49,14 +49,10 @@ preloadRender = do
nullPtr
GL_STREAM_DRAW
let wpVBO = VBO{_vboName = wpVBOname, _vboPtr = wpVBOptr, _vboVertexSize = 8}
-- wpVAOname <- genObjectName
-- bindVertexArrayObject $= Just wpVAOname
wpVAOname <- mglCreate glCreateVertexArrays
glBindVertexArray wpVAOname
glVertexArrayVertexBuffer wpVAOname 0 wpVBOname 0 (fromIntegral $ floatSize * 8)
setupVertexAttribPointer wpVAOname 0 4 0
--wpColVAOname <- genObjectName
--bindVertexArrayObject $= Just wpColVAOname
wpColVAOname <- mglCreate glCreateVertexArrays
glBindVertexArray wpColVAOname
glVertexArrayVertexBuffer wpColVAOname 0 wpVBOname 0 (fromIntegral $ floatSize * 8)
@@ -72,8 +68,6 @@ preloadRender = do
nullPtr
GL_STREAM_DRAW
let winVBO = VBO{_vboName = winVBOname, _vboPtr = winVBOptr, _vboVertexSize = 8}
--winColVAOname <- genObjectName
--bindVertexArrayObject $= Just winColVAOname
winColVAOname <- mglCreate glCreateVertexArrays
glBindVertexArray winColVAOname
glVertexArrayVertexBuffer winColVAOname 0 winVBOname 0 (fromIntegral $ floatSize * 8)
@@ -168,8 +162,6 @@ preloadRender = do
lightingTextureShad <-
makeShaderUsingVAO "lighting/texture" [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
@@ -181,7 +173,6 @@ preloadRender = do
textArrayShad <-
makeShader "texture/arrayPos" [vert, frag] [3, 3] ETriangles
>>= addTextureArray "data/texture/ayene_wooden_floor_transformed.png"
-- >>= addTextureArray "data/texture/ayene_wooden_floor.png"
-- bind fixed vertex data
bufferPokedVBO (snd fsShad) 4
framebuf2 <- setupTextureFramebuffer 800 600
@@ -197,10 +188,8 @@ preloadRender = do
fboBaseName <- setupFramebuffer3GivenStencil rboBaseBloomName
fboCloudName <- setupFramebuffer2GivenStencil rboBaseBloomName
fboBloomName <- setupFramebufferGivenStencil rboBaseBloomName
fboColorName <- setupFramebufferGivenStencil rboBaseBloomName
fboPosName <- setupFramebufferGivenStencil rboBaseBloomName
fboLightingName <- setupFramebufferGivenStencil rboBaseBloomName
--fboLightingHighName <- setupFramebufferGivenStencil rboBaseBloomName
fboShadowName <- setupShadowFramebuffer
@@ -254,12 +243,10 @@ preloadRender = do
, _fboHalf2 = fboHalf2Name
, _fboHalf3 = fboHalf3Name
, _fboLighting = fboLightingName
--, _fboLightingHigh = fboLightingHighName
, _fboShadow = fboShadowName
, _fboBase = fboBaseName
, _fboCloud = fboCloudName
, _fboBloom = fboBloomName
, _fboColor = fboColorName
, _fboPos = fboPosName
, _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO
+11 -13
View File
@@ -87,11 +87,10 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
bindTO toPos
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glStencilFunc GL_EQUAL 0 255
glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad)
glUniform3f (_shadUnis' ltextShad V.! 0) x y z
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)
glUseProgram (ltextShad ^. shadName)
glUniform3f (_shadUnis ltextShad V.! 0) x y z
glUniform4f (_shadUnis ltextShad V.! 1) r g b rad
glBindVertexArray $ ltextShad ^. shadVAO . vaoName
glDrawArrays
(marshalEPrimitiveMode (_shadPrim' ltextShad))
0
@@ -113,7 +112,6 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
0
ptr
glDisable GL_CULL_FACE
--bindTO toPos
glBindTextureUnit 0 (toPos ^. unTO)
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
@@ -154,8 +152,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glStencilFunc GL_ALWAYS 0 255
--draw wall shadows
glUseProgram (_shadName lwallShad)
glUniform3f (_shadUnis' lwallShad V.! 0) x y z
glUniform1f (_shadUnis' lwallShad V.! 1) rad
glUniform3f (_shadUnis lwallShad V.! 0) x y z
glUniform1f (_shadUnis lwallShad V.! 1) rad
glBindVertexArray $ lwallShad ^. shadVAO . vaoName -- Just (_vao $ _shadVAO lwallShad)
glDrawArrays
(marshalEPrimitiveMode $ _shadPrim' lwallShad)
@@ -166,8 +164,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
--draw silhouette shadows
glEnable GL_DEPTH_CLAMP
glUseProgram (_shadName llinesShad)
glUniform3f (_shadUnis' llinesShad V.! 0) x y z
glUniform1f (_shadUnis' llinesShad V.! 1) rad
glUniform3f (_shadUnis llinesShad V.! 0) x y z
glUniform1f (_shadUnis llinesShad V.! 1) rad
glBindVertexArray (_vaoName $ _shadVAO llinesShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' llinesShad)
@@ -179,7 +177,7 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glCullFace GL_BACK
glCullFace GL_FRONT
glUseProgram (_shadName lcapShad)
glUniform3f (_shadUnis' lcapShad V.! 0) x y z
glUniform3f (_shadUnis lcapShad V.! 0) x y z
glBindVertexArray $ lcapShad ^. shadVAO . vaoName --Just (_vao $ _shadVAO lcapShad)
glDrawElements
(marshalEPrimitiveMode $ _shadPrim' lcapShad)
@@ -198,8 +196,8 @@ createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos dra
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glStencilFunc GL_EQUAL 0 255
glUseProgram (ltextShad ^. shadName) --Just (_shadProg ltextShad)
glUniform3f (_shadUnis' ltextShad V.! 0) x y z
glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad
glUniform3f (_shadUnis ltextShad V.! 0) x y z
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
+1 -1
View File
@@ -93,4 +93,4 @@ addUniforms uniStrings shad = do foldM addUniform shad uniStrings
addUniform :: FullShader -> String -> IO FullShader
addUniform shad unistr = BS.useAsCString (pack unistr) $ \cstr -> do
loc <- glGetUniformLocation (_shadName shad) cstr
return $ shad & shadUnis' %~ (V.++ V.fromList [loc])
return $ shad & shadUnis %~ (V.++ V.fromList [loc])
-3
View File
@@ -47,6 +47,3 @@ bufferShaderVector :: MV.MVector (PrimState IO) (FullShader, VBO) -> UMV.MVector
bufferShaderVector shads counts = MV.imapM_ f shads
where
f i shad = UMV.read counts i >>= bufferPokedVBO (snd shad)
--bindShaderBuffers :: [VBO] -> [Int] -> IO ()
--bindShaderBuffers = zipWithM_ bufferPokedVBO
+5 -5
View File
@@ -42,7 +42,7 @@ makeShader s shaderlist sizes pm = do
, _shadVAO = vao
, _shadPrim' = pm
, _shadTex' = Nothing
, _shadUnis' = mempty
, _shadUnis = mempty
}
, vbo)
@@ -66,7 +66,7 @@ makeShader4 s shaderlist sizes strd pm vbo = do
, _shadVAO = vao
, _shadPrim' = pm
, _shadTex' = Nothing
, _shadUnis' = mempty
, _shadUnis = mempty
}
setupVBO :: Int -> IO VBO
@@ -96,7 +96,7 @@ makeByteStringShaderUsingVAO s shaderlist pm vao = do
, _shadVAO = vao
, _shadPrim' = pm
, _shadTex' = Nothing
, _shadUnis' = mempty
, _shadUnis = mempty
}
-- | Takes the VAO from elsewhere
@@ -116,7 +116,7 @@ makeShaderUsingVAO s shaderlist pm theVAO = do
, _shadVAO = theVAO
, _shadPrim' = pm
, _shadTex' = Nothing
, _shadUnis' = mempty
, _shadUnis = mempty
}
{- |
@@ -142,7 +142,7 @@ makeShaderSized s shaderlist sizes ndraw pm = do
, _shadVAO = vao
, _shadPrim' = pm
, _shadTex' = Nothing
, _shadUnis' = mempty
, _shadUnis = mempty
}
, vbo)
+2 -2
View File
@@ -26,7 +26,7 @@ module Shader.Data
, shadVAO
, shadPrim'
, shadTex'
, shadUnis'
, shadUnis
-- | Synonyms
, vert
, geom
@@ -42,7 +42,7 @@ data FullShader = FullShader
, _shadVAO :: VAO
, _shadPrim' :: EPrimitiveMode
, _shadTex' :: Maybe ShaderTexture
, _shadUnis' :: Vector GLint
, _shadUnis :: Vector GLint
}
{- | Vertex array object: contains the reference to the object,
and its buffer targets. -}