Work towards using vertex pulling for lighting caps, alignment issues

This commit is contained in:
2025-11-11 12:33:33 +00:00
parent 36d5edc0a6
commit a65a1cab93
9 changed files with 173 additions and 100 deletions
+2
View File
@@ -44,6 +44,8 @@ data RenderData = RenderData
, _matUBO :: GLuint -- BufferObject id
, _winSSBO :: GLuint
, _wallSSBO :: GLuint
, _shapeSSBO :: GLuint
, _ishapeSSBO :: GLuint
-- , _lightsUBO :: GLuint -- BufferObject id
, _vboWindows :: VBO
, _vboShapes :: VBO
+10
View File
@@ -116,6 +116,16 @@ doDrawing' win pdata u = do
glNamedBufferSubData (pdata ^. wallSSBO) 0
(fromIntegral $ trueNWalls * sizeOf (0::Float) * 8)
(pdata ^. wallVBO . vboPtr)
glNamedBufferSubData (pdata ^. shapeSSBO) 0
-- (fromIntegral $ nShapeVs * (sizeOf (0::Float)*8 + sizeOf (0::Word8)*4))
(fromIntegral $ nShapeVs * (sizeOf (0::Float)*12))
(pdata ^. vboShapes . vboPtr)
withArray [0::GLuint,1,2] $
glNamedBufferSubData (pdata ^. ishapeSSBO) 0
(fromIntegral $ 3 * (sizeOf (0::GLuint)))
-- glNamedBufferSubData (pdata ^. ishapeSSBO) 0
-- (fromIntegral $ nIndices * (sizeOf (0::GLushort)))
-- (pdata ^. shapeEBO . eboPtr)
setViewport _gr_world_res cfig
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
glDepthMask GL_TRUE
+13 -1
View File
@@ -49,6 +49,15 @@ preloadRender = do
glNamedBufferStorage wallssbo (fromIntegral wallssbosize) nullPtr GL_DYNAMIC_STORAGE_BIT
glBindBufferBase GL_SHADER_STORAGE_BUFFER 2 wallssbo
shapessbo <- mglCreate glCreateBuffers
let shapessbosize = fromIntegral (sizeOf (0::Float) * 12) * 65536
glNamedBufferStorage shapessbo shapessbosize nullPtr GL_DYNAMIC_STORAGE_BIT
glBindBufferBase GL_SHADER_STORAGE_BUFFER 3 shapessbo
ishapessbo <- mglCreate glCreateBuffers
let ishapessbosize = fromIntegral (sizeOf (0::GLushort) * 65536)
glNamedBufferStorage ishapessbo ishapessbosize nullPtr GL_DYNAMIC_STORAGE_BIT
glBindBufferBase GL_SHADER_STORAGE_BUFFER 4 ishapessbo
dummyvao <- mglCreate glGenVertexArrays
winpull <- makeShaderUsingVAO "pull/window" [vert,frag] pmTriangles (VAO dummyvao)
@@ -86,7 +95,8 @@ preloadRender = do
--makeShaderUsingVBO "lighting/wallShadow" [vert, geom] (toFloatVAs [4]) pmPoints wallvbo
makeShaderUsingVAO "lighting/wallShadow" [vert] pmTriangles (VAO dummyvao)
lightingCapShad <-
makeShaderUsingVAO "lighting/cap" [vert, geom] pmTriangles shPosVAO
--makeShaderUsingVAO "lighting/cap" [vert, geom] pmTriangles shPosVAO
makeShaderUsingVAO "lighting/cap" [vert] pmTriangles (VAO dummyvao)
lightingLineShadowShad <-
makeShaderUsingVAO "lighting/lineShadow" [vert, geom] pmLinesAdjacency shedgevao
@@ -214,6 +224,8 @@ preloadRender = do
, _matUBO = theUBO
, _winSSBO = winssbo
, _wallSSBO = wallssbo
, _shapeSSBO = shapessbo
, _ishapeSSBO = ishapessbo
-- , _lightsUBO = lightsubo
, _vboWindows = winvbo
, _vboShapes = shVBO
+15 -6
View File
@@ -197,12 +197,21 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li
glCullFace GL_FRONT
glUseProgram (_shaderUINT lcapShad)
glUniform3f 0 x y z
glBindVertexArray $ lcapShad ^. shaderVAO . vaoName --Just (_vao $ _shadVAO lcapShad)
glDrawElements
(_unPrimitiveMode $ _shaderPrimitive lcapShad)
(fromIntegral nCaps)
GL_UNSIGNED_SHORT
nullPtr
glUniform4f 1 r g b rad
--glBindVertexArray $ lcapShad ^. shaderVAO . vaoName --Just (_vao $ _shadVAO lcapShad)
glBindVertexArray $ pdata ^. dummyVAO . vaoName
glFrontFace(GL_CW)
glDrawArrays
GL_TRIANGLES
0
3
--(fromIntegral nCaps)
glFrontFace(GL_CCW)
--glDrawElements
-- (_unPrimitiveMode $ _shaderPrimitive lcapShad)
-- (fromIntegral nCaps)
-- GL_UNSIGNED_SHORT
-- nullPtr
glDisable GL_DEPTH_CLAMP
_ -> return ()
--draw lightmap itself
+2 -2
View File
@@ -446,7 +446,7 @@ pokeJustV ::
pokeJustV xdata cp col ptr nv sh = do
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (toColor8 col)
pokeByteOff ptr (nv *shapeVerxSize + 4 * (floatSize + ubyteSize)) (V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (V4 nx ny nz 1)
return (nv + 1)
where
V3 x y z = sh
@@ -464,7 +464,7 @@ pokeFlatV ::
pokeFlatV xdata norm col ptr nv sh = do
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (toColor8 col)
pokeByteOff ptr (nv *shapeVerxSize + 4 * (floatSize + ubyteSize)) (V4 nx ny nz 1)
pokeByteOff ptr (nv *shapeVerxSize + 8 * floatSize) (V4 nx ny nz 1)
return (nv + 1)
where
V3 x y z = sh
+5 -4
View File
@@ -1,19 +1,20 @@
module Shape.Parameters
module Shape.Parameters
(shapeVerxSize,shapeVerxAttributes)
where
import Shader.Parameters
import Shader.Data
import Data.Word
--import Data.Word
import Foreign.Storable
import Graphics.GL.Core45
shapeVerxSize :: Int
shapeVerxSize = sizeOf (0 :: Float) * 8 + 4 * sizeOf (0 :: Word8)
shapeVerxSize = sizeOf (0 :: Float) * 12
shapeVerxAttributes :: [VertexAttribute]
shapeVerxAttributes =
[VertexAttribute 4 GL_FLOAT GL_FALSE 0
,VertexAttribute 4 GL_UNSIGNED_BYTE GL_TRUE (fromIntegral (4 :: Int) * fromIntegral floatSize)
,VertexAttribute 4 GL_FLOAT GL_FALSE (fromIntegral (4 :: Int) * fromIntegral (floatSize + ubyteSize))
,VertexAttribute 4 GL_FLOAT GL_FALSE (fromIntegral (8 :: Int) * fromIntegral (floatSize))
]