Make light position uniform 3d

This commit is contained in:
jgk
2021-06-25 01:19:20 +02:00
parent b451953b99
commit b6feccd934
10 changed files with 40 additions and 71 deletions
+3 -4
View File
@@ -2,11 +2,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,1) ).xy;
uniform vec3 lightPos;
vec4 shift (vec4 p)
{ return vec4 (p.xy + (200 * (p.xy-lightPos)), 0.1 , 1);
{ return vec4 (p.xy + (200 * (p.xy-lightPos.xy)), 0.1 , 1);
}
float isLHS (vec2 startV, vec2 testV)
{
@@ -17,7 +16,7 @@ void main()
{
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)
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{
vec4 p3 = vec4 (p1.xy,-0.5,1);
vec4 p4 = vec4 (p2.xy,-0.5,1);
+5 -38
View File
@@ -2,22 +2,21 @@
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (std140, binding = 0) uniform TheMat { mat4 theMat; } ;
uniform vec3 lightPos;
uniform vec2 radLum;
out vec3 dField;
out float lum;
uniform vec2 lightPos;
uniform vec2 radLum;
float isLHS (vec2 startV, vec2 testV)
{
return sign( -startV.x * testV.y + startV.y * testV.x);
}
vec4 shiftCloser (vec4 v)
{ return vec4 (v.xy , v.z-0.0001 , v.w) ; }
void main()
{
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)
if (isLHS (p1.xy - lightPos.xy, p2.xy - lightPos.xy) < 0)
{
lum = radLum.y;
float rad = radLum.x;
@@ -25,8 +24,8 @@ if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
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;
vec2 d1 = p1.xy - lightPos.xy;
vec2 d2 = p2.xy - lightPos.xy;
vec4 a1 = shiftCloser( theMat * p1 );
vec4 a2 = shiftCloser( theMat * p2 );
@@ -49,35 +48,3 @@ if (isLHS (p1.xy - lightPos, p2.xy - lightPos) < 0)
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();
//}