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