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: vmd.vert,v $ 00012 * $Author: johns $ $Locker: $ $State: Exp $ 00013 * $Revision: 1.29 $ $Date: 2020/02/24 21:25:51 $ 00014 * 00015 ***************************************************************************/ 00021 00023 #version 110 00024 00025 // 00026 // Vertex shader varying and uniform variable definitions for data 00027 // supplied by VMD. 00028 // 00029 uniform int vmdprojectionmode; 00030 uniform int vmdtexturemode; 00031 00032 // 00033 // Outputs to fragment shader 00034 // 00035 varying vec3 oglnormal; 00036 varying vec3 oglcolor; 00037 varying vec3 V; 00038 00042 void main(void) { 00043 // transform vertex to Eye space for user clipping plane calculations 00044 vec4 ecpos = gl_ModelViewMatrix * gl_Vertex; 00045 gl_ClipVertex = ecpos; 00046 00047 // transform, normalize, and output normal. 00048 oglnormal = normalize(gl_NormalMatrix * gl_Normal); 00049 00050 // pass along vertex color for use fragment shading, 00051 // fragment shader will get an interpolated color. 00052 oglcolor = vec3(gl_Color); 00053 00054 // setup fog coordinate for fragment shader 00055 gl_FogFragCoord = abs(ecpos.z); 00056 00057 if (vmdprojectionmode == 1) { 00058 // set view direction vector from eye coordinate of vertex, for 00059 // perspective views 00060 V = normalize(vec3(ecpos) / ecpos.w); 00061 } else { 00062 // set view direction vector with constant eye coordinate, used for 00063 // orthographic views 00064 V = vec3(0.0, 0.0, -1.0); 00065 } 00066 00067 // mode 0 disables texturing 00068 // mode 1 enables texturing, emulating GL_MODULATE, with linear texgen 00069 // mode 2 enables texturing, emulating GL_REPLACE, with linear texgen 00070 if (vmdtexturemode != 0) { 00071 // transform texture coordinates as would be done by linear texgen 00072 gl_TexCoord[0].s = dot(ecpos, gl_EyePlaneS[0]); 00073 gl_TexCoord[0].t = dot(ecpos, gl_EyePlaneT[0]); 00074 gl_TexCoord[0].p = dot(ecpos, gl_EyePlaneR[0]); 00075 gl_TexCoord[0].q = dot(ecpos, gl_EyePlaneQ[0]); 00076 } 00077 00078 // transform vertex to Clip space 00079 #if 1 00080 // not all drivers support ftransform() yet. 00081 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 00082 #else 00083 // We should exactly duplicate the fixed-function pipeline transform 00084 // since VMD renders the scene in multiple passes, some of which must 00085 // continue to use the fixed-function pipeline. 00086 gl_Position = ftransform(); 00087 #endif 00088 00089 } 00090 00091 00092