00001 /*************************************************************************** 00002 *cr 00003 *cr (C) Copyright 1995-2011 The Board of Trustees of the 00004 *cr University of Illinois 00005 *cr All Rights Reserved 00006 *cr 00007 ***************************************************************************/ 00008 /*************************************************************************** 00009 * RCS INFORMATION: 00010 * 00011 * $RCSfile: vmdsphere.vert,v $ 00012 * $Author: johns $ $Locker: $ $State: Exp $ 00013 * $Revision: 1.18 $ $Date: 2020/02/24 21:25:51 $ 00014 * 00015 ***************************************************************************/ 00029 00031 #version 110 00032 00033 // 00034 // Vertex shader varying and uniform variable definitions for data 00035 // supplied by VMD. 00036 // 00037 uniform int vmdprojectionmode; 00038 uniform int vmdtexturemode; 00039 00040 // 00041 // Outputs to fragment shader 00042 // 00043 varying vec3 oglcolor; 00044 varying vec3 V; 00045 varying vec3 spherepos; 00046 varying vec3 rayorigin; 00047 varying float sphereradsq; 00048 00052 void main(void) { 00053 // transform vertex to Eye space for user clipping plane calculations 00054 vec4 ecpos = gl_ModelViewMatrix * gl_Vertex; 00055 gl_ClipVertex = ecpos; 00056 00057 // pass along vertex color for use fragment shading, 00058 // fragment shader will get an interpolated color. 00059 oglcolor = vec3(gl_Color); 00060 00061 // Sphere-specific rendering calculations 00062 // Transform sphere location 00063 vec4 spos = gl_ModelViewMatrix * vec4(0, 0, 0, 1.0); 00064 spherepos = vec3(spos) / spos.w; 00065 00066 // setup fog coordinate for fragment shader, use sphere center 00067 gl_FogFragCoord = abs(spos.z); 00068 00069 // transform sphere radius 00070 vec4 rspos = gl_ModelViewMatrix * vec4(1.0, 0, 0, 1.0); 00071 sphereradsq = length(spherepos - (vec3(rspos) / rspos.w)); 00072 sphereradsq *= sphereradsq; // square it, to save time in frag shader 00073 00074 if (vmdprojectionmode == 1) { 00075 // set view direction vector from eye coordinate of vertex, for 00076 // perspective views 00077 V = normalize(vec3(ecpos) / ecpos.w); 00078 rayorigin = vec3(0,0,0); 00079 } else { 00080 // set view direction vector with constant eye coordinate, used for 00081 // orthographic views 00082 V = vec3(0.0, 0.0, -1.0); 00083 rayorigin = vec3((ecpos.xy / ecpos.w), 0.0); 00084 } 00085 00086 // transform vertex to Clip space 00087 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 00088 } 00089 00090 00091