First attempt at using exclusively depth pass with cap on near plane
This commit is contained in:
@@ -3,17 +3,38 @@ layout (triangles) in;
|
|||||||
layout (triangle_strip, max_vertices = 3) out;
|
layout (triangle_strip, max_vertices = 3) out;
|
||||||
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||||
uniform vec3 lightPos;
|
uniform vec3 lightPos;
|
||||||
|
vec4 projNear (vec4 pos)
|
||||||
|
{
|
||||||
|
// note we project to a specific height
|
||||||
|
// this is quite brittle, not ideal
|
||||||
|
vec3 dir = pos.xyz - lightPos ;
|
||||||
|
float a = (150 - pos.z) / dir.z ;
|
||||||
|
vec2 xy = (pos.xyz + a * dir).xy ;
|
||||||
|
return vec4 ( xy, 150 , 1) ;
|
||||||
|
}
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
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 ;
|
||||||
vec4 p2 = gl_in[2].gl_Position ;
|
vec4 p2 = gl_in[2].gl_Position ;
|
||||||
if ( dot( p0.xyz - lightPos, cross( p0.xyz - p1.xyz, p1.xyz - p2.xyz)) < 0)
|
if ( //dot( p0.xyz - vec3 (0,0,1), cross( p0.xyz - p1.xyz, p1.xyz - p2.xyz)) < 0
|
||||||
|
// &&
|
||||||
|
( p0.z - lightPos.z > 0 )
|
||||||
|
&& ( p1.z - lightPos.z > 0 )
|
||||||
|
&& ( p2.z - lightPos.z > 0 )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
gl_Position = theMat * p0; EmitVertex();
|
// front cap
|
||||||
gl_Position = theMat * p1; EmitVertex();
|
vec4 v1 = vec4 (0,0,1,0) ;
|
||||||
gl_Position = theMat * p2; EmitVertex();
|
gl_Position = theMat * projNear(p0); EmitVertex();
|
||||||
|
gl_Position = theMat * projNear(p1); EmitVertex();
|
||||||
|
gl_Position = theMat * projNear(p2); EmitVertex();
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
// if light points downwards onto surface, draw back cap too
|
||||||
|
if (dot ( p0.xyz - lightPos, vec3 ( 0,0,1) ) > 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else {}
|
||||||
}
|
}
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,8 +93,8 @@ youLight =
|
|||||||
TLS { _tlsPos = V3 0 0 0
|
TLS { _tlsPos = V3 0 0 0
|
||||||
,_tlsRad = 300
|
,_tlsRad = 300
|
||||||
,_tlsIntensity = 0.1
|
,_tlsIntensity = 0.1
|
||||||
,_tlsUpdate = \w _ -> (w, Nothing)
|
--,_tlsUpdate = \w _ -> (w, Nothing)
|
||||||
--,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)}))
|
,_tlsUpdate = \w _ -> (w, Just (youLight {_tlsPos = f $ _crPos (you w)}))
|
||||||
,_tlsTime = 0
|
,_tlsTime = 0
|
||||||
}
|
}
|
||||||
where
|
where
|
||||||
|
|||||||
+10
-5
@@ -57,9 +57,10 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do
|
|||||||
depthMask $= Disabled
|
depthMask $= Disabled
|
||||||
blendFunc $= (Zero, OneMinusSrcColor)
|
blendFunc $= (Zero, OneMinusSrcColor)
|
||||||
stencilTest $= Enabled
|
stencilTest $= Enabled
|
||||||
depthFunc $= Just Lequal
|
--depthFunc $= Just Lequal
|
||||||
flip VS.mapM_ (VS.fromList lightPoints) $ \(V3 x y z,rad,V3 r g b) -> do
|
flip VS.mapM_ (VS.fromList lightPoints) $ \(V3 x y z,rad,V3 r g b) -> do
|
||||||
--forM_ lightPoints $ \(V3 x y z,r,lum) -> do
|
--forM_ lightPoints $ \(V3 x y z,r,lum) -> do
|
||||||
|
-- the use of Less is for caps on geometry
|
||||||
depthFunc $= Just Less
|
depthFunc $= Just Less
|
||||||
-- stencil out shadows
|
-- stencil out shadows
|
||||||
colorMask $= Color4 Disabled Disabled Disabled Disabled
|
colorMask $= Color4 Disabled Disabled Disabled Disabled
|
||||||
@@ -74,21 +75,25 @@ createLightMap pdata lightPoints nWalls nSils nsurfVs = do
|
|||||||
drawShader (_lightingOccludeShader pdata) nWalls
|
drawShader (_lightingOccludeShader pdata) nWalls
|
||||||
|
|
||||||
--stencilOp $= (OpKeep,OpDecr,OpKeep)
|
--stencilOp $= (OpKeep,OpDecr,OpKeep)
|
||||||
stencilOpSeparate Front $= (OpKeep,OpDecrWrap,OpKeep)
|
-- stencilOpSeparate Front $= (OpKeep,OpDecrWrap,OpKeep)
|
||||||
stencilOpSeparate Back $= (OpKeep,OpIncrWrap,OpKeep)
|
-- stencilOpSeparate Back $= (OpKeep,OpIncrWrap,OpKeep)
|
||||||
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
|
currentProgram $= Just (_shaderProgram $ _lightingLineShadowShader pdata)
|
||||||
uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata)
|
uniform (head $ _shaderCustomUnis $ _lightingLineShadowShader pdata)
|
||||||
$= Vector3 x y z
|
$= Vector3 x y z
|
||||||
depthClamp $= Enabled
|
-- depthClamp $= Enabled
|
||||||
drawShader (_lightingLineShadowShader pdata) nSils
|
drawShader (_lightingLineShadowShader pdata) nSils
|
||||||
depthClamp $= Disabled
|
-- depthClamp $= Disabled
|
||||||
|
|
||||||
|
cullFace $= Just Back
|
||||||
--stencilOp $= (OpKeep,OpDecrWrap,OpKeep)
|
--stencilOp $= (OpKeep,OpDecrWrap,OpKeep)
|
||||||
currentProgram $= Just (_shaderProgram $ _lightingCapShader pdata)
|
currentProgram $= Just (_shaderProgram $ _lightingCapShader pdata)
|
||||||
uniform (head $ _shaderCustomUnis $ _lightingCapShader pdata)
|
uniform (head $ _shaderCustomUnis $ _lightingCapShader pdata)
|
||||||
$= Vector3 x y z
|
$= Vector3 x y z
|
||||||
|
-- depthClamp $= Enabled
|
||||||
drawShader (_lightingCapShader pdata) (nSils - 6)
|
drawShader (_lightingCapShader pdata) (nSils - 6)
|
||||||
|
-- depthClamp $= Disabled
|
||||||
|
|
||||||
|
-- use Lequal to redraw surfaces above already drawn surfaces
|
||||||
depthFunc $= Just Lequal
|
depthFunc $= Just Lequal
|
||||||
-- draw geometry surfaces
|
-- draw geometry surfaces
|
||||||
--cullFace $= Just Back
|
--cullFace $= Just Back
|
||||||
|
|||||||
Reference in New Issue
Block a user