Add shading for shapes and the floor

This commit is contained in:
2023-03-15 18:24:09 +00:00
parent 21f87b96d8
commit 989140d46e
16 changed files with 158 additions and 69 deletions
+10 -3
View File
@@ -1,17 +1,24 @@
#version 450 core
uniform vec3 lightPos;
uniform vec4 lumRad;
uniform sampler2D screenTexture;
layout (binding = 0) uniform sampler2D screenTexture;
layout (binding = 1) uniform sampler2D normals;
in vec2 vTexPos;
out vec4 fColor;
float rad = lumRad.a;
void main() {
vec3 distVec = texture(screenTexture, vTexPos).xyz - lightPos;
vec3 pos = texture(screenTexture, vTexPos).xyz;
vec3 distVec = pos - lightPos;
vec4 normbit = texture(normals, vTexPos);
vec3 norm = normbit.xyz - pos;
float y1 = float(normbit.w == 0 ? 1 : dot(normalize(norm), normalize(distVec)));
float y = float(y1 > 0 ? 1 : 0);
// float y = float(normbit.w == 1 ? 1 : 0);
float dist = dot(distVec, distVec);
if (dist > rad) {
discard;
}
float x = 1 - dist / rad;
vec3 c = (x * x * x) * lumRad.rgb;
vec3 c = y* (x * x * x) * lumRad.rgb;
fColor = vec4(c, 0);
}
+5 -1
View File
@@ -1,10 +1,14 @@
#version 450 core
in vec4 vCol;
in vec4 vPos;
in vec4 vNorm;
layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=2) out vec4 fNorm;
void main()
{
fCol = vCol;
fPos = vec4(vPos.xyz,1);
fPos = vPos;
fNorm = vNorm;
//fNorm = vec4(vPos.x,vPos.y+2,vPos.z,1);
}
+3
View File
@@ -1,11 +1,14 @@
#version 450 core
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 col;
layout (location = 2) in vec4 norm;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
out vec4 vCol;
out vec4 vPos;
out vec4 vNorm;
void main() {
gl_Position = theMat * vec4(pos.xyz,1);
vCol = col;
vPos = pos;
vNorm = norm;
}
+3
View File
@@ -3,9 +3,12 @@ in vec3 vTexPos;
in vec3 vPos;
layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=2) out vec4 normal;
uniform sampler2DArray tilesetSampler;
void main()
{
fCol = texture(tilesetSampler, vTexPos);
fPos = vec4(vPos,1);
//normal = vec4(vPos.xy,vPos.z-1,1);
normal = vec4(vPos.xy,vPos.z-1,1);
}
+2
View File
@@ -1,6 +1,7 @@
#version 450 core
layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=2) out vec4 fNorm;
in vec2 tPos;
in vec4 gPos;
in vec4 gColor;
@@ -9,4 +10,5 @@ void main()
{
fCol = gColor * texture(tex,tPos);
fPos = gPos;
fNorm = gPos + vec4(1,0,0,0);
}
+4 -8
View File
@@ -15,13 +15,9 @@ void main()
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p3 = vec4 (p1.xy,100,1);
vec4 p4 = vec4 (p2.xy,100,1);
vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2;
vec4 a3 = theMat * p3;
vec4 a4 = theMat * p4;
gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = a1; EmitVertex();
gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = a3; EmitVertex();
gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = a2; EmitVertex();
gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = a4; EmitVertex();
gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = vec4(theMat * p1); EmitVertex();
gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = vec4(theMat * p3); EmitVertex();
gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = vec4(theMat * p2); EmitVertex();
gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = vec4(theMat * p4); EmitVertex();
EndPrimitive();
}