Improve normal maps on ground and walls

This commit is contained in:
2023-03-19 23:52:19 +00:00
parent e90989ee2d
commit 33f31aa385
24 changed files with 112 additions and 178 deletions
+6 -6
View File
@@ -9,19 +9,19 @@ float rad = lumRad.a;
void main() {
vec3 pos = texture(screenTexture, vTexPos).xyz;
vec3 distVec = pos - lightPos;
float dist = dot(distVec, distVec);
if (dist > rad) {
discard;
}
vec4 normbit = texture(normals, vTexPos);
vec3 norm = normbit.xyz - pos;
vec3 norm = normbit.xyz;
float y1 = dot(normalize(norm), normalize(distVec));
float y2 = float(y1 > 0 ? 1 : 0);
//float y3 = clamp(0.5 * (y1 + 1),0,1) ;
float y3 = clamp(2*y1 + 1,0,1) ;
//float y3 = clamp(0.5 * (y1 + 2),0,1) ;
float y = float(normbit.w == 0 ? y3 : y2);
float y = float(normbit.w == 0 ? y2 : y2);
//float y = y2;
float dist = dot(distVec, distVec);
if (dist > rad) {
discard;
}
float x = 1 - dist / rad;
vec3 c = y* (x * x * x) * lumRad.rgb;
fColor = vec4(c, 0);
+1 -2
View File
@@ -9,6 +9,5 @@ void main()
{
fCol = vCol;
fPos = vPos;
fNorm = vNorm;
//fNorm = vec4(vPos.x,vPos.y+2,vPos.z,1);
fNorm = vec4(vNorm.xyz - vPos.xyz,1);
}
+14 -3
View File
@@ -3,13 +3,24 @@ layout (location=0) out vec4 fCol;
layout (location=1) out vec4 fPos;
layout (location=2) out vec4 fNorm;
in vec2 tPos;
in vec3 gTexCoords;
in vec4 gPos;
in vec4 gNorm;
in vec4 gColor;
uniform sampler2D tex;
in float gRot;
layout (binding=1) uniform sampler2DArray normalSampler;
layout (binding=2) uniform sampler2DArray diffuseSampler;
vec2 rotateV2 (float a, vec2 v)
{
return vec2(v.x*cos(a) - v.y*sin(a), v.x*sin(a) + v.y*cos(a));
}
void main()
{
fCol = gColor * texture(tex,tPos);
//fCol = gColor * texture(tex,tPos);
fCol = texture(diffuseSampler,gTexCoords);
fPos = gPos;
fNorm = gNorm;
vec4 basenorm = texture(normalSampler,gTexCoords) - 0.5;
//fNorm = fPos - vec4(rotateV2(gRot,basenorm.xz), basenorm.y,0);
vec2 n = rotateV2(gRot,vec2(-basenorm.x,-basenorm.z));
fNorm = vec4(fPos.xyz - vec3(n,basenorm.y),0);
}
+16
View File
@@ -7,28 +7,44 @@ out vec4 gColor;
out vec2 tPos;
out vec4 gPos;
out vec4 gNorm;
out vec3 gTexCoords;
out float gRot;
// consider using isLHS to check if the wall is facing the center
float isLHS (vec2 startV, vec2 testV)
{ return sign( -startV.x * testV.y + startV.y * testV.x); }
void main()
{ gColor = vColor[0];
vec2 p1xy = gl_in[0].gl_Position.xy;
vec2 p2xy = gl_in[0].gl_Position.zw;
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
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);
vec2 d = vec2(p1.xy - p2.xy);
float rot = atan(d.y,d.x);
float dist = distance(p1xy,p2xy);
float tcoordx = dist / 50;
float tcoordz = 11;
vec4 norm = vec4( d.y, -d.x, 0, 0);
gPos = p1; tPos = vec2 ( 1,-1) ; gl_Position = vec4(theMat * p1);
gNorm = gPos - norm;
gTexCoords = vec3 (0,0,tcoordz);
gRot = rot;
EmitVertex();
gPos = p3; tPos = vec2 ( 1, 1) ; gl_Position = vec4(theMat * p3);
gNorm = gPos - norm;
gTexCoords = vec3 (0,2,tcoordz);
gRot = rot;
EmitVertex();
gPos = p2; tPos = vec2 (-1,-1) ; gl_Position = vec4(theMat * p2);
gNorm = gPos - norm;
gTexCoords = vec3 (tcoordx,0,tcoordz);
gRot = rot;
EmitVertex();
gPos = p4; tPos = vec2 (-1, 1) ; gl_Position = vec4(theMat * p4);
gNorm = gPos - norm;
gTexCoords = vec3 (tcoordx,2,tcoordz);
gRot = rot;
EmitVertex();
EndPrimitive();
}