Rmove overlay framebuffer, directly draw overlay instead

This commit is contained in:
2023-04-11 16:55:00 +01:00
parent d79216555b
commit 33a6e471ae
8 changed files with 123 additions and 137 deletions
+6 -6
View File
@@ -1,5 +1,5 @@
#version 450 core
layout(local_size_x= 16, local_size_y=1) in;
layout(local_size_x= 20, local_size_y=1) in;
layout(rgba8, binding = 5) uniform restrict writeonly image2D img_output;
layout (std140, binding = 1) uniform LightsBlock
{
@@ -13,7 +13,7 @@ void main ()
shared vec3[20] larray;
uint i = gl_LocalInvocationID.x;
vec3 lightamount = vec3(0,0,0);
ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
ivec2 pixel_coords = ivec2(gl_WorkGroupID.xy);
vec2 tex_coords = vec2((4*pixel_coords.x+4)/800.0, (4*pixel_coords.y+4)/835.0);
vec3 pos = texture(posTexture,tex_coords).xyz;
vec3 lightPos = posBool[i].xyz;
@@ -26,15 +26,15 @@ void main ()
float x = 1 - dist / lumRad.a;
vec3 norm = texture(normals,tex_coords).xyz;
float y1 = dot(normalize(norm), normalize(distVec));
float y = float(y1 > 0 ? 1 : 0);
float y = float(y1 > 0 ? 0 : 1);
lightamount = y*x*lumRad.rgb;
}
larray[i] = lightamount;
if (i == 0)
//{ vec3 inverselight = 1 - lightamount;
{ vec3 inverselight = vec3(0,0,0);
// for (uint j=1 ; j < 20; ++j) {inverselight = inverselight * (1 - larray[j]);}
{ vec3 inverselight = 1 - lightamount;
//{ vec3 inverselight = vec3(0,0,0);
for (uint j=1 ; j < 20; ++j) {inverselight = inverselight * (1 - larray[j]);}
imageStore(img_output, pixel_coords, vec4(inverselight,1));
}
}
-1
View File
@@ -41,7 +41,6 @@ data RenderData = RenderData
, _fboCloud :: (FBO, (TO, TO, TO))
, _fboBloom :: (FBO, TO)
, _fboPos :: (FBO, TO)
, _fboOverlay :: (FBO, TO)
, _fboLighting :: (FBO, TO)
, _fboShadow :: (FBO, (TO, TO))
, _rboBaseBloom :: GLuint -- RenderbufferObject id
+2 -2
View File
@@ -46,7 +46,7 @@ data Configuration = Configuration
, _graphics_shadow_size :: Importance
, _graphics_downsize_resolution :: ResFactor
, _graphics_world_resolution :: ResFactor
, _graphics_overlay_resolution :: ResFactor
, _graphics_distortion_resolution :: ResFactor
, _graphics_num_shadow_casters :: NumShadowCasters
, _windowX :: Int
, _windowY :: Int
@@ -136,7 +136,7 @@ defaultConfig =
, _graphics_distortions = True
, _graphics_downsize_resolution = SixteenthRes
, _graphics_world_resolution = QuarterRes
, _graphics_overlay_resolution = FullRes
, _graphics_distortion_resolution = FullRes
, _graphics_num_shadow_casters = toEnum 10
, _windowX = 800
, _windowY = 600
+5 -5
View File
@@ -15,6 +15,11 @@ import Dodge.Tree
import LensHelp
import RandomHelp
-- | A test level tree.
initialRoomTree :: State (StdGen, Int) (MetaTree Room String)
initialRoomTree = annoToRoomTree initialAnoTree
--initialRoomTree = annoToRoomTree startWorldTreeTest
startWorldTreeTest :: Annotation
startWorldTreeTest =
OnwardList $
@@ -106,8 +111,3 @@ initialAnoTree =
-- ,[Corridor]
AnTree $ randomFourCornerRoom [] >>= rToOnward "randomFourCornerRoom" . pure . cleatOnward
]
-- | A test level tree.
initialRoomTree :: State (StdGen, Int) (MetaTree Room String)
--initialRoomTree = annoToRoomTree initialAnoTree
initialRoomTree = annoToRoomTree startWorldTreeTest
+1 -1
View File
@@ -185,7 +185,7 @@ graphicsMenuOptions =
[ makeEnumOption graphics_world_resolution "World resolution" (uvIOEffects .~ updatePreload)
, makeEnumOption graphics_downsize_resolution "Downsize resolution"
(uvIOEffects .~ updatePreload)
, makeEnumOption graphics_overlay_resolution "Overlay resolution"
, makeEnumOption graphics_distortion_resolution "Overlay resolution"
(uvIOEffects .~ updatePreload)
, makeEnumOption graphics_shadow_rendering "SHADOW RENDERING" id
, makeEnumOption graphics_shadow_size "SHADOW DETAIL" id
+107 -117
View File
@@ -104,23 +104,6 @@ doDrawing' win pdata u = do
, (_shapeEBO pdata, nIndices)
, (_silhouetteEBO pdata, nSilIndices)
]
-- draw the overlay
glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboOverlay ._1 . unFBO)
withArray [0, 0, 0, 0] $ \ptr ->
glClearNamedFramebufferfv
(pdata ^. fboOverlay . _1 . unFBO)
GL_COLOR
0
ptr
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
setViewport _graphics_overlay_resolution cfig
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig))
$ \ptr -> glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
renderLayer FixedCoordLayer shadV layerCounts
-- set the coordinate uniform ready for drawing elements using world coordinates
withArray (perspectiveMatrixb rot camzoom trans wins viewFroms) $ \ptr ->
glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
@@ -247,100 +230,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
@@ -349,9 +332,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
@@ -377,9 +360,16 @@ doDrawing' win pdata u = do
bindings = zipWith (>>) (map bindFBO fboList) (map (glBindTextureUnit 1 . _unTO) toList)
zipWithM_ (>>) bindings $ map bindDrawDist rds
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
--draw overlay onto base buffer
glBindTextureUnit 0 (pdata ^. fboOverlay . _2 . unTO)
drawShader (_fullscreenShader pdata) 4
-- draw the overlay
--glBindFramebuffer GL_FRAMEBUFFER (pdata ^. fboOverlay ._1 . unFBO)
glDepthFunc GL_ALWAYS
glDepthMask GL_FALSE
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
glBindBufferBase GL_UNIFORM_BUFFER 0 (pdata ^. matUBO)
withArray (scaleMatrix (2 / windowXFloat cfig) (2 / windowYFloat cfig))
$ \ptr -> glNamedBufferSubData (pdata ^. matUBO) 0 64 ptr
renderLayer FixedCoordLayer shadV layerCounts
SDL.glSwapWindow win
getDistortions :: Configuration -> World -> [Distortion]
+2 -2
View File
@@ -50,11 +50,11 @@ sizeFBOs cfig rdata =
GL_RGBA16F
[fboBloom, fboPos]
>>= foldUpdateFBOTO
_graphics_overlay_resolution
_graphics_distortion_resolution
GL_LINEAR
GL_NEAREST
GL_RGBA8
[fbo2, fbo3, fboOverlay]
[fbo2, fbo3]
>>= foldUpdateFBOTO
_graphics_downsize_resolution
GL_LINEAR_MIPMAP_LINEAR
-3
View File
@@ -171,8 +171,6 @@ preloadRender = do
fboShadowName <- setupShadowFramebuffer
fbooverlay <- newTextureFramebuffer
fboHalf1Name <- newTextureFramebuffer
fboHalf2Name <- newTextureFramebuffer
fboHalf3Name <- newTextureFramebuffer
@@ -229,7 +227,6 @@ preloadRender = do
, _fboCloud = fboCloudName
, _fboBloom = fboBloomName
, _fboPos = fboPosName
, _fboOverlay = fbooverlay
, _rboBaseBloom = rboBaseBloomName
, _matUBO = theUBO
, -- , _orthonormalMatUBO = orthonormalUBO