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.17 $ $Date: 2010/12/16 04:10:13 $ 00014 * 00015 *************************************************************************** 00016 * DESCRIPTION: 00017 * This file contains the VMD OpenGL vertex shader implementing 00018 * a ray-traced sphere primitive with per-pixel lighting, 00019 * phong highlights, etc. The sphere is drawn within the confines of a 00020 * correctly transformed bounding cube or viewer-aligned billboard. 00021 * Much of the shading code is shared with the main VMD vertex shader, 00022 * with a few optimizations that simplify the sphere shader due to the 00023 * way it is specifically known to be used within VMD. (certain texturing 00024 * modes can't actually occur in practice, so the shader can be simplified 00025 * relative to what the main fragment shader must implement. 00026 ***************************************************************************/ 00027 00028 // requires GLSL version 1.10 00029 #version 110 00030 00031 // 00032 // Vertex shader varying and uniform variable definitions for data 00033 // supplied by VMD. 00034 // 00035 uniform int vmdprojectionmode; // perspective=1 orthographic=0 00036 uniform int vmdtexturemode; // VMD texture mode 00037 00038 // 00039 // Outputs to fragment shader 00040 // 00041 varying vec3 oglcolor; // output interpolated color to frag shader 00042 varying vec3 V; // output view direction vector 00043 varying vec3 spherepos; // output transformed sphere position 00044 varying vec3 rayorigin; // output ray origin 00045 varying float sphereradsq; // output transformed sphere radius squared 00046 00047 // 00048 // VMD Sphere Vertex Shader 00049 // 00050 void main(void) { 00051 // transform vertex to Eye space for user clipping plane calculations 00052 vec4 ecpos = gl_ModelViewMatrix * gl_Vertex; 00053 gl_ClipVertex = ecpos; 00054 00055 // pass along vertex color for use fragment shading, 00056 // fragment shader will get an interpolated color. 00057 oglcolor = vec3(gl_Color); 00058 00059 // Sphere-specific rendering calculations 00060 // Transform sphere location 00061 vec4 spos = gl_ModelViewMatrix * vec4(0, 0, 0, 1.0); 00062 spherepos = vec3(spos) / spos.w; 00063 00064 // setup fog coordinate for fragment shader, use sphere center 00065 gl_FogFragCoord = abs(spos.z); 00066 00067 // transform sphere radius 00068 vec4 rspos = gl_ModelViewMatrix * vec4(1.0, 0, 0, 1.0); 00069 sphereradsq = length(spherepos - (vec3(rspos) / rspos.w)); 00070 sphereradsq *= sphereradsq; // square it, to save time in frag shader 00071 00072 if (vmdprojectionmode == 1) { 00073 // set view direction vector from eye coordinate of vertex, for 00074 // perspective views 00075 V = normalize(vec3(ecpos) / ecpos.w); 00076 rayorigin = vec3(0,0,0); 00077 } else { 00078 // set view direction vector with constant eye coordinate, used for 00079 // orthographic views 00080 V = vec3(0.0, 0.0, -1.0); 00081 rayorigin = vec3((ecpos.xy / ecpos.w), 0.0); 00082 } 00083 00084 // transform vertex to Clip space 00085 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 00086 } 00087 00088 00089
1.2.14 written by Dimitri van Heesch,
© 1997-2002