Add hard edge to non-visible areas

This commit is contained in:
2021-06-30 13:52:14 +02:00
parent 1cfd1663d1
commit 532f491327
10 changed files with 68 additions and 56 deletions
+2 -2
View File
@@ -3,14 +3,14 @@ layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 4) out; layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos; uniform vec3 lightPos;
vec4 shift (vec4 p) { return (vec4 (p.xyz + (2000*(p.xyz-lightPos)), 1));} vec4 shift (vec4 p) { return (vec4 (p.xyz + (1000*(p.xyz-lightPos)), 1));}
vec4 f (vec4 p) {return (theMat * p);} vec4 f (vec4 p) {return (theMat * p);}
void main() void main()
{ {
vec4 p0 = gl_in[0].gl_Position; vec4 p0 = gl_in[0].gl_Position;
vec3 n0 = gl_in[2].gl_Position.xyz; vec3 n0 = gl_in[2].gl_Position.xyz;
vec3 n1 = gl_in[3].gl_Position.xyz; vec3 n1 = gl_in[3].gl_Position.xyz;
vec3 n2 = n0 + n1; // assumes the summands are normalized //vec3 n2 = n0 + n1; // assumes the summands are normalized
vec3 lightDir = p0.xyz - lightPos.xyz; vec3 lightDir = p0.xyz - lightPos.xyz;
// first test if the edge is part of the silhouette // first test if the edge is part of the silhouette
// that is, if the normals of the faces connected by the edge point in // that is, if the normals of the faces connected by the edge point in
+1 -1
View File
@@ -2,5 +2,5 @@
out vec4 fColor; out vec4 fColor;
void main() void main()
{ {
fColor = vec4 (0.9,0.5,0,0); fColor = vec4 (0.9,0.5,0,1);
} }
+24 -6
View File
@@ -34,18 +34,36 @@ vec4 a6 = theMat * p6;
vec4 a7 = theMat * p7; vec4 a7 = theMat * p7;
vec4 a8 = theMat * p8; vec4 a8 = theMat * p8;
gl_Position = a4; EmitVertex(); //gl_Position = a4; EmitVertex();
gl_Position = a3; EmitVertex(); //gl_Position = a3; EmitVertex();
gl_Position = a7; EmitVertex(); //gl_Position = a7; EmitVertex();
gl_Position = a8; EmitVertex(); //gl_Position = a8; EmitVertex();
//gl_Position = a5; EmitVertex();
//gl_Position = a3; EmitVertex();
//gl_Position = a1; EmitVertex();
//gl_Position = a4; EmitVertex();
//gl_Position = a2; EmitVertex();
//gl_Position = a7; EmitVertex();
//gl_Position = a6; EmitVertex();
gl_Position = a1; EmitVertex();
gl_Position = a5; EmitVertex(); gl_Position = a5; EmitVertex();
gl_Position = a3; EmitVertex(); gl_Position = a3; EmitVertex();
gl_Position = a1; EmitVertex(); gl_Position = a8; EmitVertex();
gl_Position = a4; EmitVertex(); gl_Position = a4; EmitVertex();
gl_Position = a2; EmitVertex();
gl_Position = a7; EmitVertex(); gl_Position = a7; EmitVertex();
gl_Position = a2; EmitVertex();
gl_Position = a6; EmitVertex(); gl_Position = a6; EmitVertex();
//gl_Position = a5; EmitVertex();
//gl_Position = a1; EmitVertex();
//gl_Position = a8; EmitVertex();
//gl_Position = a3; EmitVertex();
//gl_Position = a7; EmitVertex();
//gl_Position = a4; EmitVertex();
//gl_Position = a6; EmitVertex();
//gl_Position = a2; EmitVertex();
EndPrimitive(); EndPrimitive();
} else {} } else {}
} }
+2 -1
View File
@@ -11,7 +11,8 @@ float isLHS (vec2 startV, vec2 testV)
return sign( -startV.x * testV.y + startV.y * testV.x); return sign( -startV.x * testV.y + startV.y * testV.x);
} }
vec4 shiftCloser (vec4 v) vec4 shiftCloser (vec4 v)
{ return vec4 (v.xy , v.z-0.0001 , v.w) ; } { return vec4 (v.xy , v.z , v.w) ; }
//{ return vec4 (v.xy , v.z-0.0001 , v.w) ; }
void main() void main()
{ {
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
+2 -2
View File
@@ -21,8 +21,8 @@ void main()
vec4 a1 = theMat * p1; vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2; vec4 a2 = theMat * p2;
// if (0 > isLHS (a1.xy - a2.xy, a1.xy - "viewFromPoint")) { // if (0 > isLHS (a1.xy - a2.xy, a1.xy - "viewFromPoint")) {
vec4 p3 = vec4 (p1.xy,150,1); vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,150,1); vec4 p4 = vec4 (p2.xy,100,1);
vec4 a3 = theMat * p3; vec4 a3 = theMat * p3;
vec4 a4 = theMat * p4; vec4 a4 = theMat * p4;
+2 -2
View File
@@ -17,8 +17,8 @@ void main()
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1); vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1); vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p3 = vec4 (p1.xy,150,1); vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,150,1); vec4 p4 = vec4 (p2.xy,100,1);
vec4 a1 = theMat * p1; vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2; vec4 a2 = theMat * p2;
+1 -1
View File
@@ -17,7 +17,7 @@ import Dodge.WorldEvent.Sound
import Dodge.Creature.Update hiding (CRUpdate) import Dodge.Creature.Update hiding (CRUpdate)
import Picture import Picture
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import Geometry --import Geometry
import Geometry.Vector3D import Geometry.Vector3D
import Polyhedra import Polyhedra
+9 -1
View File
@@ -11,7 +11,7 @@ import Dodge.Base
--import Dodge.Render.MenuScreen --import Dodge.Render.MenuScreen
import Dodge.Render.Picture import Dodge.Render.Picture
--import Dodge.Render.PerspectiveMatrix --import Dodge.Render.PerspectiveMatrix
import Geometry --import Geometry
import Geometry.Data import Geometry.Data
--import Picture --import Picture
import Render import Render
@@ -67,6 +67,14 @@ doDrawing pdata w = do
createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms createLightMap pdata (w ^. config . shadow_resolution) wallPoints lightPoints viewFroms
(foregroundPics w) scPol (foregroundPics w) scPol
clear [DepthBuffer] clear [DepthBuffer]
nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 viewFromx viewFromy
drawShader (_lightingOccludeShader pdata) nWalls
depthFunc $= Just Less depthFunc $= Just Less
-- set blending to depend upon the alpha level already present -- set blending to depend upon the alpha level already present
blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One)) blendFuncSeparate $= ((SrcAlphaSaturate, OneMinusSrcAlpha), (Zero,One))
+1 -4
View File
@@ -51,10 +51,7 @@ diagonalLinesRect pa pb w d ang = zip lhsPoints $ map findDiPoint lhsPoints
highPipe :: Float -> Point2 -> Point2 -> [Polyhedra] highPipe :: Float -> Point2 -> Point2 -> [Polyhedra]
highPipe h x@(xx,xy) y = highPipe h x@(xx,xy) y =
[ Polyhedron . map (map ( (,orange) . (+.+.+ (xx,xy,h)))) [ Polyhedron . map (map ( (,orange) . (+.+.+ (xx,xy,h))))
$ boxABC (a,b,0) (a',b',0) (0,0,10) $ boxABC (a,b,0) (a',b',0) (0,0,5)
-- ,verticalPipe 5 orange x 0 100
-- ,verticalPipe 5 orange y 0 100
-- ,verticalPipe 5 orange (0.5 *.* (x +.+ y)) 50 100
] ]
where where
(a,b) = y -.- x (a,b) = y -.- x
+23 -35
View File
@@ -65,54 +65,48 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
-- set the viewport size to that of the render buffer -- set the viewport size to that of the render buffer
viewport $= (vppos, divideSize resDiv vpsize) viewport $= (vppos, divideSize resDiv vpsize)
bindFramebuffer Framebuffer $= _spareFBO pdata bindFramebuffer Framebuffer $= _spareFBO pdata
-- store wall and light positions into buffer -- store wall and light positions into buffer
nWallLights <- F.foldM (pokeShader $ _lightingWallShader pdata) (map Render22 wallPoints) nWallLights <- F.foldM (pokeShader $ _lightingWallShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingWallShader pdata] [nWallLights] bindShaderBuffers [_lightingWallShader pdata] [nWallLights]
nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints) nWalls <- F.foldM (pokeShader $ _lightingOccludeShader pdata) (map Render22 wallPoints)
bindShaderBuffers [_lightingOccludeShader pdata] [nWalls] bindShaderBuffers [_lightingOccludeShader pdata] [nWalls]
-- store foreground silhouette geometry into buffer -- store foreground silhouette geometry into buffer
nSils <- F.foldM (pokeShader $ _lightingLineShadowShader pdata) (concatMap polyToRender fpics) nSils <- F.foldM (pokeShader $ _lightingLineShadowShader pdata) (concatMap polyToRender fpics)
bindShaderBuffers [_lightingLineShadowShader pdata] [nSils] bindShaderBuffers [_lightingLineShadowShader pdata] [nSils]
-- store foreground geometry and floor into buffer -- store foreground geometry and floor into buffer
let addC (xx,yy) = (xx,yy,0) let addC (xx,yy) = (xx,yy,0)
nsurfVs <- F.foldM (pokeShader (_lightingSurfaceShader pdata)) nsurfVs <- F.foldM (pokeShader (_lightingSurfaceShader pdata))
$ [Render3 $ polyToTris $ map addC $ scPol ] $ [Render3 $ polyToTris $ map addC $ scPol ]
++ concatMap polyToGeoRender (fpics) ++ concatMap polyToGeoRender (fpics)
bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs] bindShaderBuffers [_lightingSurfaceShader pdata] [nsurfVs]
-- clear buffer to full alpha and furthest depth -- clear buffer to full alpha and furthest depth
-- clearColor is specified in preloadRender -- clearColor is specified in preloadRender
clear [ColorBuffer,DepthBuffer] clear [ColorBuffer,DepthBuffer]
-- draw walls from your point of view in order to set z buffer
colorMask $= Color4 Disabled Disabled Disabled Disabled
currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector2 viewFromx viewFromy
cullFace $= Just Back cullFace $= Just Back
drawShader (_lightingOccludeShader pdata) nWalls -- draw walls from your point of view in order to set z buffer
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
cullFace $= Nothing drawShader (_lightingWallShader pdata) nWallLights
--colorMask $= Color4 Disabled Disabled Disabled Disabled
--currentProgram $= Just (_shaderProgram $ _lightingOccludeShader pdata)
--uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
-- $= Vector2 viewFromx viewFromy
--drawShader (_lightingOccludeShader pdata) nWalls
---- draw foreground elements to set z buffer ---- draw foreground elements to set z buffer
--_ <- renderFoldable pdata $ picToLTree (Just 0) (polysToPic fpics)
currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata) currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata)
drawShader (_lightingSurfaceShader pdata) nsurfVs drawShader (_lightingSurfaceShader pdata) nsurfVs
-- for each of the lights: -- for each of the lights:
-- stencil out the walls from this light's point of view -- stencil out the walls from this light's point of view
-- draw fading lightmap circles on the floor -- draw fading lightmap circles on the floor
-- draw fading lightmaps on the walls -- draw fading lightmaps on the walls
--cullFace $= Nothing
depthMask $= Disabled depthMask $= Disabled
blendFunc $= (Zero, OneMinusSrcAlpha) blendFunc $= (Zero, OneMinusSrcAlpha)
stencilTest $= Enabled stencilTest $= Enabled
--depthFunc $= Just Less --depthFunc $= Just Less
forM_ lightPoints $ \((x,y,z),r,lum) -> do forM_ lightPoints $ \((x,y,z),r,lum) -> do
-- stencil out walls -- stencil out shadows
depthFunc $= Just Less --depthFunc $= Just Less
depthFunc $= Just Lequal
colorMask $= Color4 Disabled Disabled Disabled Disabled colorMask $= Color4 Disabled Disabled Disabled Disabled
clear [StencilBuffer] clear [StencilBuffer]
cullFace $= Just Back cullFace $= Just Back
@@ -122,7 +116,6 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata) uniform (head $ _shaderCustomUnis $ _lightingOccludeShader pdata)
$= Vector3 x y z $= Vector3 x y z
drawShader (_lightingOccludeShader pdata) nWalls drawShader (_lightingOccludeShader pdata) nWalls
--cullFace $= Nothing --cullFace $= Nothing
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata) currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata) uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata)
@@ -137,19 +130,18 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata) currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
drawShader (_lightingLineShadowShader pdata) nSils drawShader (_lightingLineShadowShader pdata) nSils
depthFunc $= Just Lequal depthFunc $= Just Lequal
-- draw floor light circles -- draw geometry surfaces
cullFace $= Nothing cullFace $= Just Back
colorMask $= Color4 Disabled Disabled Disabled Enabled colorMask $= Color4 Disabled Disabled Disabled Enabled
stencilFunc $= (Equal, 0, 255) stencilFunc $= (Equal, 0, 255)
-- draw floor surface
currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata) currentProgram $= Just (_shaderProgram $ _lightingSurfaceShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata) uniform (head $ _shaderCustomUnis $ _lightingSurfaceShader pdata)
$= Vector3 x y z $= Vector3 x y z
uniform (_shaderCustomUnis (_lightingSurfaceShader pdata) !! 1) uniform (_shaderCustomUnis (_lightingSurfaceShader pdata) !! 1)
$= Vector2 r lum $= Vector2 r lum
drawShader (_lightingSurfaceShader pdata) nsurfVs drawShader (_lightingSurfaceShader pdata) nsurfVs
-- draw wall light "circles"
-- draw wall light "circles" --cullFace $= Nothing
currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata) currentProgram $= Just (_shaderProgram $ _lightingWallShader pdata)
uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata) uniform (head $ _shaderCustomUnis $ _lightingWallShader pdata)
$= Vector3 x y z $= Vector3 x y z
@@ -159,30 +151,26 @@ createLightMap pdata resDiv wallPoints lightPoints (viewFromx,viewFromy) fpics s
cullFace $= Nothing cullFace $= Nothing
stencilTest $= Disabled stencilTest $= Disabled
blend $= Disabled blend $= Disabled
-- set the viewport size to that of the window
-- set the viewport size to that of the window
viewport $= (vppos, vpsize) viewport $= (vppos, vpsize)
-- disable depth testing for blurring -- disable depth testing for blurring
depthFunc $= Just Always depthFunc $= Just Always
-- draw the lightmap on a full size fbo -- draw the lightmap on a full size fbo
bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata) bindFramebuffer Framebuffer $= fst3 (_fbo2 pdata)
colorMask $= Color4 Disabled Disabled Disabled Enabled colorMask $= Color4 Disabled Disabled Disabled Enabled
bindShaderBuffers [_boxBlurShader pdata] [4] bindShaderBuffers [_boxBlurShader pdata] [4]
textureBinding Texture2D $= Just (_fboTexture pdata) textureBinding Texture2D $= Just (_fboTexture pdata)
-- by upscaling the shadowmap texture and using Linear' magnification -- by upscaling the shadowmap texture and using Linear' magnification
-- interpolation, we get a poor mans blur, not sure about performance -- interpolation, we get a poor mans blur, not sure about performance
textureFilter Texture2D $= ((Linear',Just Linear') , Linear') textureFilter Texture2D $= ((Linear',Just Linear') , Linear')
generateMipmap' Texture2D generateMipmap' Texture2D
drawShader (_boxBlurShader pdata) 4 drawShader (_boxBlurShader pdata) 4
-- ping pong blur between '_fbo2' and '_fbo3' as many times as desired
-- ping pong blur between '_fbo2' and '_fbo3' as many times as desired
replicateM_ 3 $ pingPongBlur pdata replicateM_ 3 $ pingPongBlur pdata
-- reset drawing parameters ready for drawing on top of the light map
-- reset drawing parameters ready for drawing on top of the light map
colorMask $= Color4 Enabled Enabled Enabled Enabled colorMask $= Color4 Enabled Enabled Enabled Enabled
depthMask $= Enabled depthMask $= Enabled
blend $= Enabled blend $= Enabled
{- | {- |
Blur between two framebuffers. Blur between two framebuffers.
Assumes no depth testing is done (depthFunc %= Just Always). Assumes no depth testing is done (depthFunc %= Just Always).