Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vmdspheresprite.frag

Go to the documentation of this file.
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: vmdspheresprite.frag,v $
00012  *      $Author: johns $        $Locker:  $             $State: Exp $
00013  *      $Revision: 1.3 $       $Date: 2020/02/24 21:25:51 $
00014  *
00015  ***************************************************************************/
00030 
00035 #version 110
00036 
00037 //
00038 // Fragment shader varying and uniform variable definitions for data 
00039 // supplied by VMD and/or the vertex shader
00040 //
00041 varying vec3 oglcolor;        // interpolated color from the vertex shader
00042 varying vec3 V;               // view direction vector
00043 
00044 uniform vec3 vmdlight0;       // VMD directional lights
00045 uniform vec3 vmdlight1;
00046 uniform vec3 vmdlight2;
00047 uniform vec3 vmdlight3;
00048 
00049 uniform vec3 vmdlight0H;      // Blinn halfway vectors for all four lights
00050 uniform vec3 vmdlight1H;
00051 uniform vec3 vmdlight2H;
00052 uniform vec3 vmdlight3H;
00053 
00054 uniform vec4 vmdlightscale;   // VMD light on/off state for all 4 VMD lights,
00055                               // represented as a scaling constant.  Could be
00056                               // done with on/off flags but ATI doesn't deal
00057                               // well with branching constructs, so this value
00058                               // is simply multiplied by the light's 
00059                               // contribution.  Hacky, but it works for now.
00060 
00061 uniform vec4 vmdmaterial;     // VMD material properties
00062                               // [0] is ambient (white ambient light only)
00063                               // [1] is diffuse
00064                               // [2] is specular
00065                               // [3] is shininess
00066 
00067 uniform float vmdopacity;     // VMD global alpha value
00068 
00069 uniform float vmdoutline;     // VMD outline shading
00070 
00071 uniform float vmdoutlinewidth;// VMD outline shading width
00072 
00073 uniform int vmdtransmode;     // VMD transparency mode
00074 
00075 uniform int vmdfogmode;       // VMD depth cueing / fog mode
00076 
00077 uniform int vmdtexturemode;   // VMD texture mode 0=off 1=modulate 2=replace
00078 uniform sampler3D vmdtex0;    // active 3-D texture map
00079 
00080 //
00081 // VMD Fragment Shader
00082 //
00083 void main(void) {
00084   // Texture coords for point sprites range from 0,0 to 1,1, so we use this
00085   // to compute which pixels fall on the sphere (circle)
00086   vec2 pos = gl_TexCoord[0].xy - vec2(0.5, 0.5);
00087   float r2 = pos.x*pos.x + pos.y*pos.y;
00088   if (r2 > 0.25)
00089     discard; // Discard fragments outside of the sphere (circle)
00090 
00091 #if 0
00092   vec3 texcolor;                    // texture color if needed
00093   // perform texturing operations for volumetric data start texture
00094   // fetch as early as possible to hide memory latency
00095   if (vmdtexturemode != 0) {
00096     texcolor = vec3(texture3D(vmdtex0, gl_TexCoord[0].xyz));
00097   }
00098 #endif
00099   
00100   // Compute the surface normal for fragments on the sphere
00101   //  vec3 N = normalize(vec3(pos.x, -pos.y, sqrt(0.25 - r2)));
00102   vec3 N = 2.0*vec3(pos.x, -pos.y, sqrt(0.25 - r2));
00103 
00104   // beginning of shading calculations
00105   float ambient = vmdmaterial[0];   // ambient
00106   float diffuse = 0.0;
00107   float specular = 0.0;
00108   float shininess = vmdmaterial[3]; // shininess 
00109 
00110   // calculate diffuse lighting contribution
00111   diffuse += max(0.0, dot(N, vmdlight0)) * vmdlightscale[0];
00112   diffuse += max(0.0, dot(N, vmdlight1)) * vmdlightscale[1];
00113   diffuse += max(0.0, dot(N, vmdlight2)) * vmdlightscale[2];
00114   diffuse += max(0.0, dot(N, vmdlight3)) * vmdlightscale[3];
00115   diffuse *= vmdmaterial[1]; // diffuse scaling factor
00116 
00117   // compute edge outline if enabled
00118   if (vmdoutline > 0.0) {
00119     float edgefactor = dot(N,V);
00120     edgefactor = 1.0 - (edgefactor*edgefactor);
00121     edgefactor = 1.0 - pow(edgefactor, (1.0-vmdoutlinewidth)*32.0);
00122     diffuse = mix(diffuse, diffuse * edgefactor, vmdoutline);
00123   }
00124 
00125   // calculate specular lighting contribution with Phong highlights, based
00126   // on Blinn's halfway vector variation of Phong highlights
00127   specular += pow(max(0.0, dot(N, vmdlight0H)), shininess) * vmdlightscale[0];
00128   specular += pow(max(0.0, dot(N, vmdlight1H)), shininess) * vmdlightscale[1];
00129   specular += pow(max(0.0, dot(N, vmdlight2H)), shininess) * vmdlightscale[2];
00130   specular += pow(max(0.0, dot(N, vmdlight3H)), shininess) * vmdlightscale[3];
00131   specular *= vmdmaterial[2]; // specular scaling factor
00132 
00133   // Fog computations
00134   const float Log2E = 1.442695; // = log2(2.718281828)
00135   float fog = 1.0;
00136   if (vmdfogmode == 1) {
00137     // linear fog
00138     fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;
00139   } else if (vmdfogmode == 2) {
00140     // exponential fog
00141     fog = exp2(-gl_Fog.density * gl_FogFragCoord * Log2E);
00142   } else if (vmdfogmode == 3) { 
00143     // exponential-squared fog
00144     fog = exp2(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord * Log2E);
00145   }
00146   fog = clamp(fog, 0.0, 1.0);       // clamp the final fog parameter [0->1)
00147 
00148   vec3 objcolor = oglcolor * vec3(diffuse);         // texturing is disabled
00149 #if 0
00150   if (vmdtexturemode == 1) {
00151     objcolor = oglcolor * texcolor * vec3(diffuse); // emulate GL_MODULATE
00152   } else if (vmdtexturemode == 2) {
00153     objcolor = texcolor;                            // emulate GL_REPLACE
00154   } 
00155 #endif
00156 
00157   vec3 color = objcolor + vec3(ambient + specular);
00158 
00159   float alpha = vmdopacity;
00160 
00161   // Emulate Raster3D's angle-dependent surface opacity if enabled
00162   if (vmdtransmode==1) {
00163     alpha = 1.0 + cos(3.1415926 * (1.0-alpha) * dot(N,V));
00164     alpha = alpha*alpha * 0.25;
00165   }
00166 
00167   gl_FragColor = vec4(mix(vec3(gl_Fog.color), color, fog), alpha);
00168 }
00169 
00170 

Generated on Thu Mar 28 02:44:22 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002