Try to add compute shaders

This commit is contained in:
2023-04-11 14:55:57 +01:00
parent 69a76dbf93
commit d79216555b
21 changed files with 457 additions and 246 deletions
+100 -97
View File
@@ -209,6 +209,9 @@ doDrawing' win pdata u = do
pdata
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
--apply lightmap to base buffer
glDisable GL_CULL_FACE
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboBase . _1 . unFBO)
glBindTextureUnit 0 (pdata ^. fboLighting . _2 . unTO)
glEnable GL_BLEND
@@ -244,100 +247,100 @@ doDrawing' win pdata u = do
replicateM_ 2 $ pingPongBetween (_fboHalf1 pdata) (_fboHalf2 pdata) (_bloomBlurShader pdata)
glEnable GL_BLEND
setViewport _graphics_world_resolution cfig
--draw clouds onto cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
glDepthFunc GL_LEQUAL
glDepthMask GL_FALSE
--blendFunc $= (SrcAlphaSaturate,One)
--blendColor $= Color4 0.5 0.5 0.5 0.5
--blendFuncSeparate $= ((SrcAlphaSaturate,One) , (One,OneMinusSrcAlpha))
--blendFuncSeparate $= ((SrcAlpha, OneMinusSrcAlpha), (One, OneMinusSrcAlpha))
--glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA
glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_DST_ALPHA GL_ONE
--glBlendFuncSeparate GL_SRC_ALPHA_SATURATE GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA
--glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr
withArray [0.5, 0.5, 0.5, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
0
ptr
-- renderLayer MidLayer shadV layerCounts
glUseProgram (pdata ^. cloudShader . shaderUINT)
glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
glDrawElements
(pdata ^. cloudShader . shaderPrimitive . unPrimitiveMode)
(fromIntegral nCloudIs)
GL_UNSIGNED_SHORT
nullPtr
drawShader (_windowShader pdata) nWins
when (_graphics_cloud_shadows cfig) $ do
----render transparency depths
glDepthMask GL_TRUE
glDepthFunc GL_ALWAYS
glDisable GL_BLEND
withArray [GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ \ptr -> glDrawBuffers 3 ptr
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
1
ptr
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboCloud . _1 . unFBO)
GL_COLOR
2
ptr
glEnable GL_BLEND
-- we sum the positions weighted by alpha, and sum the alpha
glBlendFuncSeparatei 1 GL_SRC_ALPHA GL_ONE GL_ONE GL_ONE
-- and sum the normals weighted by alpha
glBlendFunci 2 GL_SRC_ALPHA GL_ONE
glUseProgram (pdata ^. cloudShader . shaderUINT)
glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
glDepthMask GL_TRUE
glDrawElements
(pdata ^. cloudShader . shaderPrimitive . unPrimitiveMode)
(fromIntegral nCloudIs)
GL_UNSIGNED_SHORT
nullPtr
drawShader (_windowShader pdata) nWins
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboPos . _1 . unFBO)
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboPos . _1 . unFBO)
GL_COLOR
0
ptr
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _2 . unTO)
glDepthMask GL_FALSE
drawShader (pdata ^. alphaDivideShader) 4
----draw lightmap for cloud buffer
glDepthFunc GL_LESS
glEnable GL_BLEND
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
createLightMap
cfig
(fromIntegral trueNWalls)
nSilIndices
nIndices
(pdata ^. fboPos . _2)
(pdata ^. fboCloud . _2 . _3)
lightPoints
pdata
glInvalidateBufferData (pdata ^. vboShapes . vboName)
--apply lightmap to cloud buffer
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
glDepthMask GL_FALSE
withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr
glDepthFunc GL_ALWAYS
glBindTextureUnit 0 (_unTO . snd $ _fboLighting pdata)
glEnable GL_BLEND
glBlendFuncSeparate GL_ZERO GL_ONE_MINUS_SRC_COLOR GL_ZERO GL_ONE
drawShader (_fullscreenShader pdata) 4
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- --draw clouds onto cloud buffer
-- glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
-- glDepthFunc GL_LEQUAL
-- glDepthMask GL_FALSE
-- --blendFunc $= (SrcAlphaSaturate,One)
-- --blendColor $= Color4 0.5 0.5 0.5 0.5
-- --blendFuncSeparate $= ((SrcAlphaSaturate,One) , (One,OneMinusSrcAlpha))
-- --blendFuncSeparate $= ((SrcAlpha, OneMinusSrcAlpha), (One, OneMinusSrcAlpha))
-- --glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA
-- glBlendFuncSeparate GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA GL_ONE_MINUS_DST_ALPHA GL_ONE
-- --glBlendFuncSeparate GL_SRC_ALPHA_SATURATE GL_ONE_MINUS_SRC_ALPHA GL_ONE GL_ONE_MINUS_SRC_ALPHA
-- --glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr
-- withArray [0.5, 0.5, 0.5, 0] $ \ptr ->
-- glClearNamedFramebufferfv
-- (pdata ^. fboCloud . _1 . unFBO)
-- GL_COLOR
-- 0
-- ptr
-- -- renderLayer MidLayer shadV layerCounts
-- glUseProgram (pdata ^. cloudShader . shaderUINT)
-- glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
-- glDrawElements
-- (pdata ^. cloudShader . shaderPrimitive . unPrimitiveMode)
-- (fromIntegral nCloudIs)
-- GL_UNSIGNED_SHORT
-- nullPtr
-- drawShader (_windowShader pdata) nWins
-- when (_graphics_cloud_shadows cfig) $ do
-- ----render transparency depths
-- glDepthMask GL_TRUE
-- glDepthFunc GL_ALWAYS
-- glDisable GL_BLEND
-- withArray [GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ \ptr -> glDrawBuffers 3 ptr
-- withArray [0, 0, 0, 0] $ \ptr ->
-- glClearNamedFramebufferfv
-- (pdata ^. fboCloud . _1 . unFBO)
-- GL_COLOR
-- 1
-- ptr
-- withArray [0, 0, 0, 0] $ \ptr ->
-- glClearNamedFramebufferfv
-- (pdata ^. fboCloud . _1 . unFBO)
-- GL_COLOR
-- 2
-- ptr
-- glEnable GL_BLEND
-- -- we sum the positions weighted by alpha, and sum the alpha
-- glBlendFuncSeparatei 1 GL_SRC_ALPHA GL_ONE GL_ONE GL_ONE
-- -- and sum the normals weighted by alpha
-- glBlendFunci 2 GL_SRC_ALPHA GL_ONE
-- glUseProgram (pdata ^. cloudShader . shaderUINT)
-- glBindVertexArray $ pdata ^. cloudShader . shaderVAO . vaoName
-- glDepthMask GL_TRUE
-- glDrawElements
-- (pdata ^. cloudShader . shaderPrimitive . unPrimitiveMode)
-- (fromIntegral nCloudIs)
-- GL_UNSIGNED_SHORT
-- nullPtr
-- drawShader (_windowShader pdata) nWins
-- glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboPos . _1 . unFBO)
-- withArray [0, 0, 0, 0] $ \ptr ->
-- glClearNamedFramebufferfv
-- (pdata ^. fboPos . _1 . unFBO)
-- GL_COLOR
-- 0
-- ptr
-- glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _2 . unTO)
-- glDepthMask GL_FALSE
-- drawShader (pdata ^. alphaDivideShader) 4
-- ----draw lightmap for cloud buffer
-- glDepthFunc GL_LESS
-- glEnable GL_BLEND
-- glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
-- createLightMap
-- cfig
-- (fromIntegral trueNWalls)
-- nSilIndices
-- nIndices
-- (pdata ^. fboPos . _2)
-- (pdata ^. fboCloud . _2 . _3)
-- lightPoints
-- pdata
-- glInvalidateBufferData (pdata ^. vboShapes . vboName)
-- --apply lightmap to cloud buffer
-- glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboCloud pdata)))
-- glDepthMask GL_FALSE
-- withArray [GL_COLOR_ATTACHMENT0, GL_NONE] $ \ptr -> glDrawBuffers 2 ptr
-- glDepthFunc GL_ALWAYS
-- glBindTextureUnit 0 (_unTO . snd $ _fboLighting pdata)
-- glEnable GL_BLEND
-- glBlendFuncSeparate GL_ZERO GL_ONE_MINUS_SRC_COLOR GL_ZERO GL_ONE
-- drawShader (_fullscreenShader pdata) 4
-- glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
-- bind base buffer for drawing bloom then clouds
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboBase pdata)))
--Draw blurred bloom onto base buffer
@@ -346,9 +349,9 @@ doDrawing' win pdata u = do
glBindTextureUnit 0 (_unTO . snd $ _fboHalf1 pdata)
drawShader (_fullscreenShader pdata) 4
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
--draw shadowed clouds onto base buffer
glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
drawShader (_fullscreenShader pdata) 4
-- --draw shadowed clouds onto base buffer
-- glBindTextureUnit 0 (pdata ^. fboCloud . _2 . _1 . unTO)
-- drawShader (_fullscreenShader pdata) 4
--set viewport for radial distortion
--setViewportSize (round winx) (round winy)
setViewport (const FullRes) cfig