diff --git a/plugins/mmstd_moldyn/Shaders/sphere/vertex_spheretouchplane.glsl b/plugins/mmstd_moldyn/Shaders/sphere/vertex_spheretouchplane.glsl index 9f221e772e..053fba148d 100644 --- a/plugins/mmstd_moldyn/Shaders/sphere/vertex_spheretouchplane.glsl +++ b/plugins/mmstd_moldyn/Shaders/sphere/vertex_spheretouchplane.glsl @@ -22,6 +22,7 @@ vec3 testPos; vec4 projPos; +#if 0 // projected camera vector vec3 c2 = vec3(dot(camPos.xyz, camRight), dot(camPos.xyz, camUp), dot(camPos.xyz, camIn)); @@ -77,3 +78,53 @@ testPos = objPos.xyz - camIn * rad; projPos = MVP * vec4(testPos, 1.0); projPos /= projPos.w; +#else + + vec3 base_vec = (-camPos.xyz); + float bv = length(base_vec); + + //vec3 cc = vec3(dot(base_vec, camRight), dot(base_vec, camUp), dot(base_vec, camIn)); + + //vec3 hv = normalize(-cc.z*camRight+cc.x*camIn); + //vec3 uv = normalize(cross(hv, base_vec)); + + vec3 in_v = normalize(base_vec); + vec3 up = normalize(cross(in_v, camRight)); + vec3 right = normalize(cross(in_v, up)); + up = normalize(cross(in_v, right)); + + float pe = squarRad/bv; + float h2 = squarRad-pe*pe; + float ha = sqrt(h2); + //float qu = bv-pe; + //float x = ha/qu*(qu-rad+pe); + + vec3 plane_base = objPos.xyz - in_v*pe; + vec3 corner_0 = plane_base-right*ha-up*ha; + vec3 corner_1 = plane_base+right*ha-up*ha; + vec3 corner_2 = plane_base+right*ha+up*ha; + vec3 corner_3 = plane_base-right*ha+up*ha; + + projPos=MVP*vec4(corner_0,1.0); + projPos/=projPos.w; + mins = projPos.xy; + maxs = projPos.xy; + + projPos=MVP*vec4(corner_1,1.0); + projPos/=projPos.w; + mins = min(mins, projPos.xy); + maxs = max(maxs, projPos.xy); + + projPos=MVP*vec4(corner_2,1.0); + projPos/=projPos.w; + mins = min(mins, projPos.xy); + maxs = max(maxs, projPos.xy); + + projPos=MVP*vec4(corner_3,1.0); + projPos/=projPos.w; + mins = min(mins, projPos.xy); + maxs = max(maxs, projPos.xy); + + projPos=MVP*vec4(objPos.xyz - camIn*rad,1.0); + projPos/=projPos.w; +#endif