Experiment with bloom

This commit is contained in:
jgk
2021-07-05 19:39:34 +02:00
parent 2d94e50e3a
commit 77d93fabeb
6 changed files with 93 additions and 10 deletions
+57
View File
@@ -0,0 +1,57 @@
#version 430 core
in vec2 vTexPos;
out vec4 fColor;
uniform vec2 winSize;
uniform sampler2D screenTexture;
const float hOff = 2.0 / 600;
const float vOff = 2.0 / 600;
const float frac = 1.0 / 9;
const vec2 off[9] = vec2[]
( vec2( vOff,hOff )
, vec2( vOff,0.0 )
, vec2( vOff,-hOff )
, vec2( 0.0,hOff )
, vec2( 0.0,0.0 )
, vec2( 0.0,-hOff )
, vec2( -vOff,hOff )
, vec2( -vOff,0.0 )
, vec2( -vOff,-hOff )
);
const vec2 fiveOff[5] = vec2[]
( vec2( vOff,0.0 )
, vec2( 0.0,hOff )
, vec2( 0.0,0.0 )
, vec2( 0.0,-hOff )
, vec2( -vOff,0.0 )
);
vec4 combinef (vec4 ac, vec4 bc)
//{ return vec4 (max(ac.x,bc.x),max(ac.y,bc.y),max(ac.z,bc.z),ac.w + bc.w -
// ac.w*bc.w);
//{ return vec4 (max(ac.x,bc.x),max(ac.y,bc.y),max(ac.z,bc.z),ac.w + bc.w);
{ return vec4 (ac.rgb + bc.rgb * bc.a , ac.a + bc.a );
}
void main()
{
vec4 sampleTex[9];
for(int i=0; i<9; i++)
{
sampleTex[i] = vec4(texture(screenTexture, vTexPos + off[i]));
}
vec4 col = vec4(0,0,0,0);
for (int i = 0; i < 9; i++)
col = combinef(col,sampleTex[i]);
//col += sampleTex[i] * frac;
float alph = 0.0;
for (int i = 0; i < 9; i++)
alph += sampleTex[i].a;
alph = sampleTex[5].a + alph/9.0;
//
//fColor = col;
fColor = vec4(col.rgb/col.a,alph);
//if (col.a == 0.0)
//{ fColor = vec4(0,0,0,0); }
//else
//{ fColor = vec4( col.r/col.a , col.g/col.a , col.b/col.a, col.a/9.0); }
}
+9
View File
@@ -0,0 +1,9 @@
#version 430 core
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 texPos;
out vec2 vTexPos;
void main()
{
gl_Position = vec4(pos,0,1);
vTexPos = texPos;
}
+6 -2
View File
@@ -19,7 +19,10 @@ const vec2 off[9] = vec2[](
, vec2( -vOff,0.0 )
, vec2( -vOff,-hOff )
);
vec4 combinef (vec4 ac, vec4 bc)
//{ return vec4 (max(ac.x,bc.x),max(ac.y,bc.y),max(ac.z,bc.z),max(ac.w,bc.w));
{ return vec4 (max(ac.x,bc.x),max(ac.y,bc.y),max(ac.z,bc.z),ac.w +bc.w*frac);
}
void main()
{
vec4 sampleTex[9];
@@ -29,6 +32,7 @@ void main()
}
vec4 col = vec4(0,0,0,0);
for (int i = 0; i < 9; i++)
col += sampleTex[i] * frac;
col = combinef(col,sampleTex[i]);
//col += sampleTex[i] * frac;
fColor = col;
}
+17 -2
View File
@@ -77,8 +77,22 @@ doDrawing pdata w = do
_ <- renderFoldable pdata $ picToLTree (Just 3) pic
_ <- renderFoldable pdata $ picToLTree (Just 4) pic
_ <- renderFoldable pdata $ picToLTree (Just 5) pic
depthMask $= Enabled
bindFramebuffer Framebuffer $= (fst3 $ _fbo3 pdata)
clear [ColorBuffer]
bindFramebuffer Framebuffer $= (fst3 $ _fbo2 pdata)
depthFunc $= Just Always
--blend $= Disabled
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
clear [ColorBuffer]
--blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
blendFunc $= (One,Zero)
bindShaderBuffers [_boxBlurShader pdata] [4]
drawShader (_boxBlurShader pdata) 4
pingPongBlur pdata
--blend $= Enabled
blendFunc $= (SrcAlpha,OneMinusSrcAlpha)
bindFramebuffer Framebuffer $= (fst $ _fboLighting pdata)
let scPol = screenPolygon w
@@ -106,7 +120,8 @@ doDrawing pdata w = do
blendFunc $= (Zero, OneMinusSrcAlpha)
drawShader (_fullscreenShader pdata) 4
blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
--textureBinding Texture2D $= Just (snd $ _fboBloom pdata)
textureBinding Texture2D $= Just (snd3 $ _fbo2 pdata)
drawShader (_fullscreenShader pdata) 4
depthFunc $= Just Lequal
+1 -1
View File
@@ -51,7 +51,7 @@ preloadRender = do
fsShad <- makeShader "texture/simple" [vert,frag] [2,2] ETriangleStrip $ const cornerList
-- note we directly poke the shader vertex data here
pokeArray (_vboPointer $ _vaoVBO $ _shaderVAO fsShad) $ concat cornerList
boxBlurShad <- makeShader "texture/boxBlur" [vert,frag] [2,2] ETriangleStrip $ const cornerList
boxBlurShad <- makeShader "texture/bloomBlur" [vert,frag] [2,2] ETriangleStrip $ const cornerList
pokeArray (_vboPointer $ _vaoVBO $ _shaderVAO boxBlurShad) $ concat cornerList
grayscaleShad <- makeShader "texture/grayscale" [vert,frag] [2,2] ETriangleStrip $ const cornerList
pokeArray (_vboPointer $ _vaoVBO $ _shaderVAO grayscaleShad) $ concat cornerList
+3 -5
View File
@@ -61,17 +61,15 @@ createLightMap
-> [Point2]
-> IO ()
createLightMap pdata resDiv wallPoints lightPoints fpics scPol = do
depthFunc $= Just Less
-- get viewport size so we can reset it later
(vppos,vpsize) <- get viewport
-- set the viewport size to desired fidelity
let vsize = divideSize resDiv vpsize
viewport $= (vppos, vsize)
textureBinding Texture2D $= Just (snd $ _fboLighting pdata)
-- this is a problem! it should be resized once on screen/parameter resize
--texImage2D Texture2D NoProxy 0 RGBA8 (sizeToTexSize vsize) 0 (PixelData RGBA UnsignedByte nullPtr)
textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
generateMipmap' Texture2D
-- bindFramebuffer Framebuffer $= _spareFBO pdata
--textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
--generateMipmap' Texture2D
-- store wall and light positions into buffer
nWallLights <- F.foldM (pokeShader $ _lightingWallShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingWallShader pdata] [nWallLights]