cylinder.vs (pymol-v2.1.0.tar.bz2) | : | cylinder.vs (pymol-open-source-2.2.0) | ||
---|---|---|---|---|
#include webgl_header.vs | ||||
// cylinder imposter vertex shader | // cylinder imposter vertex shader | |||
attribute vec4 attr_origin; | attribute vec3 attr_vertex1; | |||
attribute vec4 attr_axis; | attribute vec3 attr_vertex2; | |||
attribute vec4 attr_colors; | attribute vec4 a_Color; | |||
attribute vec4 attr_colors2; | attribute vec4 a_Color2; | |||
attribute float attr_radius; | ||||
uniform float uni_radius; | attribute float a_cap; | |||
//varying vec3 point; // surface point | attribute float attr_flags; | |||
//varying vec3 axis; // cylinder axis | varying vec3 surface_point ; | |||
//varying vec3 base; // cylinder base | varying vec3 axis ; | |||
//varying vec3 end; // cylinder end | varying vec3 base ; | |||
//varying vec3 U; // cylinder base plane coordinates | varying vec3 end_cyl ; | |||
//varying vec3 V; | varying vec3 U ; | |||
//varying float radius; // radius | varying vec3 V ; | |||
//varying float cap; // should we draw the endcap | varying float radius; | |||
//varying float inv_sqr_height; | varying float cap; | |||
varying float inv_sqr_height; | ||||
varying vec4 packed_data_0 ; | ||||
varying vec4 packed_data_1 ; | ||||
varying vec4 packed_data_2 ; | ||||
varying vec4 packed_data_3 ; | ||||
varying vec4 packed_data_4 ; | ||||
varying vec4 packed_data_5 ; | ||||
#define point ( packed_data_0.xyz ) | ||||
#define axis ( packed_data_1.xyz ) | ||||
#define base ( packed_data_2.xyz ) | ||||
#define end ( packed_data_3.xyz ) | ||||
#define U ( packed_data_4.xyz ) | ||||
#define V ( packed_data_5.xyz ) | ||||
#define radius (packed_data_3.w) | ||||
#define cap (packed_data_4.w) | ||||
#define inv_sqr_height (packed_data_5.w) | ||||
varying vec4 color1; | varying vec4 color1; | |||
varying vec4 color2; | varying vec4 color2; | |||
varying vec2 bgTextureLookup; | varying vec2 bgTextureLookup; | |||
uniform vec2 pixelSize; | ||||
uniform float uni_radius; | ||||
// get_bit_and_shift: returns 0 or 1 | ||||
float get_bit_and_shift(inout float bits) { | ||||
float bit = mod(bits, 2.0); | ||||
bits = (bits - bit) / 2.0; | ||||
return step(.5, bit); | ||||
} | ||||
void main(void) | void main(void) | |||
{ | { | |||
float uniformglscale = length(g_NormalMatrix[0]); | ||||
if (uni_radius!=0.0){ | if (uni_radius!=0.0){ | |||
radius = uni_radius * attr_origin.w; | radius = uni_radius * attr_radius; | |||
} else { | } else { | |||
radius = attr_origin.w; | radius = attr_radius; | |||
} | } | |||
color1 = attr_colors; | ||||
color2 = attr_colors2; | ||||
float packed_flags = attr_axis.w; | ||||
vec4 flags = mod(vec4(packed_flags/262144.0, packed_flags/4096.0, | color1 = a_Color; | |||
packed_flags/64.0, packed_flags), 64.0); | color2 = a_Color2; | |||
cap = flags.x; | vec3 attr_axis = attr_vertex2 - attr_vertex1; | |||
float right_v = flags.y; | cap = a_cap; | |||
float up_v = flags.z; | ||||
float out_v = flags.w; | ||||
// calculate reciprocal of squared height | // calculate reciprocal of squared height | |||
inv_sqr_height = length(attr_axis.xyz); | inv_sqr_height = length(attr_axis) / uniformglscale; | |||
inv_sqr_height *= inv_sqr_height; | inv_sqr_height *= inv_sqr_height; | |||
inv_sqr_height = 1.0 / inv_sqr_height; | inv_sqr_height = 1.0 / inv_sqr_height; | |||
// h is a normalized cylinder axis | // h is a normalized cylinder axis | |||
vec3 h = normalize(attr_axis.xyz); | vec3 h = normalize(attr_axis); | |||
// axis is the cylinder axis in modelview coordinates | // axis is the cylinder axis in modelview coordinates | |||
axis = normalize(gl_NormalMatrix * h); | axis = normalize(g_NormalMatrix * h); | |||
// u, v, h is local system of coordinates | // u, v, h is local system of coordinates | |||
vec3 u = cross(h, vec3(1.0, 0.0, 0.0)); | vec3 u = cross(h, vec3(1.0, 0.0, 0.0)); | |||
if (dot(u,u) < 0.001) | if (dot(u,u) < 0.001) | |||
u = cross(h, vec3(0.0, 1.0, 0.0)); | u = cross(h, vec3(0.0, 1.0, 0.0)); | |||
u = normalize(u); | u = normalize(u); | |||
vec3 v = normalize(cross(u, h)); | vec3 v = normalize(cross(u, h)); | |||
// transform to modelview coordinates | // transform to modelview coordinates | |||
U = normalize(gl_NormalMatrix * u); | U = normalize(g_NormalMatrix * u); | |||
V = normalize(gl_NormalMatrix * v); | V = normalize(g_NormalMatrix * v); | |||
// compute bounding box vertex position | vec4 base4 = g_ModelViewMatrix * vec4(attr_vertex1, 1.0); | |||
vec4 vertex = vec4(attr_origin.xyz, 1.0); | base = base4.xyz; | |||
vec4 end4 = g_ModelViewMatrix * vec4(attr_vertex2, 1.0); | ||||
end_cyl = end4.xyz; | ||||
vertex.xyz += up_v * attr_axis.xyz; | // compute bounding box vertex position | |||
vec4 vertex = vec4(attr_vertex1, 1.0); | ||||
float packed_flags = attr_flags; | ||||
float out_v = get_bit_and_shift(packed_flags); | ||||
float up_v = get_bit_and_shift(packed_flags); | ||||
float right_v = get_bit_and_shift(packed_flags); | ||||
vertex.xyz += up_v * attr_axis; | ||||
vertex.xyz += (2.0 * right_v - 1.0) * radius * u; | vertex.xyz += (2.0 * right_v - 1.0) * radius * u; | |||
vertex.xyz += (2.0 * out_v - 1.0) * radius * v; | vertex.xyz += (2.0 * out_v - 1.0) * radius * v; | |||
vertex.xyz += (2.0 * up_v - 1.0) * radius * h; | vertex.xyz += (2.0 * up_v - 1.0) * radius * h; | |||
vec4 base4 = gl_ModelViewMatrix * vec4(attr_origin.xyz, 1.0); | vec4 tvertex = g_ModelViewMatrix * vertex; | |||
base = base4.xyz / base4.w; | surface_point = tvertex.xyz; | |||
vec4 end4 = gl_ModelViewMatrix * vec4(attr_origin.xyz + 1.0 * attr_axis.xyz, | ||||
1.0); | ||||
end = end4.xyz / end4.w; | ||||
vec4 tvertex = gl_ModelViewMatrix * vertex; | gl_Position = g_ProjectionMatrix * g_ModelViewMatrix * vertex; | |||
point = tvertex.xyz / tvertex.w; | ||||
gl_Position = gl_ModelViewProjectionMatrix * vertex; | // support uniform scaling | |||
radius /= uniformglscale; | ||||
// clamp z on front clipping plane if impostor box would be clipped. | // clamp z on front clipping plane if impostor box would be clipped. | |||
// (we ultimatly want to clip on the calculated depth in the fragment | // (we ultimatly want to clip on the calculated depth in the fragment | |||
// shader, not the depth of the box face) | // shader, not the depth of the box face) | |||
if (gl_Position.z / gl_Position.w < -1.0) { | if (gl_Position.z / gl_Position.w < -1.0) { | |||
// upper bound of possible cylinder z extend | // upper bound of possible cylinder z extend | |||
float diff = abs(base4.z - end4.z) + radius * 3.5; | float diff = abs(base4.z - end4.z) + radius * 3.5; | |||
// z-`diff`-offsetted vertex | // z-`diff`-offsetted vertex | |||
vec4 inset = gl_ModelViewMatrix * vertex; | vec4 inset = g_ModelViewMatrix * vertex; | |||
inset.z -= diff; | inset.z -= diff; | |||
inset = gl_ProjectionMatrix * inset; | inset = g_ProjectionMatrix * inset; | |||
// if offsetted vertex is within front clipping plane, then clamp | // if offsetted vertex is within front clipping plane, then clamp | |||
if (inset.z / inset.w > -1.0) { | if (inset.z / inset.w > -1.0) { | |||
gl_Position.z = -gl_Position.w; | gl_Position.z = -gl_Position.w; | |||
} | } | |||
} | } | |||
bgTextureLookup = (gl_Position.xy/gl_Position.w) / 2.0 + 0.5; | bgTextureLookup = (gl_Position.xy/gl_Position.w) / 2.0 + 0.5; | |||
} | } | |||
End of changes. 23 change blocks. | ||||
71 lines changed or deleted | 59 lines changed or added |