Commit c1dc9b62 authored by Sylvain Thery's avatar Sylvain Thery

resolve pb of clipping with line Shaders

parent 4107949a
...@@ -4,14 +4,10 @@ PRECISION; ...@@ -4,14 +4,10 @@ PRECISION;
VARYING_FRAG vec3 fragColor; VARYING_FRAG vec3 fragColor;
uniform float alpha; uniform float alpha;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = vec4(fragColor,alpha); FRAG_OUT = vec4(fragColor,alpha);
} }
// ShaderBold3DColorLines::geometryShaderText // ShaderBold3DColorLines::geometryShaderText
uniform float lineWidth; uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform float lineWidth;
uniform vec4 planeClip;
VARYING_IN vec3 vcolor[]; VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor; VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 Ap = (ProjectionMatrix*POSITION_IN(0)); /*
vec4 Bp = (ProjectionMatrix*POSITION_IN(1)); float v0 = dot(planeClip,POSITION_IN(0));
float v1 = dot(planeClip,POSITION_IN(1));
vec4 A = vec4(0.0,0.0,0.0,0.0);
vec4 B = vec4(0.0,0.0,0.0,0.0);
if (v0 <= 0.0) //A not clipped
{
A = ModelViewMatrix *POSITION_IN(0);
if (v1 <= 0.0)
B = ModelViewMatrix *POSITION_IN(1);
else
B = ModelViewMatrix * vec4(POSITION_IN(0).xyz * v1/(v1-v0) - POSITION_IN(1).xyz * v0/(v1-v0) ,1.0);
}
else
{
if (v1 <= 0.0) //B not clipped
{
B = ModelViewMatrix *POSITION_IN(1);
A = ModelViewMatrix * vec4(POSITION_IN(1).xyz * v0/(v0-v1) - POSITION_IN(0).xyz * v1/(v0-v1) ,1.0);
}
}
*/
vec4 A = ModelViewMatrix*POSITION_IN(0);
vec4 B = ModelViewMatrix*POSITION_IN(1);
vec4 Ap = ProjectionMatrix*A;
vec4 Bp = ProjectionMatrix*B;
vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w)); vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w));
vec3 U = vec3(lineWidth*U3); vec3 U = vec3(lineWidth*U3);
vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0); vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0);
fragClip = posClip[0];
fragColor = vcolor[0]; fragColor = vcolor[0];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-U, 1.0); gl_Position = ProjectionMatrix*vec4(A.xyz-U, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz+V, 1.0); gl_Position = ProjectionMatrix*vec4(A.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-V, 1.0); gl_Position = ProjectionMatrix*vec4(A.xyz-V, 1.0);
EmitVertex(); EmitVertex();
fragClip = posClip[1];
fragColor = vcolor[1]; fragColor = vcolor[1];
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+V, 1.0); gl_Position = ProjectionMatrix*vec4(B.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz-V, 1.0); gl_Position = ProjectionMatrix*vec4(B.xyz-V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+U, 1.0); gl_Position = ProjectionMatrix*vec4(B.xyz+U, 1.0);
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
} }
...@@ -2,14 +2,12 @@ ...@@ -2,14 +2,12 @@
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor; ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 vcolor; VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition;
vcolor = VertexColor; vcolor = VertexColor;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0); gl_Position = vec4 (VertexPosition, 1.0);
} }
// ShaderBold3DLines::fragmentShaderText // ShaderBold3DLines::fragmentShaderText
PRECISION; PRECISION;
uniform vec4 lineColor; uniform vec4 lineColor;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = lineColor; FRAG_OUT = lineColor;
} }
// ShaderBold3DLines::geometryShaderText // ShaderBold3DLines::geometryShaderText
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform float lineWidth; uniform float lineWidth;
VARYING_IN vec3 posClip[]; uniform vec4 planeClip;
VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 Ap = (ProjectionMatrix*POSITION_IN(0)); float v0 = dot(planeClip,POSITION_IN(0));
vec4 Bp = (ProjectionMatrix*POSITION_IN(1)); float v1 = dot(planeClip,POSITION_IN(1));
vec4 A = vec4(0.0,0.0,0.0,0.0);
vec4 B = vec4(0.0,0.0,0.0,0.0);
if (v0 <= 0.0) //A not clipped
{
A = ModelViewMatrix *POSITION_IN(0);
if (v1 <= 0.0)
B = ModelViewMatrix *POSITION_IN(1);
else
B = ModelViewMatrix * vec4(POSITION_IN(0).xyz * v1/(v1-v0) - POSITION_IN(1).xyz * v0/(v1-v0) ,1.0);
}
else
{
if (v1 <= 0.0) //B not clipped
{
B = ModelViewMatrix *POSITION_IN(1);
A = ModelViewMatrix * vec4(POSITION_IN(1).xyz * v0/(v0-v1) - POSITION_IN(0).xyz * v1/(v0-v1) ,1.0);
}
}
vec4 Ap = (ProjectionMatrix*A);
vec4 Bp = (ProjectionMatrix*B);
vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w)); vec3 U3 = normalize((Bp.xyz/Bp.w - Ap.xyz/Ap.w));
vec3 U = vec3(lineWidth*U3); vec3 U = vec3(lineWidth*U3);
vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0); vec3 V = vec3(lineWidth*normalize(vec2(U[1],-U[0])), 0.0);
fragClip = posClip[0]; gl_Position = ProjectionMatrix*vec4(A.xyz-U, 1.0);
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-U, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz+V, 1.0); gl_Position = ProjectionMatrix*vec4(A.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(0).xyz-V, 1.0); gl_Position = ProjectionMatrix*vec4(A.xyz-V, 1.0);
EmitVertex(); EmitVertex();
fragClip = posClip[1]; gl_Position = ProjectionMatrix*vec4(B.xyz+V, 1.0);
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz-V, 1.0); gl_Position = ProjectionMatrix*vec4(B.xyz-V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = ProjectionMatrix*vec4(POSITION_IN(1).xyz+U, 1.0); gl_Position = ProjectionMatrix*vec4(B.xyz+U, 1.0);
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
} }
// ShaderBold3DLines::vertexShaderText // ShaderBold3DLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition; posClip = VertexPosition;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0); gl_Position = vec4 (VertexPosition, 1.0);
} }
...@@ -4,14 +4,10 @@ PRECISION; ...@@ -4,14 +4,10 @@ PRECISION;
VARYING_FRAG vec3 fragColor; VARYING_FRAG vec3 fragColor;
uniform float alpha; uniform float alpha;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = vec4(fragColor,alpha); FRAG_OUT = vec4(fragColor,alpha);
} }
// ShaderBoldColorLines::geometryShaderText // ShaderBoldColorLines::geometryShaderText
uniform vec2 lineWidths; uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform vec2 lineWidths;
uniform vec4 planeClip;
VARYING_IN vec3 vcolor[]; VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor; VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 A = POSITION_IN(0); float v0 = dot(planeClip,POSITION_IN(0));
vec4 B = POSITION_IN(1); float v1 = dot(planeClip,POSITION_IN(1));
vec4 A = vec4(0.0,0.0,0.0,0.0);
vec4 B = vec4(0.0,0.0,0.0,0.0);
if (v0 <= 0.0) //A not clipped
{
A = ModelViewMatrix *POSITION_IN(0);
if (v1 <= 0.0)
B = ModelViewMatrix *POSITION_IN(1);
else
B = ModelViewMatrix * vec4(POSITION_IN(0).xyz * v1/(v1-v0) - POSITION_IN(1).xyz * v0/(v1-v0) ,1.0);
}
else
{
if (v1 <= 0.0) //B not clipped
{
B = ModelViewMatrix *POSITION_IN(1);
A = ModelViewMatrix * vec4(POSITION_IN(1).xyz * v0/(v0-v1) - POSITION_IN(0).xyz * v1/(v0-v1) ,1.0);
}
}
float nearZ = 1.0; float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0) if (ProjectionMatrix[2][2] != 1.0)
nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0); nearZ = - ProjectionMatrix[3][2] / (ProjectionMatrix[2][2] - 1.0);
if ((A.z < nearZ) || (B.z < nearZ)) if ((A.z < nearZ) || (B.z < nearZ))
{ {
if (A.z >= nearZ) if (A.z >= nearZ)
...@@ -28,16 +46,15 @@ void main() ...@@ -28,16 +46,15 @@ void main()
A = ProjectionMatrix*A; A = ProjectionMatrix*A;
B = ProjectionMatrix*B; B = ProjectionMatrix*B;
A = A/A.w; A = A/A.w;
B = B/B.w; B = B/B.w;
vec2 U2 = normalize(vec2(lineWidths[1],lineWidths[0])*(B.xy - A.xy)); vec2 U2 = normalize(vec2(lineWidths[1],lineWidths[0])*(B.xy - A.xy));
vec2 LWCorr =lineWidths * max(abs(U2.x),abs(U2.y)); vec2 LWCorr =lineWidths * max(abs(U2.x),abs(U2.y));
vec3 U = vec3(LWCorr*U2,0.0); vec3 U = vec3(LWCorr*U2,0.0);
vec3 V = vec3(LWCorr*vec2(U2[1], -U2[0]), 0.0); vec3 V = vec3(LWCorr*vec2(U2[1], -U2[0]), 0.0);
fragClip = posClip[0];
fragColor = vcolor[0]; fragColor = vcolor[0];
gl_Position = vec4(A.xyz-U, 1.0); gl_Position = vec4(A.xyz-U, 1.0);
EmitVertex(); EmitVertex();
...@@ -46,7 +63,6 @@ void main() ...@@ -46,7 +63,6 @@ void main()
gl_Position = vec4(A.xyz-V, 1.0); gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex(); EmitVertex();
fragClip = posClip[1];
fragColor = vcolor[1]; fragColor = vcolor[1];
gl_Position = vec4(B.xyz+V, 1.0); gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex(); EmitVertex();
...@@ -54,7 +70,7 @@ void main() ...@@ -54,7 +70,7 @@ void main()
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz+U, 1.0); gl_Position = vec4(B.xyz+U, 1.0);
EmitVertex(); EmitVertex();
EndPrimitive(); EndPrimitive();
} }
} }
...@@ -2,14 +2,11 @@ ...@@ -2,14 +2,11 @@
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
ATTRIBUTE vec3 VertexColor; ATTRIBUTE vec3 VertexColor;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 vcolor; VARYING_VERT vec3 vcolor;
VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition;
vcolor = VertexColor; vcolor = VertexColor;
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0); gl_Position = vec4(VertexPosition, 1.0);
} }
...@@ -2,13 +2,9 @@ ...@@ -2,13 +2,9 @@
PRECISION; PRECISION;
uniform vec4 lineColor; uniform vec4 lineColor;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = lineColor; FRAG_OUT = lineColor;
} }
// ShaderBoldLines::geometryShaderText // ShaderBoldLines::geometryShaderText
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform vec2 lineWidths; uniform vec2 lineWidths;
VARYING_IN vec3 posClip[]; uniform vec4 planeClip;
VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 A = POSITION_IN(0); float v0 = dot(planeClip,POSITION_IN(0));
vec4 B = POSITION_IN(1); float v1 = dot(planeClip,POSITION_IN(1));
vec4 A = vec4(0.0,0.0,0.0,0.0);
vec4 B = vec4(0.0,0.0,0.0,0.0);
if (v0 <= 0.0) //A not clipped
{
A = ModelViewMatrix *POSITION_IN(0);
if (v1 <= 0.0)
B = ModelViewMatrix *POSITION_IN(1);
else
B = ModelViewMatrix * vec4(POSITION_IN(0).xyz * v1/(v1-v0) - POSITION_IN(1).xyz * v0/(v1-v0) ,1.0);
}
else
{
if (v1 <= 0.0) //B not clipped
{
B = ModelViewMatrix *POSITION_IN(1);
A = ModelViewMatrix * vec4(POSITION_IN(1).xyz * v0/(v0-v1) - POSITION_IN(0).xyz * v1/(v0-v1) ,1.0);
}
}
float nearZ = 1.0; float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0) if (ProjectionMatrix[2][2] != 1.0)
...@@ -31,7 +51,6 @@ void main() ...@@ -31,7 +51,6 @@ void main()
vec3 U = vec3(LWCorr*U2,0.0); vec3 U = vec3(LWCorr*U2,0.0);
vec3 V = vec3(LWCorr*vec2(U2[1], -U2[0]), 0.0); vec3 V = vec3(LWCorr*vec2(U2[1], -U2[0]), 0.0);
fragClip = posClip[0];
gl_Position = vec4(A.xyz-U, 1.0); gl_Position = vec4(A.xyz-U, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(A.xyz+V, 1.0); gl_Position = vec4(A.xyz+V, 1.0);
...@@ -39,7 +58,6 @@ void main() ...@@ -39,7 +58,6 @@ void main()
gl_Position = vec4(A.xyz-V, 1.0); gl_Position = vec4(A.xyz-V, 1.0);
EmitVertex(); EmitVertex();
fragClip = posClip[1];
gl_Position = vec4(B.xyz+V, 1.0); gl_Position = vec4(B.xyz+V, 1.0);
EmitVertex(); EmitVertex();
gl_Position = vec4(B.xyz-V, 1.0); gl_Position = vec4(B.xyz-V, 1.0);
......
// ShaderBoldLines::vertexShaderText // ShaderBoldLines::vertexShaderText
ATTRIBUTE vec3 VertexPosition; ATTRIBUTE vec3 VertexPosition;
uniform mat4 ModelViewMatrix;
VARYING_VERT vec3 posClip;
INVARIANT_POS; INVARIANT_POS;
void main () void main ()
{ {
posClip = VertexPosition; gl_Position = vec4 (VertexPosition, 1.0);
gl_Position = ModelViewMatrix * vec4 (VertexPosition, 1.0);
} }
...@@ -4,14 +4,10 @@ PRECISION; ...@@ -4,14 +4,10 @@ PRECISION;
VARYING_FRAG vec3 fragColor; VARYING_FRAG vec3 fragColor;
uniform float alpha; uniform float alpha;
uniform vec4 planeClip;
VARYING_FRAG vec3 fragClip;
FRAG_OUT_DEF; FRAG_OUT_DEF;
void main() void main()
{ {
if (dot(planeClip,vec4(fragClip,1.0))>0.0)
discard;
FRAG_OUT = vec4(fragColor,alpha); FRAG_OUT = vec4(fragColor,alpha);
} }
// ShaderColorDarts::geometryShaderText // ShaderColorDarts::geometryShaderText
uniform mat4 ModelViewMatrix;
uniform mat4 ProjectionMatrix; uniform mat4 ProjectionMatrix;
uniform vec2 lineWidths; uniform vec2 lineWidths;
uniform vec4 planeClip;
VARYING_IN vec3 vcolor[]; VARYING_IN vec3 vcolor[];
VARYING_OUT vec3 fragColor; VARYING_OUT vec3 fragColor;
VARYING_IN vec3 posClip[];
VARYING_OUT vec3 fragClip;
void main() void main()
{ {
vec4 A = POSITION_IN(0); float v0 = dot(planeClip,POSITION_IN(0));
vec4 B = POSITION_IN(1); float v1 = dot(planeClip,POSITION_IN(1));
float scalePoint = 3.0;
vec4 A = vec4(0.0,0.0,0.0,0.0);
vec4 B = vec4(0.0,0.0,0.0,0.0);
if (v0 <= 0.0) //A not clipped
{
A = ModelViewMatrix *POSITION_IN(0);
if (v1 <= 0.0)
B = ModelViewMatrix *POSITION_IN(1);
else
B = ModelViewMatrix * vec4(POSITION_IN(0).xyz * v1/(v1-v0) - POSITION_IN(1).xyz * v0/(v1-v0) ,1.0);
}
else
{
if (v1 <= 0.0) //B not clipped
{
B = ModelViewMatrix *POSITION_IN(1);
A = ModelViewMatrix * vec4(POSITION_IN(1).xyz * v0/(v0-v1) - POSITION_IN(0).xyz * v1/(v0-v1) ,1.0);
scalePoint = 1.0;
}
}
float nearZ = 1.0; float nearZ = 1.0;
if (ProjectionMatrix[2][2] != 1.0) if (ProjectionMatrix[2][2] != 1.0)
...@@ -33,29 +53,27 @@ void main() ...@@ -33,29 +53,27 @@ void main()
B = B/B.w; B = B/B.w;
vec2 U2 = normalize(vec2(lineWidths[1],lineWidths[0])*(B.xy - A.xy)); vec2 U2 = normalize(vec2(lineWidths[1],lineWidths[0])*(B.xy - A.xy));
vec2 LWCorr =lineWidths * max(abs(U2.x),abs(U2.y)); vec3 U = vec3(lineWidths*U2,0.0)*scalePoint;
vec3 U = vec3(LWCorr*U2,0.0) * 3.0; vec3 V = vec3(lineWidths*vec2(U2[1], -U2[0]), 0.0) * scalePoint;
vec3 V = vec3(LWCorr*vec2(U2[1], -U2[0]), 0.0)*3.0;
fragClip = posClip[0];
fragColor = vcolor[0]; fragColor = vcolor[0];
gl_Position = vec4(