Work on geometry shader based shadows

This commit is contained in:
2023-03-11 22:59:19 +00:00
parent 5724a0543e
commit 7ee3f6581d
18 changed files with 235 additions and 144 deletions
+2
View File
@@ -9,6 +9,7 @@ layout (std140, binding = 1) uniform LightsBlock
} ; } ;
uniform int lightID; uniform int lightID;
vec3 lightPos = posBool[lightID].xyz ; vec3 lightPos = posBool[lightID].xyz ;
float theBool = posBool[gl_InvocationID].w;
// this code is duplicated in lineShadow.geom, should not be changed on its own // this code is duplicated in lineShadow.geom, should not be changed on its own
vec4 projNear (vec4 pos) vec4 projNear (vec4 pos)
{ {
@@ -29,6 +30,7 @@ void main()
( p0.z - lightPos.z > 0 ) ( p0.z - lightPos.z > 0 )
&& ( p1.z - lightPos.z > 0 ) && ( p1.z - lightPos.z > 0 )
&& ( p2.z - lightPos.z > 0 ) && ( p2.z - lightPos.z > 0 )
&& theBool == 1
) )
{ {
// the front cap // the front cap
+9
View File
@@ -0,0 +1,9 @@
#version 450 core
uniform sampler2DArray screenTexture;
in vec3 gTexPos;
out vec4 fColor;
void main()
{
fColor = texture(screenTexture,gTexPos);
//fColor = vec4(0.05,0.01,0,1);
}
+30
View File
@@ -0,0 +1,30 @@
#version 450 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (invocations = 20) in;
layout (std140, binding = 1) uniform LightsBlock
{
vec4 posBool[20];
vec4 colRad[20];
} ;
out vec3 gTexPos;
float theBool = posBool[gl_InvocationID].w;
float l = gl_InvocationID;
void main()
{
if (theBool == 1){
gTexPos = vec3(0,1,l);
gl_Position = vec4(-1,1,0,1) ;
EmitVertex();
gTexPos = vec3(0,0,l);
gl_Position = vec4(-1,-1,0,1) ;
EmitVertex();
gTexPos = vec3(1,1,l);
gl_Position = vec4(1,1,0,1) ;
EmitVertex();
gTexPos = vec3(1,0,l);
gl_Position = vec4(1,-1,0,1) ;
EmitVertex();
EndPrimitive();
}else {}
}
+4
View File
@@ -0,0 +1,4 @@
#version 450 core
void main()
{
}
+12 -12
View File
@@ -1,5 +1,6 @@
#version 450 core #version 450 core
layout (lines_adjacency) in; layout (lines_adjacency) in;
layout (invocations = 20) 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; } ;
layout (std140, binding = 1) uniform LightsBlock layout (std140, binding = 1) uniform LightsBlock
@@ -7,9 +8,8 @@ layout (std140, binding = 1) uniform LightsBlock
vec4 posBool[20]; vec4 posBool[20];
vec4 colRad[20]; vec4 colRad[20];
} ; } ;
uniform int lightID; vec3 lightPos1 = posBool[gl_InvocationID].xyz;
vec3 lightPos1 = posBool[lightID].xyz; float theBool = posBool[gl_InvocationID].w;
float theBool = posBool[lightID].w;
vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos1)), 1));} ; vec4 shift (vec4 p) { return (vec4 (p.xyz + (100000*(p.xyz-lightPos1)), 1));} ;
vec4 shiftBy (float x,vec4 p) { return (vec4 (lightPos1 + (x*normalize(p.xyz-lightPos1)), 1));} ; vec4 shiftBy (float x,vec4 p) { return (vec4 (lightPos1 + (x*normalize(p.xyz-lightPos1)), 1));} ;
// copied from lighting/cap.geom, should not be changed on its own // copied from lighting/cap.geom, should not be changed on its own
@@ -34,7 +34,7 @@ void main()
{ {
if (theBool == 1){ if (theBool == 1){
// float ru2 = radiusUniform * radiusUniform ; // float ru2 = radiusUniform * radiusUniform ;
float ru = colRad[lightID].w ; float ru = colRad[gl_InvocationID].w ;
float ru2 = ru * ru; float ru2 = ru * ru;
vec4 p0 = gl_in[0].gl_Position; vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position; vec4 p1 = gl_in[1].gl_Position;
@@ -59,17 +59,17 @@ void main()
vec4 p3 = shiftNear(p1); vec4 p3 = shiftNear(p1);
if ( dot(n0 , lightDir) > 0) if ( dot(n0 , lightDir) > 0)
{ {
gl_Position = f(p0); EmitVertex(); gl_Position = f(p0); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p1); EmitVertex(); gl_Position = f(p1); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p2); EmitVertex(); gl_Position = f(p2); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p3); EmitVertex(); gl_Position = f(p3); gl_Layer = gl_InvocationID; EmitVertex();
} }
else else
{ {
gl_Position = f(p1); EmitVertex(); gl_Position = f(p1); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p0); EmitVertex(); gl_Position = f(p0); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p3); EmitVertex(); gl_Position = f(p3); gl_Layer = gl_InvocationID; EmitVertex();
gl_Position = f(p2); EmitVertex(); gl_Position = f(p2); gl_Layer = gl_InvocationID; EmitVertex();
} }
EndPrimitive(); EndPrimitive();
} }
+4 -3
View File
@@ -8,14 +8,15 @@ uniform int lightID;
vec3 lightPos = posBool[lightID].xyz; vec3 lightPos = posBool[lightID].xyz;
vec4 lumRad = colRad[lightID]; vec4 lumRad = colRad[lightID];
uniform sampler2D screenTexture; uniform sampler2D screenTexture;
in vec2 vTexPos; in vec2 gTexPos;
out vec4 fColor; out vec4 fColor;
void main() void main()
{ {
vec3 distVec = texture(screenTexture,vTexPos).xyz - lightPos; vec3 distVec = texture(screenTexture,gTexPos).xyz - lightPos;
float dist = dot(distVec,distVec); float dist = dot(distVec,distVec);
if (dist > lumRad.a) {discard;} if (dist > lumRad.a) {discard;}
float x = 1 - dist / lumRad.a ; float x = 1 - dist / lumRad.a ;
vec3 c = (x * x * x) * lumRad.rgb ; vec3 c = (x * x * x) * lumRad.rgb ;
fColor = vec4(c,0); //fColor = vec4(c,0);
fColor = vec4(1,0,0,0);
} }
+25
View File
@@ -0,0 +1,25 @@
#version 450 core
layout (triangles) in;
layout (triangle_strip, max_vertices = 3) out;
layout (invocations = 20) in;
layout (std140, binding = 1) uniform LightsBlock
{
vec4 posBool[20];
vec4 colRad[20];
} ;
float theBool = posBool[gl_InvocationID].w;
in vec2 vTexPos[];
out vec2 gTexPos;
void main()
{
if (theBool == 1){
for (int i = 0; i < 3; i++)
{
gTexPos = vTexPos[i];
gl_Layer = gl_InvocationID;
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}else {}
}
+12 -32
View File
@@ -1,5 +1,6 @@
#version 450 core #version 450 core
layout (points) in; layout (points) in;
layout (invocations = 20) in;
layout (triangle_strip, max_vertices = 8) out; layout (triangle_strip, max_vertices = 8) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ; layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
layout (std140, binding = 1) uniform LightsBlock layout (std140, binding = 1) uniform LightsBlock
@@ -7,8 +8,8 @@ layout (std140, binding = 1) uniform LightsBlock
vec4 posBool[20]; vec4 posBool[20];
vec4 colRad[20]; vec4 colRad[20];
} ; } ;
uniform int lightID; vec3 lightPos = posBool[gl_InvocationID].xyz;
vec3 lightPos = posBool[lightID].xyz; float theBool = posBool[gl_InvocationID].w;
vec4 shift (vec4 p) vec4 shift (vec4 p)
{ return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0 , 1); { return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0 , 1);
} }
@@ -21,7 +22,7 @@ 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);
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0) if (theBool==1 && isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{ {
vec4 p3 = vec4 (p1.xy,100,1); vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,100,1); vec4 p4 = vec4 (p2.xy,100,1);
@@ -39,35 +40,14 @@ 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 = a1; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a3; EmitVertex(); gl_Position = a5; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a7; EmitVertex(); gl_Position = a3; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a8; EmitVertex(); gl_Position = a8; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a5; EmitVertex(); gl_Position = a4; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a3; EmitVertex(); gl_Position = a7; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a1; EmitVertex(); gl_Position = a2; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a4; EmitVertex(); gl_Position = a6; gl_Layer = gl_InvocationID; EmitVertex();
//gl_Position = a2; EmitVertex();
//gl_Position = a7; EmitVertex();
//gl_Position = a6; EmitVertex();
gl_Position = a1; EmitVertex();
gl_Position = a5; EmitVertex();
gl_Position = a3; EmitVertex();
gl_Position = a8; EmitVertex();
gl_Position = a4; EmitVertex();
gl_Position = a7; EmitVertex();
gl_Position = a2; 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 {}
+1
View File
@@ -23,6 +23,7 @@ data RenderData = RenderData
, _shadowCapShader :: FullShader , _shadowCapShader :: FullShader
, _shadowWallShader :: FullShader , _shadowWallShader :: FullShader
, _shadowLightShader :: FullShader , _shadowLightShader :: FullShader
, _shadowCombineShader :: FullShader
, _positionalBlankShader :: FullShader , _positionalBlankShader :: FullShader
, _wallBlankShader :: FullShader , _wallBlankShader :: FullShader
, _windowShader :: FullShader , _windowShader :: FullShader
+2 -1
View File
@@ -27,7 +27,8 @@ data Input = Input
, _rSelect :: Point2 , _rSelect :: Point2
, _clickMousePos :: Point2 , _clickMousePos :: Point2
, _textInput :: String , _textInput :: String
, _scrollTestValue :: Float , _scrollTestFloat :: Float
, _scrollTestInt :: Int
} }
makeLenses ''Input makeLenses ''Input
+2 -1
View File
@@ -26,7 +26,8 @@ defaultInput =
, _rLine = (0, 0) , _rLine = (0, 0)
, _lSelect = 0 , _lSelect = 0
, _rSelect = 0 , _rSelect = 0
, _scrollTestValue = 1 , _scrollTestFloat = 1
, _scrollTestInt = 0
} }
defaultWorld :: World defaultWorld :: World
+20 -1
View File
@@ -3,6 +3,7 @@ module Dodge.Render (
doDrawing, doDrawing,
) where ) where
import qualified Data.Map.Strict as M
import Picture.Base import Picture.Base
import qualified SDL import qualified SDL
import qualified Data.Vector as V import qualified Data.Vector as V
@@ -31,8 +32,18 @@ import Shader.Parameters
import Shader.Poke import Shader.Poke
doDrawing :: SDL.Window -> RenderData -> Universe -> IO () doDrawing :: SDL.Window -> RenderData -> Universe -> IO ()
doDrawing win pdata u = do doDrawing window rdata u
| SDL.ScancodeT `M.member` (u ^. uvWorld . input . pressedKeys) = doTestDrawing rdata u
| otherwise = doDrawing' window rdata u
doTestDrawing :: RenderData -> Universe -> IO ()
doTestDrawing _ _ = do
return ()
doDrawing' :: SDL.Window -> RenderData -> Universe -> IO ()
doDrawing' win pdata u = do
--sTicks <- SDL.ticks --sTicks <- SDL.ticks
checkGLError
let w = _uvWorld u let w = _uvWorld u
cfig = _uvConfig u cfig = _uvConfig u
rot = w ^. cWorld . camPos . camRot rot = w ^. cWorld . camPos . camRot
@@ -139,6 +150,7 @@ doDrawing win pdata u = do
--bindFramebuffer Framebuffer $= fst (_fboLighting pdata) --bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
createLightMap createLightMap
cfig
pdata pdata
lightPoints lightPoints
nWalls nWalls
@@ -212,6 +224,7 @@ doDrawing win pdata u = do
--bindFramebuffer Framebuffer $= fst (_fboLighting pdata) --bindFramebuffer Framebuffer $= fst (_fboLighting pdata)
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata))) glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
createLightMap createLightMap
cfig
pdata pdata
lightPoints lightPoints
nWalls nWalls
@@ -352,3 +365,9 @@ renderTextureWalls pdata nWalls = do
glDisable GL_CULL_FACE glDisable GL_CULL_FACE
--cullFace $= Nothing --cullFace $= Nothing
checkGLError :: IO ()
checkGLError = do
err <- glGetError
case err of
0 -> return ()
i -> error $ "OpenGL error: " ++ show i
+4 -2
View File
@@ -4,6 +4,8 @@ import Dodge.Data.Input
import LensHelp import LensHelp
updateScrollTestValue :: Input -> Input updateScrollTestValue :: Input -> Input
updateScrollTestValue theinput = theinput & scrollTestValue +~ theamount updateScrollTestValue theinput = theinput & scrollTestFloat +~ theamount
& scrollTestInt +~ i
where where
theamount = fromIntegral (theinput ^. scrollAmount) / 100 i = theinput ^. scrollAmount
theamount = fromIntegral i / 100
+3 -1
View File
@@ -15,7 +15,9 @@ testStringInit :: Universe -> [String]
testStringInit u = [show $ length $ lightsToRender (u ^. uvConfig) (u ^. uvWorld . cWorld . camPos) testStringInit u = [show $ length $ lightsToRender (u ^. uvConfig) (u ^. uvWorld . cWorld . camPos)
(u ^. uvWorld . cWorld . lWorld) (u ^. uvWorld . cWorld . lWorld)
, show $ length $ fst $ worldSPic (u ^. uvConfig) (u ^. uvWorld) , show $ length $ fst $ worldSPic (u ^. uvConfig) (u ^. uvWorld)
, show $ length $ snd $ worldSPic (u ^. uvConfig) (u ^. uvWorld) ] , show $ length $ snd $ worldSPic (u ^. uvConfig) (u ^. uvWorld)
, show $ u ^. uvWorld . input . scrollTestInt
]
--[show $ u ^? uvWorld . hud . hudElement . diSections . sssExtra . sssSelPos . _Just] --[show $ u ^? uvWorld . hud . hudElement . diSections . sssExtra . sssSelPos . _Just]
-- [show $ fmap IM.keys $ u ^? uvWorld . hud . hudElement . subInventory . ciSections . sssSections] -- [show $ fmap IM.keys $ u ^? uvWorld . hud . hudElement . subInventory . ciSections . sssSections]
+2 -2
View File
@@ -110,9 +110,9 @@ resizeShadowFBO (fbo, (oldto1, oldto2)) x y = do
glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo) glBindFramebuffer GL_FRAMEBUFFER (_unFBO fbo)
mglDelete glDeleteTextures $ _unTO oldto1 mglDelete glDeleteTextures $ _unTO oldto1
mglDelete glDeleteTextures $ _unTO oldto2 mglDelete glDeleteTextures $ _unTO oldto2
to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 10 GL_NEAREST GL_NEAREST GL_RGBA8 to1 <- initializeTexture2DArray fbo GL_COLOR_ATTACHMENT0 x y 20 GL_NEAREST GL_NEAREST GL_RGBA8
to2 <- initializeTexture2DArray to2 <- initializeTexture2DArray
fbo GL_DEPTH_STENCIL_ATTACHMENT x y 10 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8 fbo GL_DEPTH_STENCIL_ATTACHMENT x y 20 GL_NEAREST GL_NEAREST GL_DEPTH24_STENCIL8
checkFBO fbo checkFBO fbo
return (fbo, (TO to1, TO to2)) return (fbo, (TO to1, TO to2))
+17 -9
View File
@@ -141,15 +141,15 @@ preloadRender = do
shadowedgeshader <- shadowedgeshader <-
makeShaderUsingVAO "shadow/edge" [vert, geom] ELinesAdjacency shEdgeVAO makeShaderUsingVAO "shadow/edge" [vert, geom] ELinesAdjacency shEdgeVAO
>>= addUniforms ["lightID"]
-- >>= addUniforms ["lightPos", "radiusUniform","lightID"]
shadowcapshader <- shadowcapshader <-
makeShaderUsingVAO "shadow/cap" [vert, geom] ETriangles shPosVAO makeShaderUsingVAO "shadow/cap" [vert, geom] ETriangles shPosVAO
>>= addUniforms [ "lightID"]
-- >>= addUniforms ["lightPos"]
shadowwallshader <- shadowwallshader <-
makeShaderUsingVAO "shadow/wallShadow" [vert, geom] EPoints wpVAO makeShaderUsingVAO "shadow/wallShadow" [vert, geom] EPoints wpVAO
>>= addUniforms ["lightID"] shadowlightshader <- makeShaderSized "shadow/light" [vert, geom, frag]
[1] 1
EPoints
shadowcombineshader <- makeShaderSized "shadow/combine" [vert,geom,frag] [1] 1 EPoints
pokeArray (shadVBOptr' shadowlightshader) $ concat cornerListForTriangles
-- positional shader -- positional shader
positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] ETriangles positionalBlankShad <- makeShader "positional/blank" [vert, frag] [3] ETriangles
@@ -181,17 +181,15 @@ preloadRender = do
lightingTextureShad <- lightingTextureShad <-
makeShaderUsingVAO "lighting/texture" [vert, frag] ETriangleStrip fsshadvao makeShaderUsingVAO "lighting/texture" [vert, frag] ETriangleStrip fsshadvao
>>= addUniforms ["lightPos", "lumRad"] >>= addUniforms ["lightPos", "lumRad"]
shadowlightshader <-
makeShaderUsingVAO "shadow/light" [vert, frag] ETriangleStrip fsshadvao
-- >>= addUniforms ["lightPos", "lumRad"] -- >>= addUniforms ["lightPos", "lumRad"]
>>= addUniforms ["lightID"] -- >>= addUniforms ["lightID"]
barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] EPoints barrelShad <- makeShader "texture/barrel" [vert, geom, frag] [2, 2, 2, 1] EPoints
-- blank wallShader -- blank wallShader
wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] EPoints wpColVAO wallBlankShad <- makeShaderUsingVAO "wall/blank" [vert, geom, frag] EPoints wpColVAO
-- textured wallShader -- textured wallShader
wallTextureShad <- wallTextureShad <-
makeShaderUsingVAO "wall/texture" [vert, geom, frag] EPoints wpColVAO makeShaderUsingVAO "wall/texture" [vert, geom, frag] EPoints wpColVAO
>>= addTexture "data/texture/grayscaleDirt.png" >>= addSamplerTexture2D "data/texture/grayscaleDirt.png"
---- texture array shader ---- texture array shader
textArrayShad <- textArrayShad <-
makeShader "texture/arrayPos" [vert, frag] [3, 3] ETriangles makeShader "texture/arrayPos" [vert, frag] [3, 3] ETriangles
@@ -254,6 +252,7 @@ preloadRender = do
, _shadowCapShader = shadowcapshader , _shadowCapShader = shadowcapshader
, _shadowWallShader = shadowwallshader , _shadowWallShader = shadowwallshader
, _shadowLightShader = shadowlightshader , _shadowLightShader = shadowlightshader
, _shadowCombineShader = shadowcombineshader
, _positionalBlankShader = positionalBlankShad , _positionalBlankShader = positionalBlankShad
, _wallBlankShader = wallBlankShad , _wallBlankShader = wallBlankShad
, _wallTextureShader = wallTextureShad , _wallTextureShader = wallTextureShad
@@ -292,6 +291,15 @@ cornerList =
, [1, 1, 1, 1] , [1, 1, 1, 1]
, [1, -1, 1, 0] , [1, -1, 1, 0]
] ]
cornerListForTriangles :: [[Float]]
cornerListForTriangles =
[ [-1, 1, 0, 1]
, [-1, -1, 0, 0]
, [1, 1, 1, 1]
, [-1, -1, 0, 0]
, [1, 1, 1, 1]
, [1, -1, 1, 0]
]
cleanUpRenderPreload :: RenderData -> IO () cleanUpRenderPreload :: RenderData -> IO ()
cleanUpRenderPreload pd = do cleanUpRenderPreload pd = do
+83 -77
View File
@@ -7,6 +7,8 @@ module Render (
bindFBO, bindFBO,
) where ) where
import Control.Monad
import Dodge.WindowSize
import Control.Lens import Control.Lens
import Control.Monad.Primitive import Control.Monad.Primitive
import Data.Preload.Render import Data.Preload.Render
@@ -28,6 +30,7 @@ import Shader.ExtraPrimitive
-- think of the produced texture as showing what RGB values should be "taken -- think of the produced texture as showing what RGB values should be "taken
-- away" from the shape colors. -- away" from the shape colors.
createLightMap :: createLightMap ::
Configuration ->
RenderData -> RenderData ->
[(Point3, Float, Point3)] -> -- Lights [(Point3, Float, Point3)] -> -- Lights
-- | number of walls -- | number of walls
@@ -42,8 +45,8 @@ createLightMap ::
TO -> TO ->
(Point3 -> Float -> IO ()) -> -- attempt at drawing shadow not using geo shader (Point3 -> Float -> IO ()) -> -- attempt at drawing shadow not using geo shader
IO () IO ()
createLightMap pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of createLightMap cfig pdata lightPoints nWalls nSils nCaps shadsdrawtype toPos drawCPUShadows = case shadsdrawtype of
InstancingShads -> instanceLightMap pdata lightPoints nWalls nSils nCaps toPos InstancingShads -> instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos
_ -> do _ -> do
let llinesShad = _lightingLineShadowShader pdata let llinesShad = _lightingLineShadowShader pdata
lcapShad = _lightingCapShader pdata lcapShad = _lightingCapShader pdata
@@ -146,6 +149,7 @@ lightsToArray xs = concat (take 20 $ map t xs ++ repeat [0,0,0,0])
--t (V3 a b c,d,V3 e f g) = [a,b,c,1] --t (V3 a b c,d,V3 e f g) = [a,b,c,1]
instanceLightMap :: instanceLightMap ::
Configuration ->
RenderData -> RenderData ->
[(Point3, Float, Point3)] -> -- Lights [(Point3, Float, Point3)] -> -- Lights
-- | number of walls -- | number of walls
@@ -157,99 +161,101 @@ instanceLightMap ::
-- | the texture object giving positions -- | the texture object giving positions
TO -> TO ->
IO () IO ()
instanceLightMap pdata lightPoints nWalls nSils nCaps toPos = do instanceLightMap cfig pdata lightPoints nWalls nSils nCaps toPos = do
let llinesShad = _shadowEdgeShader pdata let llinesShad = _shadowEdgeShader pdata
lcapShad = _shadowCapShader pdata lcapShad = _shadowCapShader pdata
lwallShad = _shadowWallShader pdata lwallShad = _shadowWallShader pdata
--llinesShad = _lightingLineShadowShader pdata (xsize,ysize) = getWindowSize cfig
ltextShad = _shadowLightShader pdata
withArray (lightsToArray lightPoints) $ \ptr -> withArray (lightsToArray lightPoints) $ \ptr ->
glNamedBufferSubData (pdata ^. lightsUBO) 0 620 ptr glNamedBufferSubData (pdata ^. lightsUBO) 0 620 ptr
-- we assume that the renderbuffer's depth has been correctly set elsewhere
-- we will not be changing that here forM_ [0..19] $ \i -> glCopyImageSubData
(pdata ^. rboBaseBloom)
GL_RENDERBUFFER
0
0 0 0
(pdata ^. fboShadow . _2 . _2 . unTO)
GL_TEXTURE_2D_ARRAY 0 0 0 i (fromIntegral xsize) (fromIntegral ysize)
1
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboShadow pdata)))
glDepthMask GL_FALSE glDepthMask GL_FALSE
-- clearColor is specified differently in preloadRender -- clearColor is specified differently in preloadRender
-- the colors are inverted -- the colors are inverted
glClearColor 1 1 1 1 glClearColor 0 0 0 0
glClear GL_COLOR_BUFFER_BIT glClear $ GL_COLOR_BUFFER_BIT + GL_STENCIL_BUFFER_BIT
-- for each of the lights: -- for each of the lights:
-- 1. stencil out the shadows from this light's point of view -- 1. stencil out the shadows from this light's point of view
-- 2. calculate lighting based on each fragment's position -- 2. calculate lighting based on each fragment's position
-- to consider: adding normals/a "material" for each fragment -- to consider: adding normals/a "material" for each fragment
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
glEnable GL_STENCIL_TEST glEnable GL_STENCIL_TEST
--stencilTest $= Enabled
glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP glStencilOpSeparate GL_FRONT GL_KEEP GL_KEEP GL_INCR_WRAP
--stencilOpSeparate Front $= (OpKeep, OpKeep, OpIncrWrap)
--stencilOpSeparate Back $= (OpKeep, OpKeep, OpDecrWrap)
glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP glStencilOpSeparate GL_BACK GL_KEEP GL_KEEP GL_DECR_WRAP
flip VFSM.mapM_ (VFSM.fromList (zip lightPoints [(0::Int)..])) $ \(_,i) -> do -- this was a loop
glDepthFunc GL_LESS glDepthFunc GL_LESS
-- setup stencil -- setup stencil
glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE glColorMask GL_FALSE GL_FALSE GL_FALSE GL_FALSE
glClear GL_STENCIL_BUFFER_BIT glDisable GL_CULL_FACE
glDisable GL_CULL_FACE glStencilFunc GL_ALWAYS 0 255
--cullFace $= Nothing --draw wall shadows
glStencilFunc GL_ALWAYS 0 255 glUseProgram (_shadProg' lwallShad)
--draw wall shadows glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad)
--currentProgram $= Just (_shadProg lwallShad) -- glDrawArrays
glUseProgram (_shadProg' lwallShad) -- (marshalEPrimitiveMode $ _shadPrim' lwallShad)
--uniform (_shadUnis lwallShad V.! 0) -- 0
-- $= Vector3 x y z -- (fromIntegral nWalls)
--glUniform3f (_shadUnis' lwallShad V.! 0) x y z --draw silhouette shadows
glUniform1i (_shadUnis' lwallShad V.! 0) (fromIntegral i) glUseProgram (_shadProg' llinesShad)
--bindVertexArrayObject $= lwallShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) glBindVertexArray (_vaoName $ _shadVAO' llinesShad)
glBindVertexArray $ lwallShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO lwallShad) -- glDrawElements
glDrawArrays -- (marshalEPrimitiveMode $ _shadPrim' llinesShad)
(marshalEPrimitiveMode $ _shadPrim' lwallShad) -- (fromIntegral nSils)
0 -- GL_UNSIGNED_SHORT
(fromIntegral nWalls) -- nullPtr
--draw silhouette shadows --draw caps on the near plane as required
glUseProgram (_shadProg' llinesShad) glEnable GL_CULL_FACE
glUniform1i (_shadUnis' llinesShad V.! 0) (fromIntegral i) glCullFace GL_BACK
glBindVertexArray (_vaoName $ _shadVAO' llinesShad) glUseProgram (_shadProg' lcapShad)
glDrawElements glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad)
(marshalEPrimitiveMode $ _shadPrim' llinesShad) -- glDrawElements
(fromIntegral nSils) -- (marshalEPrimitiveMode $ _shadPrim' lcapShad)
GL_UNSIGNED_SHORT -- (fromIntegral nCaps)
nullPtr -- GL_UNSIGNED_SHORT
--draw caps on the near plane as required -- nullPtr
glEnable GL_CULL_FACE -- --draw lightmap itself
glCullFace GL_BACK glEnable GL_DEPTH_TEST
glUseProgram (_shadProg' lcapShad) glDepthFunc GL_ALWAYS
--glUniform3f (_shadUnis' lcapShad V.! 0) x y z glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
glUniform1i (_shadUnis' lcapShad V.! 0) (fromIntegral i) glStencilFunc GL_EQUAL 0 255
glBindVertexArray $ lcapShad ^. shadVAO' . vaoName --Just (_vao $ _shadVAO lcapShad) -- delete vvvv
glDrawElements glDisable GL_STENCIL_TEST
(marshalEPrimitiveMode $ _shadPrim' lcapShad) -- delete ^^^^
(fromIntegral nCaps) glUseProgram (pdata ^. shadowLightShader . shadProg')
GL_UNSIGNED_SHORT -- bind world position texture
nullPtr bindTO toPos
--draw lightmap itself glDisable GL_BLEND
glEnable GL_DEPTH_TEST glBindVertexArray $ pdata ^. shadowLightShader . shadVAO' . vaoName
glDepthFunc GL_ALWAYS glDrawArrays
--depthFunc $= Just Always (marshalEPrimitiveMode $ pdata ^. shadowLightShader . shadPrim')
-- bind world position texture 0
bindTO toPos (fromIntegral (4 :: Int))
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_TRUE
--stencilOp $= (OpKeep, OpKeep, OpKeep) -- this was the end of the loop
glStencilFunc GL_EQUAL 0 255
--currentProgram $= ltextShad ^? shadProg --Just (_shadProg ltextShad)
--uniform (_shadUnis ltextShad V.! 0) $= Vector3 x y z
--uniform (_shadUnis ltextShad V.! 1) $= Vector4 r g b rad
glUseProgram (ltextShad ^. shadProg') --Just (_shadProg ltextShad)
glUniform1i (_shadUnis' ltextShad V.! 0) $ fromIntegral i
--glUniform4f (_shadUnis' ltextShad V.! 1) r g b rad
--bindVertexArrayObject $= ltextShad ^? shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
glBindVertexArray $ ltextShad ^. shadVAO' . vaoName -- Just (_vao $ _shadVAO ltextShad)
glDrawArrays
(marshalEPrimitiveMode (_shadPrim' ltextShad))
0
(fromIntegral (4 :: Int))
--cleanup: may not be necessary, depending on what comes after...
glDisable GL_CULL_FACE glDisable GL_CULL_FACE
glDisable GL_STENCIL_TEST glDisable GL_STENCIL_TEST
--draw to the lighting framebuffer here
glBindFramebuffer GL_FRAMEBUFFER (_unFBO (fst (_fboLighting pdata)))
glClearColor 1 1 1 1
glClear GL_COLOR_BUFFER_BIT
glBindTexture GL_TEXTURE_2D_ARRAY (pdata ^. fboShadow . _2 . _1 . unTO)
glEnable GL_BLEND
glBlendFunc GL_ZERO GL_ONE_MINUS_SRC_COLOR
glUseProgram (pdata ^. shadowCombineShader . shadProg') --Just (_shadProg ltextShad)
glDrawArrays
(marshalEPrimitiveMode EPoints)
0
1
-- assumes that vertices have already been sent to the shader -- assumes that vertices have already been sent to the shader
pingPongBetween :: pingPongBetween ::
(FBO, TO) -> (FBO, TO) ->
+3 -3
View File
@@ -1,5 +1,5 @@
module Shader.AuxAddition module Shader.AuxAddition
( addTexture ( addSamplerTexture2D
, vaddTextureNoFilter , vaddTextureNoFilter
, addTextureArray , addTextureArray
, addUniforms , addUniforms
@@ -20,8 +20,8 @@ import GLHelp
-- I am not sure if this assumes that the shader is constructed directly before -- I am not sure if this assumes that the shader is constructed directly before
-- the texture is added... -- the texture is added...
addTexture :: String -> FullShader -> IO FullShader addSamplerTexture2D :: String -> FullShader -> IO FullShader
addTexture = addTexture2D 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR addSamplerTexture2D = addTexture2D 3 GL_LINEAR_MIPMAP_LINEAR GL_LINEAR
vaddTextureNoFilter :: String -> FullShader -> IO FullShader vaddTextureNoFilter :: String -> FullShader -> IO FullShader
vaddTextureNoFilter = addTexture2D 1 GL_NEAREST GL_NEAREST vaddTextureNoFilter = addTexture2D 1 GL_NEAREST GL_NEAREST