eVolve/vertexShader_glsl.h
00001
00002 static const std::string vertexShader_glsl = "/* Copyright (c) 2007 Maxim Makhinya\n *\n * This library is free software; you can redistribute it and/or modify it under\n * the terms of the GNU Lesser General Public License version 2.1 as published\n * by the Free Software Foundation.\n * \n * This library is distributed in the hope that it will be useful, but WITHOUT\n * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\n * details.\n * \n * You should have received a copy of the GNU Lesser General Public License\n * along with this library; if not, write to the Free Software Foundation, Inc.,\n * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n */\n \n #version 110\n \n // updated per frame\n uniform float sliceDistance;\n uniform float perspProj;\n \n \n uniform float W; //scale for x\n uniform float H; //scale for y\n uniform float D; //scale for z\n uniform float Do; //shift of z\n uniform float Db; //z offset \n \n void main(void)\n {\n gl_TexCoord[0] = 0.5 * gl_Vertex + 0.5;\n \n vec4 vDir = normalize(gl_ModelViewMatrixInverse * vec4(0.,0.,-1.,1.));\n \n //compute position of virtual back vertex\n vec4 vPosition = gl_ModelViewMatrixInverse*vec4(0,0,0,1);\n \n vec4 eyeToVert = normalize(gl_Vertex - vPosition);\n \n // perspective/parallel projection sellection\n vec4 shift = eyeToVert * (sliceDistance / dot(vDir,eyeToVert)) * perspProj +\n vDir * sliceDistance * ( 1.0 - perspProj );\n \n gl_TexCoord[1] = gl_Vertex + shift;\n \n //compute texture coordinates for virtual back vertex\n gl_TexCoord[1] = 0.5 * gl_TexCoord[1] + 0.5;\n \n \n //Scaling of texture coordinates\n gl_TexCoord[0].x *= W;\n gl_TexCoord[0].y *= H;\n gl_TexCoord[0].z = Db + (gl_TexCoord[0].z - Do) * D;\n \n gl_TexCoord[1].x *= W;\n gl_TexCoord[1].y *= H;\n gl_TexCoord[1].z = Db + (gl_TexCoord[1].z - Do) * D;\n \n gl_Position = ftransform();\n }\n ";