diff --git a/shader/compute/shadow.comp b/shader/compute/shadow.comp index 404d913f2..b079d9966 100644 --- a/shader/compute/shadow.comp +++ b/shader/compute/shadow.comp @@ -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)); } } diff --git a/src/Data/Preload/Render.hs b/src/Data/Preload/Render.hs index 73217aa4e..254dd9d7f 100644 --- a/src/Data/Preload/Render.hs +++ b/src/Data/Preload/Render.hs @@ -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 diff --git a/src/Dodge/Data/Config.hs b/src/Dodge/Data/Config.hs index d0737b64b..a822127e7 100644 --- a/src/Dodge/Data/Config.hs +++ b/src/Dodge/Data/Config.hs @@ -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 diff --git a/src/Dodge/Floor.hs b/src/Dodge/Floor.hs index 5ea877534..0986b9127 100644 --- a/src/Dodge/Floor.hs +++ b/src/Dodge/Floor.hs @@ -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 diff --git a/src/Dodge/Menu.hs b/src/Dodge/Menu.hs index cd017eba7..7f3803faf 100644 --- a/src/Dodge/Menu.hs +++ b/src/Dodge/Menu.hs @@ -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 diff --git a/src/Dodge/Render.hs b/src/Dodge/Render.hs index c00303755..ed65ac036 100644 --- a/src/Dodge/Render.hs +++ b/src/Dodge/Render.hs @@ -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] diff --git a/src/Framebuffer/Update.hs b/src/Framebuffer/Update.hs index cd241c819..c82957309 100644 --- a/src/Framebuffer/Update.hs +++ b/src/Framebuffer/Update.hs @@ -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 diff --git a/src/Preload/Render.hs b/src/Preload/Render.hs index c3e456c7e..66ec9f35a 100644 --- a/src/Preload/Render.hs +++ b/src/Preload/Render.hs @@ -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