Move towards pixel upscaling filter
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
in vec4 vTexPosRot;
|
in vec4 vTexPosRot;
|
||||||
in vec2 vPos;
|
in vec2 vPos;
|
||||||
layout (location=0) out vec4 fCol;
|
layout (location=0) out vec4 fCol;
|
||||||
layout (location=1) out vec4 fPos;
|
layout (location=1) out vec3 fPos;
|
||||||
layout (location=2) out vec4 normal;
|
layout (location=2) out vec4 normal;
|
||||||
layout (binding=40) uniform sampler2DArray diffuseSampler;
|
layout (binding=40) uniform sampler2DArray diffuseSampler;
|
||||||
layout (binding=41) uniform sampler2DArray normalSampler;
|
layout (binding=41) uniform sampler2DArray normalSampler;
|
||||||
@@ -15,9 +15,9 @@ void main()
|
|||||||
vec3 vTexPos = vTexPosRot.xyz;
|
vec3 vTexPos = vTexPosRot.xyz;
|
||||||
float rot = vTexPosRot.w;
|
float rot = vTexPosRot.w;
|
||||||
fCol = vec4(texture(diffuseSampler,vTexPos));
|
fCol = vec4(texture(diffuseSampler,vTexPos));
|
||||||
fPos = vec4(vPos,0,1);
|
fPos = vec3(vPos,0);
|
||||||
vec4 bn = vec4(texture(normalSampler,vTexPos) - 0.5);
|
vec4 bn = vec4(texture(normalSampler,vTexPos) - 0.5);
|
||||||
vec3 nmap1 = vec3(rotateV2(rot,bn.xy), bn.z);
|
vec3 nmap1 = vec3(rotateV2(rot,bn.xy), bn.z);
|
||||||
normal = vec4(-nmap1 ,0);
|
normal = vec4(-nmap1.xyz ,0);
|
||||||
//normal = vec4(0,0,-1 ,0);
|
//normal = vec4(0,0,-1 ,0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,13 +13,22 @@ void main() {
|
|||||||
// if (dist > rad) {
|
// if (dist > rad) {
|
||||||
// discard;
|
// discard;
|
||||||
// }
|
// }
|
||||||
|
float t = texture(normals, vTexPos).w;
|
||||||
vec3 norm = texture(normals, vTexPos).xyz;
|
vec3 norm = texture(normals, vTexPos).xyz;
|
||||||
float y1 = dot(norm, distVec);
|
float y1 = dot(normalize(norm), normalize(distVec));
|
||||||
float y2 = float(y1 > 0 ? 1 : 0);
|
float y2 = float(y1 > 0 ? 1 : 0);
|
||||||
float x = 1 - (pow(dist / rad,4));
|
//float y2x = y2;
|
||||||
|
float y4 = float(y1 > 0 && y1 < 0.5 ? 0.5 : y2);
|
||||||
|
float y5 = max(0,y1);
|
||||||
|
//float y4 = smoothstep(-1,1,y1);
|
||||||
|
//float y4 = 0.25*pow(y1+1,2);
|
||||||
|
float y3 = float(t > 0
|
||||||
|
? y2
|
||||||
|
: (t == 0 ? y4 : y4));
|
||||||
//float x = 1 - (dist / rad);
|
//float x = 1 - (dist / rad);
|
||||||
//float x = 1;
|
//float x = 1;
|
||||||
//float x = (dist > rad ? 0 : 1);
|
//float x = (dist > rad ? 0 : 1);
|
||||||
vec3 c = y2* x * lumRad.rgb;
|
float x = 1 - (pow(dist / rad,4));
|
||||||
|
vec3 c = y3* x * lumRad.rgb;
|
||||||
fColor = vec4(c, 0);
|
fColor = vec4(c, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#version 450 core
|
#version 450 core
|
||||||
layout (location=0) out vec4 fCol;
|
layout (location=0) out vec4 fCol;
|
||||||
layout (location=1) out vec4 fPos;
|
layout (location=1) out vec3 fPos;
|
||||||
layout (location=2) out vec4 fNorm;
|
layout (location=2) out vec4 fNorm;
|
||||||
in vec3 vTexCoords;
|
in vec3 vTexCoords;
|
||||||
in vec4 vPos;
|
in vec4 vPos;
|
||||||
@@ -12,7 +12,7 @@ vec2 rotateV2 (float a, vec2 v)
|
|||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fCol = texture(diffuseSampler,vTexCoords);
|
fCol = texture(diffuseSampler,vTexCoords);
|
||||||
fPos = vPos;
|
fPos = vPos.xyz;
|
||||||
vec4 basenorm = texture(normalSampler,vTexCoords) - 0.5;
|
vec4 basenorm = texture(normalSampler,vTexCoords) - 0.5;
|
||||||
vec2 n1 = rotateV2(vAng,vec2(basenorm.x,basenorm.z));
|
vec2 n1 = rotateV2(vAng,vec2(basenorm.x,basenorm.z));
|
||||||
fNorm = vec4(-vec3(n1,basenorm.y),0);
|
fNorm = vec4(-vec3(n1,basenorm.y),0);
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ in vec4 vPos;
|
|||||||
in vec4 vNorm;
|
in vec4 vNorm;
|
||||||
layout (location=0) out vec4 fCol;
|
layout (location=0) out vec4 fCol;
|
||||||
layout (location=1) out vec3 fPos;
|
layout (location=1) out vec3 fPos;
|
||||||
layout (location=2) out vec3 fNorm;
|
layout (location=2) out vec4 fNorm;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fCol = vCol;
|
fCol = vCol;
|
||||||
fPos = vPos.xyz;
|
fPos = vPos.xyz;
|
||||||
fNorm = vNorm.xyz;
|
//fNorm = vec4(vNorm.xyz,1);
|
||||||
|
fNorm = vNorm;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
#version 450 core
|
||||||
|
in vec2 vTexPos;
|
||||||
|
out vec4 fColor;
|
||||||
|
layout (location = 0) uniform vec2 screensize;
|
||||||
|
layout(binding = 0) uniform sampler2D screenTexture;
|
||||||
|
float xoff = 2 / screensize.x;
|
||||||
|
float yoff = 2 / screensize.y;
|
||||||
|
vec3 f (float x, float y)
|
||||||
|
{ return texture(screenTexture, vTexPos + vec2(x*xoff,y*yoff)).xyz;
|
||||||
|
}
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 tl = f(-1, 1);
|
||||||
|
vec3 tt = f( 0, 1);
|
||||||
|
vec3 tr = f( 1, 1);
|
||||||
|
vec3 mr = f( 1, 0);
|
||||||
|
vec3 br = f( 1,-1);
|
||||||
|
if (tl == tt && tt == tr && tr == mr && mr == br)
|
||||||
|
{ fColor = vec4(tl,1);}
|
||||||
|
else {fColor = texture(screenTexture, vTexPos); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#version 450 core
|
||||||
|
layout (std140, binding = 2) uniform PosTex { vec4 posTex[3]; };
|
||||||
|
out vec2 vTexPos;
|
||||||
|
void main() {
|
||||||
|
gl_Position = vec4(posTex[gl_VertexID].xy,0,1);
|
||||||
|
vTexPos = posTex[gl_VertexID].zw ;
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#version 450 core
|
|
||||||
in vec3 vTexPos;
|
|
||||||
in vec3 vPos;
|
|
||||||
layout (location=0) out vec4 fCol;
|
|
||||||
layout (location=1) out vec4 fPos;
|
|
||||||
layout (location=2) out vec4 normal;
|
|
||||||
//layout (binding=0) uniform sampler2DArray tilesetSampler;
|
|
||||||
layout (binding=1) uniform sampler2D normalSampler;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
//fCol = texture(tilesetSampler, vec3(0.3,0.1,0) + vTexPos);
|
|
||||||
fCol = vec4(0.2,0.3,0.6,1);
|
|
||||||
//fCol = vec4(0.6,0.4,0.3,1);
|
|
||||||
fPos = vec4(vPos,1);
|
|
||||||
normal = vec4(vec3(0.5) - texture(normalSampler,2*vTexPos.xy).xyz,0);
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#version 450 core
|
|
||||||
layout (location = 0) in vec3 pos;
|
|
||||||
layout (location = 1) in vec3 texPos;
|
|
||||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
|
||||||
out vec3 vTexPos;
|
|
||||||
out vec3 vPos;
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = theMat * vec4(pos,1.0) ;
|
|
||||||
vTexPos = texPos;
|
|
||||||
vPos = pos;
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,7 @@ data RenderData = RenderData
|
|||||||
, _windowPullShader :: GLuint
|
, _windowPullShader :: GLuint
|
||||||
, _pullWallShader :: GLuint
|
, _pullWallShader :: GLuint
|
||||||
, _fullscreenShader :: GLuint
|
, _fullscreenShader :: GLuint
|
||||||
|
, _textureAntiaShader :: GLuint
|
||||||
, _bloomBlurShader :: GLuint
|
, _bloomBlurShader :: GLuint
|
||||||
, _barrelShader :: (GLuint,VBO)
|
, _barrelShader :: (GLuint,VBO)
|
||||||
, _shapeShader :: GLuint
|
, _shapeShader :: GLuint
|
||||||
|
|||||||
+2
-1
@@ -367,7 +367,8 @@ doDrawing' win pdata u = do
|
|||||||
[] -> do
|
[] -> do
|
||||||
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
|
glBindTextureUnit 0 $ pdata ^. fboBase . _2 . _1 . unTO
|
||||||
glBindFramebuffer GL_FRAMEBUFFER 0
|
glBindFramebuffer GL_FRAMEBUFFER 0
|
||||||
glUseProgram (pdata ^. fullscreenShader)
|
glUseProgram (pdata ^. textureAntiaShader)
|
||||||
|
glUniform2f 0 (windowXFloat cfig) (windowYFloat cfig)
|
||||||
--glDrawArrays GL_TRIANGLES 0 6
|
--glDrawArrays GL_TRIANGLES 0 6
|
||||||
glDrawArrays GL_TRIANGLES 0 3
|
glDrawArrays GL_TRIANGLES 0 3
|
||||||
rs' -> do
|
rs' -> do
|
||||||
|
|||||||
@@ -21,17 +21,29 @@ import Unsafe.Coerce
|
|||||||
sizeFBOs :: Config -> RenderData -> IO RenderData
|
sizeFBOs :: Config -> RenderData -> IO RenderData
|
||||||
sizeFBOs cfig rdata =
|
sizeFBOs cfig rdata =
|
||||||
uncurryV (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _gr_world_res cfig)
|
uncurryV (resizeRBO (_rboBaseBloom rdata)) (getWindowSize _gr_world_res cfig)
|
||||||
>> updateFBOTO3
|
-- >> updateFBOTO3
|
||||||
|
-- (getWindowSize _gr_world_res cfig)
|
||||||
|
-- GL_NEAREST
|
||||||
|
-- GL_NEAREST
|
||||||
|
-- GL_RGB16F -- RGBAF not sure if the alpha is necessary here
|
||||||
|
-- GL_RGB16F -- could possibly recover using depth in a clever way
|
||||||
|
-- -- but probably not, because the projection matrix is
|
||||||
|
-- -- not always on-center
|
||||||
|
-- GL_RGBA8_SNORM
|
||||||
|
-- rdata
|
||||||
|
-- fboBase
|
||||||
|
>> fboBase (resizeFBOTO3'
|
||||||
(getWindowSize _gr_world_res cfig)
|
(getWindowSize _gr_world_res cfig)
|
||||||
GL_NEAREST
|
GL_NEAREST
|
||||||
GL_NEAREST
|
GL_NEAREST
|
||||||
GL_RGBA16F -- not sure if the alpha is necessary here
|
GL_NEAREST
|
||||||
|
GL_NEAREST
|
||||||
|
GL_RGB16F -- RGBAF not sure if the alpha is necessary here
|
||||||
GL_RGB16F -- could possibly recover using depth in a clever way
|
GL_RGB16F -- could possibly recover using depth in a clever way
|
||||||
-- but probably not, because the projection matrix is
|
-- but probably not, because the projection matrix is
|
||||||
-- not always on-center
|
-- not always on-center
|
||||||
GL_RGB8_SNORM
|
GL_RGBA8_SNORM)
|
||||||
rdata
|
rdata
|
||||||
fboBase
|
|
||||||
>>= flip
|
>>= flip
|
||||||
(
|
(
|
||||||
updateFBOTO3
|
updateFBOTO3
|
||||||
@@ -181,8 +193,39 @@ resizeFBOTO3 (fbo, (told1, told2, told3)) xsize ysize minfilt magfilt form1 form
|
|||||||
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form1
|
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize minfilt magfilt form1
|
||||||
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
|
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
|
||||||
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3
|
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3
|
||||||
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $ \ptr ->
|
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
|
||||||
glNamedFramebufferDrawBuffers (_unFBO fbo) 3 ptr
|
glNamedFramebufferDrawBuffers (_unFBO fbo) 3
|
||||||
|
checkFBO fbo
|
||||||
|
return (fbo, (TO to1, TO to2, TO to3))
|
||||||
|
|
||||||
|
resizeFBOTO3' ::
|
||||||
|
V2 Int ->
|
||||||
|
-- | minification filter
|
||||||
|
GLenum ->
|
||||||
|
-- | magnification filter
|
||||||
|
GLenum ->
|
||||||
|
-- | minification filter
|
||||||
|
GLenum ->
|
||||||
|
-- | magnification filter
|
||||||
|
GLenum ->
|
||||||
|
-- | internal color format1
|
||||||
|
GLenum ->
|
||||||
|
-- | internal color format2
|
||||||
|
GLenum ->
|
||||||
|
-- | internal color format3
|
||||||
|
GLenum ->
|
||||||
|
(FBO, (TO, TO, TO)) ->
|
||||||
|
IO (FBO, (TO, TO, TO))
|
||||||
|
resizeFBOTO3' (V2 xsize ysize) min1 mag1 minfilt magfilt form1 form2 form3 (fbo, (told1, told2, told3)) = do
|
||||||
|
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
|
||||||
|
mglDelete glDeleteTextures $ _unTO told1
|
||||||
|
mglDelete glDeleteTextures $ _unTO told2
|
||||||
|
mglDelete glDeleteTextures $ _unTO told3
|
||||||
|
to1 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT0 xsize ysize min1 mag1 form1
|
||||||
|
to2 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT1 xsize ysize minfilt magfilt form2
|
||||||
|
to3 <- initializeTexture2D fbo GL_COLOR_ATTACHMENT2 xsize ysize minfilt magfilt form3
|
||||||
|
withArray [GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2] $
|
||||||
|
glNamedFramebufferDrawBuffers (_unFBO fbo) 3
|
||||||
checkFBO fbo
|
checkFBO fbo
|
||||||
return (fbo, (TO to1, TO to2, TO to3))
|
return (fbo, (TO to1, TO to2, TO to3))
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ preloadRender = do
|
|||||||
putStrLn "Setup full screen shaders"
|
putStrLn "Setup full screen shaders"
|
||||||
alphadivideshader <- makeSourcedShader "texture2D/alphaDivide" [vert, frag]
|
alphadivideshader <- makeSourcedShader "texture2D/alphaDivide" [vert, frag]
|
||||||
fsShad <- makeSourcedShader "texture/simple" [vert, frag]
|
fsShad <- makeSourcedShader "texture/simple" [vert, frag]
|
||||||
|
textureantiashad <- makeSourcedShader "texture/antia" [vert,frag]
|
||||||
bloomBlurShad <- makeSourcedShader "texture/bloomBlur" [vert, frag]
|
bloomBlurShad <- makeSourcedShader "texture/bloomBlur" [vert, frag]
|
||||||
lightingTextureShad <- makeSourcedShader "lighting/texture" [vert, frag]
|
lightingTextureShad <- makeSourcedShader "lighting/texture" [vert, frag]
|
||||||
lightingCloudShad <- makeSourcedShader "lighting/cloud" [vert, frag]
|
lightingCloudShad <- makeSourcedShader "lighting/cloud" [vert, frag]
|
||||||
@@ -150,8 +151,9 @@ preloadRender = do
|
|||||||
flptr <- mallocArray (8 * 65536)
|
flptr <- mallocArray (8 * 65536)
|
||||||
let floorvbo = VBO flvbo flptr (8 * floatSize)
|
let floorvbo = VBO flvbo flptr (8 * floatSize)
|
||||||
floorshader <- makeSourcedShader "floor/arrayPos" [vert, frag]
|
floorshader <- makeSourcedShader "floor/arrayPos" [vert, frag]
|
||||||
initTexture2DArraySquare 40 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/diffuseArray.png"
|
initTexture2DArraySquare 40 5 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/diffuseArray.png"
|
||||||
initTexture2DArraySquare 41 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png"
|
initTexture2DArraySquare 41 5 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png"
|
||||||
|
-- initTexture2DArraySquare 41 3 GL_NEAREST_MIPMAP_LINEAR GL_LINEAR "data/normalMaps/normalArray.png"
|
||||||
|
|
||||||
putStrLn "Setup chasm VBO, shader"
|
putStrLn "Setup chasm VBO, shader"
|
||||||
chvbo <- mglCreate glCreateBuffers
|
chvbo <- mglCreate glCreateBuffers
|
||||||
@@ -196,6 +198,7 @@ preloadRender = do
|
|||||||
, _ceilingStencilShader = ceilingstencilshader
|
, _ceilingStencilShader = ceilingstencilshader
|
||||||
, _windowPullShader = winpull
|
, _windowPullShader = winpull
|
||||||
, _pullWallShader = wallpull
|
, _pullWallShader = wallpull
|
||||||
|
, _textureAntiaShader = textureantiashad
|
||||||
, _fullscreenShader = fsShad
|
, _fullscreenShader = fsShad
|
||||||
, _alphaDivideShader = alphadivideshader
|
, _alphaDivideShader = alphadivideshader
|
||||||
, _lightingTextureShader = lightingTextureShad
|
, _lightingTextureShader = lightingTextureShad
|
||||||
|
|||||||
+2
-2
@@ -455,7 +455,7 @@ pokeFlatV ::
|
|||||||
{-# INLINE pokeFlatV #-}
|
{-# INLINE pokeFlatV #-}
|
||||||
pokeFlatV xdata pnorm col ptr nv sh = do
|
pokeFlatV xdata pnorm col ptr nv sh = do
|
||||||
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
|
pokeByteOff ptr (nv * shapeVerxSize) (V4 x y z xdata)
|
||||||
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz 1)
|
pokeByteOff ptr (nv *shapeVerxSize + 4 * floatSize) (normalTo8 $ V4 nx ny nz (-1))
|
||||||
pokeByteOff ptr (nv *shapeVerxSize + 5 * floatSize) (toColor8 col)
|
pokeByteOff ptr (nv *shapeVerxSize + 5 * floatSize) (toColor8 col)
|
||||||
return (nv + 1)
|
return (nv + 1)
|
||||||
where
|
where
|
||||||
@@ -463,7 +463,7 @@ pokeFlatV xdata pnorm col ptr nv sh = do
|
|||||||
V3 nx ny nz = (sh - pnorm) - V3 x y z
|
V3 nx ny nz = (sh - pnorm) - V3 x y z
|
||||||
|
|
||||||
normalTo8 :: Point4 -> V4 Int8
|
normalTo8 :: Point4 -> V4 Int8
|
||||||
normalTo8 = over each f . normalize
|
normalTo8 = over each f . over _xyz normalize
|
||||||
where
|
where
|
||||||
f x = floor $ x * 127
|
f x = floor $ x * 127
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user