Vertex pull fullscreen lighting texture shader
This commit is contained in:
@@ -4,8 +4,6 @@ layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
|
||||
layout (std140, binding = 1) uniform TheLight { vec4 lightPos; vec4 lumRad; };
|
||||
layout (std430, binding = 3) readonly buffer Data { PosColNorm data[]; };
|
||||
layout (std430, binding = 4) readonly buffer Indices { uint indices[]; };
|
||||
//layout(location=0)uniform vec3 lightPos;
|
||||
//layout(location=1)uniform vec4 lumRad;
|
||||
vec4 projNear (vec4 pos)
|
||||
{
|
||||
// note we project to a specific height
|
||||
|
||||
@@ -57,6 +57,7 @@ void main()
|
||||
// test if the edge is part of the silhouette
|
||||
// that is, if the normals of the faces connected to the edge are in
|
||||
// "different directions" wrt the light direction
|
||||
// (first test the "drawbit")
|
||||
if (p0.w==1 && dot(n0, lightDir) * dot(n1, lightDir) <= 0 &&
|
||||
(dot(lightDir, lightDir) < ru2 || dot(lightDir2, lightDir2) < ru2))
|
||||
// using <= rather than < seems to get rid of overlapping shadow
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#version 450 core
|
||||
layout(early_fragment_tests) in;
|
||||
layout(location=0)uniform vec3 lightPos;
|
||||
layout(location=1)uniform vec4 lumRad;
|
||||
layout (std140, binding = 1) uniform TheLight { vec4 lightPos; vec4 lumRad; };
|
||||
layout (binding = 0) uniform sampler2D screenTexture;
|
||||
layout (binding = 1) uniform sampler2D normals;
|
||||
in vec2 vTexPos;
|
||||
@@ -9,18 +8,18 @@ out vec4 fColor;
|
||||
float rad = lumRad.a;
|
||||
void main() {
|
||||
vec3 pos = texture(screenTexture, vTexPos).xyz;
|
||||
vec3 distVec = pos - lightPos;
|
||||
vec3 distVec = pos - lightPos.xyz;
|
||||
float dist = dot(distVec, distVec);
|
||||
if (dist > rad) {
|
||||
discard;
|
||||
}
|
||||
vec4 normbit = texture(normals, vTexPos);
|
||||
vec3 norm = normbit.xyz;
|
||||
// if (dist > rad) {
|
||||
// discard;
|
||||
// }
|
||||
vec3 norm = texture(normals, vTexPos).xyz;
|
||||
float y1 = dot(norm, distVec);
|
||||
float y2 = float(y1 > 0 ? 1 : 0);
|
||||
float x = 1 - (pow(dist / rad,4));
|
||||
//float x = 1 - (dist / rad);
|
||||
//float x = 1;
|
||||
//float x = (dist > rad ? 0 : 1);
|
||||
vec3 c = y2* x * lumRad.rgb;
|
||||
fColor = vec4(c, 0);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#version 450 core
|
||||
layout (location = 0) in vec2 pos;
|
||||
layout (location = 1) in vec2 texPos;
|
||||
layout (std140, binding = 2) uniform PosTex { vec4 posTex[6]; };
|
||||
out vec2 vTexPos;
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(pos,0,1);
|
||||
vTexPos = texPos;
|
||||
gl_Position = vec4(posTex[gl_VertexID].xy,0,1);
|
||||
vTexPos = posTex[gl_VertexID].zw;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ preloadRender = do
|
||||
glNamedBufferStorage lightubo 32 nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
glBindBufferBase GL_UNIFORM_BUFFER 1 lightubo
|
||||
|
||||
fulltexbo <- mglCreate glCreateBuffers
|
||||
let ftsize = fromIntegral $ sizeOf (0::Float) * 6 * 4
|
||||
withArray cornerList' $ \ptr ->
|
||||
glNamedBufferStorage fulltexbo ftsize ptr 0
|
||||
glBindBufferBase GL_UNIFORM_BUFFER 2 fulltexbo
|
||||
|
||||
winssbo <- mglCreate glCreateBuffers
|
||||
let winssbosize = sizeOf (0 :: Float) * 8 * 1024
|
||||
glNamedBufferStorage winssbo (fromIntegral winssbosize) nullPtr GL_DYNAMIC_STORAGE_BIT
|
||||
@@ -248,6 +254,16 @@ cornerList =
|
||||
, [1, 1, 1, 1]
|
||||
, [1, -1, 1, 0]
|
||||
]
|
||||
cornerList' :: [Float]
|
||||
cornerList' = concat
|
||||
[ bl, br, tl
|
||||
, tl, br, tr
|
||||
]
|
||||
where
|
||||
bl = [-1, -1, 0, 0]
|
||||
br = [ 1, -1, 1, 0]
|
||||
tl = [-1, 1, 0, 1]
|
||||
tr = [ 1, 1, 1, 1]
|
||||
|
||||
--cornerListForTriangles :: [[Float]]
|
||||
--cornerListForTriangles =
|
||||
|
||||
+1
-7
@@ -201,13 +201,7 @@ renderShadows shadrendertype nWalls nSils nCaps positiontexture normaltexture li
|
||||
glColorMask GL_TRUE GL_TRUE GL_TRUE GL_FALSE
|
||||
glStencilFunc GL_EQUAL 0 255
|
||||
glUseProgram (ltextShad ^. shaderUINT)
|
||||
glUniform3f 0 x y z
|
||||
glUniform4f 1 r g b rad
|
||||
glBindVertexArray $ ltextShad ^. shaderVAO . vaoName
|
||||
glDrawArrays
|
||||
(_unPrimitiveMode (_shaderPrimitive ltextShad))
|
||||
0
|
||||
(fromIntegral (4 :: Int))
|
||||
glDrawArrays GL_TRIANGLES 0 6
|
||||
--cleanup: may not be necessary, depending on what comes after...
|
||||
-- glDisable GL_STENCIL_TEST
|
||||
-- glDisable GL_SCISSOR_TEST
|
||||
|
||||
Reference in New Issue
Block a user