Refactor lighting shaders

This commit is contained in:
jgk
2021-06-25 00:44:45 +02:00
parent 6320093473
commit b451953b99
13 changed files with 44 additions and 80 deletions
+5 -5
View File
@@ -7,20 +7,20 @@ out vec2 dField;
void main()
{
lum = gl_in[0].gl_Position.w;
vec4 cenPos = vec4( gl_in[0].gl_Position.xy, 0 , 1);
vec4 cenPos = vec4( gl_in[0].gl_Position.xy, 0.1 , 1);
float gRad = gl_in[0].gl_Position.z;
dField = vec2 ( 1, 1);
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y + gRad, -0 , 1);
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y + gRad, 0.1 , 1);
EmitVertex();
dField = vec2 (-1, 1);
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y + gRad, -0 , 1);
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y + gRad, 0.1 , 1);
EmitVertex();
dField = vec2 ( 1,-1);
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y - gRad, -0 , 1);
gl_Position = theMat * vec4 (cenPos.x + gRad, cenPos.y - gRad, 0.1 , 1);
EmitVertex();
dField = vec2 (-1,-1);
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y - gRad, -0 , 1);
gl_Position = theMat * vec4 (cenPos.x - gRad, cenPos.y - gRad, 0.1 , 1);
EmitVertex();
EndPrimitive();
+4 -4
View File
@@ -3,10 +3,10 @@ layout (points) in;
layout (triangle_strip, max_vertices = 11) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec2 lightPos;
vec2 lightPosa = ( theMat * vec4(lightPos,0,1) ).xy;
vec2 lightPosa = ( theMat * vec4(lightPos,0.1,1) ).xy;
vec4 shift (vec4 p)
{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0 , 1);
{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0.1 , 1);
}
float isLHS (vec2 startV, vec2 testV)
{
@@ -15,8 +15,8 @@ float isLHS (vec2 startV, vec2 testV)
// construct a box with openings on bottom face and face away from wall
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1);
if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
{
vec4 p3 = vec4 (p1.xy,-0.5,1);
-1
View File
@@ -1,5 +1,4 @@
#version 430 core
in vec2 cenPosT;
in float lum;
in vec3 dField;
out vec4 fColor;
+8 -8
View File
@@ -15,15 +15,15 @@ vec4 shiftCloser (vec4 v)
void main()
{
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0,1);
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,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);
vec4 p3 = vec4 (p1.xy,-0.3,1);
vec4 p4 = vec4 (p2.xy,-0.3,1);
vec2 d1 = p1.xy - lightPos;
vec2 d2 = p2.xy - lightPos;
@@ -33,16 +33,16 @@ if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
vec4 a3 = shiftCloser( theMat * p3 );
vec4 a4 = shiftCloser( theMat * p4 );
dField = vec3( d1.x/rad, d1.y/rad, 0);
dField = vec3( d1.x/rad, d1.y/rad, 100.0/rad);
gl_Position = a1;
EmitVertex();
dField = vec3( d1.x/rad, d1.y/rad, 0);
dField = vec3( d1.x/rad, d1.y/rad, -300.0/rad);
gl_Position = a3;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 0);
dField = vec3( d2.x/rad, d2.y/rad, 100.0/rad);
gl_Position = a2;
EmitVertex();
dField = vec3( d2.x/rad, d2.y/rad, 0);
dField = vec3( d2.x/rad, d2.y/rad, -300.0/rad);
gl_Position = a4;
EmitVertex();
+4 -4
View File
@@ -15,10 +15,10 @@ void main()
{
gColor = vColor[0];
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,-0.3,1);
vec4 p4 = vec4 (p2.xy,-0.3,1);
vec4 p1 = vec4 (gl_in[0].gl_Position.xy,0.1,1);
vec4 p2 = vec4 (gl_in[0].gl_Position.zw,0.1,1);
vec4 p3 = vec4 (p1.xy,-0.5,1);
vec4 p4 = vec4 (p2.xy,-0.5,1);
vec4 a1 = theMat * p1;
vec4 a2 = theMat * p2;