Play around with alpha blending

This commit is contained in:
2025-11-04 10:42:18 +00:00
parent 833d4562e2
commit 05c530eeb1
4 changed files with 30 additions and 36 deletions
+10 -21
View File
@@ -4,8 +4,6 @@ layout(triangle_strip, max_vertices = 4) out;
layout(std140, binding = 0) uniform TheMat { mat4 theMat; };
layout(location=0) uniform vec3 lightPos;
layout(location=1) uniform float radiusUniform;
// vec4 shift (vec4 p) { return (vec4 (p.xyz +
// (lumRad.a*normalize(p.xyz-lightPos)), 1));}
float closestPointOnLineParam3 (vec3 a, vec3 b, vec3 p) {
return dot(p - a,b-a) / dot(b-a,b-a);
}
@@ -17,13 +15,10 @@ vec3 closestPointOnSeg3 (vec3 a,vec3 b, vec3 p) {
{ return a + (x * (b- a));}
}
}
//vec3 closepoint =
vec4 shift(vec4 p) { return (vec4(p.xyz + (100000 * (p.xyz - lightPos)), 1)); }
vec4 shift(vec4 p) { return (vec4(p.xyz + (10000 * (p.xyz - lightPos)), 1)); }
vec4 shiftBy(float x, vec4 p) {
return (vec4(lightPos + (x * normalize(p.xyz - lightPos)), 1));
}
// vec4 shift (vec4 p) { return (vec4 (lightPos +
// (lumRad.a*normalize(p.xyz-lightPos)), 1));}
// copied from lighting/cap.geom, should not be changed on its own
vec4 projNear(vec4 pos) {
// note we project to a specific height
@@ -34,7 +29,6 @@ vec4 projNear(vec4 pos) {
return vec4(xy, 100, 1);
}
vec4 shiftNear(vec4 pos)
//{ vec4 sp = shiftBy(radiusUniform,pos);
{
vec4 sp = shift(pos);
if (sp.z > 100) {
@@ -43,19 +37,16 @@ vec4 shiftNear(vec4 pos)
return sp;
}
}
vec4 f(vec4 p) { return (theMat * p); }
void main() {
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
vec4 p0 = gl_in[0].gl_Position;
vec4 p1 = gl_in[1].gl_Position;
vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
float ru2 = radiusUniform * radiusUniform;
vec4 mid = 0.5 * (p0 + p1);
vec3 n0a = gl_in[2].gl_Position.xyz;
vec3 n1a = gl_in[3].gl_Position.xyz;
vec3 n0 = cross(p1.xyz - p0.xyz, n0a - p0.xyz);
vec3 n1 = cross(p0.xyz - p1.xyz, n1a - p1.xyz);
// vec3 n2 = n0 + n1; // assumes the summands are normalized
vec3 lightDir = p0.xyz - lightPos.xyz;
vec3 lightDir2 = p1.xyz - lightPos.xyz;
// first test if the edge is part of the silhouette
@@ -66,24 +57,22 @@ vec3 closepoint = closestPointOnSeg3(p0.xyz,p1.xyz,lightPos);
// using <= rather than < seems to get rid of overlapping shadow
// artefacts
{
//vec4 p2 = shiftNear(p0);
//vec4 p3 = shiftNear(p1);
vec4 p2 = shiftNear(p0);
vec4 p3 = shiftNear(p1);
gl_Position = f(p0);
gl_Position = theMat * p0;
EmitVertex();
if (dot(n0, lightDir) > 0) {
gl_Position = f(p2);
gl_Position = theMat * p2;
EmitVertex();
gl_Position = f(p1);
gl_Position = theMat * p1;
EmitVertex();
} else {
gl_Position = f(p1);
gl_Position = theMat * p1;
EmitVertex();
gl_Position = f(p2);
gl_Position = theMat * p2;
EmitVertex();
}
gl_Position = f(p3);
gl_Position = theMat * p3;
EmitVertex();
EndPrimitive();
} else {