Add lighting on walls, imperfect

This commit is contained in:
jgk
2021-03-21 11:11:44 +01:00
parent a8aa19bb18
commit e7b4e54f9a
8 changed files with 140 additions and 68 deletions
+4 -4
View File
@@ -18,16 +18,16 @@ void main()
cenPosT = vec2 ( (cenPos.x + 1) * 0.5 * winSize.x , (cenPos.y + 1) * 0.5 * winSize.y);
dField = vec2 ( 1, 1);
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y + gRad/winSize.y, -0.2 , 1);
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
EmitVertex();
dField = vec2 (-1, 1);
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y + gRad/winSize.y, -0.2 , 1);
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y + gRad/winSize.y, -0 , 1);
EmitVertex();
dField = vec2 ( 1,-1);
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y - gRad/winSize.y, -0.2 , 1);
gl_Position = vec4 (cenPos.x + gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
EmitVertex();
dField = vec2 (-1,-1);
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y - gRad/winSize.y, -0.2 , 1);
gl_Position = vec4 (cenPos.x - gRad/winSize.x, cenPos.y - gRad/winSize.y, -0 , 1);
EmitVertex();
EndPrimitive();
+13
View File
@@ -0,0 +1,13 @@
#version 430 core
in vec2 cenPosT;
in float lum;
in vec3 dField;
out vec4 fColor;
void main()
{
float c = pow (1 - min(1, dot(dField,dField)) , 2) * lum ;
fColor = vec4(c,c,c,c);
}
+86
View File
@@ -0,0 +1,86 @@
#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
out vec3 dField;
out float lum;
uniform vec2 lightPos;
uniform mat4 perpMat;
uniform vec2 radLum;
float isLHS (vec2 startV, vec2 testV)
{
return sign( -startV.x * testV.y + startV.y * testV.x);
}
vec4 shiftUp (vec4 v)
{ return vec4 (v.xy , v.z-0.1 , v.w) ; }
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
{
lum = radLum.y;
float rad = radLum.x;
vec4 p3 = vec4 (p1.xy,-0.2,1);
vec4 p4 = vec4 (p2.xy,-0.2,1);
vec2 d1 = p1.xy - lightPos;
vec2 d2 = p2.xy - lightPos;
vec4 a1 = shiftUp( perpMat * p1 );
vec4 a2 = shiftUp( perpMat * p2 );
vec4 a3 = shiftUp( perpMat * p3 );
vec4 a4 = shiftUp( perpMat * p4 );
dField = vec3( d1.x/rad, d1.y/rad, 0);
gl_Position = a1;
EmitVertex();
dField = vec3( d1.x/rad, d1.y/rad, 1);
gl_Position = a3;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 0);
gl_Position = a2;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 1);
gl_Position = a4;
EmitVertex();
EndPrimitive();
} else {}
}
// // void main()
// // {
// // vec4 frontL4 = worldMat * vec4(gl_in[0].gl_Position.xy, 0 ,1);
// // vec4 frontR4 = worldMat * vec4(gl_in[0].gl_Position.zw, 0 ,1);
// // vec2 frontL = frontL4.xy;
// // vec2 frontR = frontR4.xy;
// //
// // emitLine (frontR);
// // emitLine (frontL);
// // EndPrimitive();
// // }
// gl_Position = perspective * worldMat * p4; EmitVertex();
// gl_Position = perspective * worldMat * p3; EmitVertex();
// gl_Position = perspective * worldMat * p7; EmitVertex();
// gl_Position = perspective * worldMat * p8; EmitVertex();
// gl_Position = perspective * worldMat * p5; EmitVertex();
// gl_Position = perspective * worldMat * p3; EmitVertex();
// gl_Position = perspective * worldMat * p1; EmitVertex();
// gl_Position = perspective * worldMat * p4; EmitVertex();
// gl_Position = perspective * worldMat * p2; EmitVertex();
// gl_Position = perspective * worldMat * p7; EmitVertex();
// gl_Position = perspective * worldMat * p6; EmitVertex();
// gl_Position = perspective * worldMat * p5; EmitVertex();
//void emitLine (vec2 pa)
//{
// gl_Position = vec4 (pa, 0, 1);
// EmitVertex();
// gl_Position = shift (vec4 (pa,0,1)); //vec4 (pa + (200 * (pa - lightPosa)), 0 , 1);
// EmitVertex();
//}
+7
View File
@@ -0,0 +1,7 @@
#version 430 core
layout (location = 0) in vec4 poss;
void main()
{
gl_Position = poss;
}
+4 -4
View File
@@ -23,12 +23,12 @@ vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
{
vec4 p3 = vec4 (p1.xy,-0.2,1);
vec4 p4 = vec4 (p2.xy,-0.2,1);
vec4 p3 = vec4 (p1.xy,-0.5,1);
vec4 p4 = vec4 (p2.xy,-0.5,1);
vec4 p5 = shift(p1);
vec4 p6 = shift(p2);
vec4 p7 = vec4 (p6.xy,-0.2,1);
vec4 p8 = vec4 (p5.xy,-0.2,1);
vec4 p7 = vec4 (p6.xy,-0.5,1);
vec4 p8 = vec4 (p5.xy,-0.5,1);
vec4 a1 = perpMat * p1;
vec4 a2 = perpMat * p2;