1 /*
  2   Copyright (c) 2008 Seneca College
  3   Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
  4 */
  5 
  6 c3dl.sepia_vs =   
  7 
  8 "attribute vec3 Vertex;" + 
  9 "attribute vec3 Normal;" + 
 10 "attribute vec3 Texture;" + 
 11 
 12 // for every model we multiply the projection, view and model matrices
 13 // once to prevent having to do it for every vertex, however we still need
 14 // the view matrix to calculate lighting.
 15 "uniform mat4 modelViewMatrix;" +
 16 
 17 // we can calculate this once per model to speed up processing done on the js side.
 18 "uniform mat4 modelViewProjMatrix;" +
 19 
 20 // matrix to transform the vertex normals
 21 "uniform mat4 normalMatrix;" + 
 22 
 23 
 24 "void main(void){" + 
 25 
 26 	// create a normal matrix 3x3 out of 4x4
 27 "	mat3 normalMatrix3x3 = mat3(normalMatrix[0][0],normalMatrix[0][1],normalMatrix[0][2]," +
 28 "								normalMatrix[1][0],normalMatrix[1][1],normalMatrix[1][2]," +
 29 "								normalMatrix[2][0],normalMatrix[2][1],normalMatrix[2][2]);" + 
 30 "	vec3 transformNormal = normalize(normalMatrix3x3 * Normal);" + 
 31 
 32 //
 33 "	vec3 ambient  = vec3(0.0, 0.0, 0.0);" + 
 34 "	vec3 diffuse  = vec3(0.0, 0.0, 0.0);" + 
 35 "	vec3 specular = vec3(0.0, 0.0, 0.0);" +
 36 
 37 	// place the current vertex into view space
 38 	// ecPos = eye coordinate position.
 39 "	vec4 ecPos4 = modelViewMatrix * vec4(Vertex,1.0);" +
 40 
 41 	// the current vertex in eye coordinate space
 42 	// perspective divide
 43 "	vec3 ecPos = (vec3(ecPos4))/ecPos4.w;" +
 44 
 45 "	vec3 eye = vec3(0.0, 0.0, 1.0);" +
 46 
 47 "	float shine = 1.0;" +
 48 "	if(usingMaterial)" +
 49 "	{" +
 50 "		shine = material.shininess;" +
 51 "	}" +
 52 
 53 "	if(lightingOn)" +
 54 "	{" +
 55 		// iterate over all the lights, and keep incrementing color values
 56 		// the color values are passed by reference and modified.
 57 "		for(int i = 0; i < C3DL_MAX_LIGHTS; i++)" +
 58 "		{" +
 59 "			if(lights[i].isOn) " +
 60 "			{" +
 61 "				if(lights[i].type == 1)" +
 62 "				{" +
 63 "					c3dl_DirectionalLight(lights[i], transformNormal, ambient, diffuse, specular, shine);" +
 64 "				}" +
 65 
 66 "				else if(lights[i].type == 2) " +
 67 "				{" +
 68 "					c3dl_PointLight(lights[i], transformNormal, eye, ecPos, ambient, diffuse, specular, shine);" +
 69 "				}" +
 70 
 71 "				else if(lights[i].type == 3)" +
 72 "				{" +
 73 "					c3dl_SpotLight(lights[i], transformNormal, eye, ecPos, ambient, diffuse, specular, shine);" +
 74 "				}" +
 75 "			}" +
 76 "		}" +
 77 "	}" +
 78 
 79 "	if( usingMaterial ){" +
 80 "		gl_FrontColor =	vec4(material.emission +				" +
 81 "							ambientLightColor +					" +
 82 "							ambient * material.ambient +		" +
 83 "							diffuse * material.diffuse +		" +
 84 "							specular * material.specular,1.0);	" +
 85 "	}" +
 86 "	else{" +
 87 "		gl_FrontColor = vec4(ambientLightColor + ambient + diffuse + specular,1.0);" +
 88 "	}" +
 89 
 90 "	gl_Position =  modelViewProjMatrix * vec4(Vertex, 1.0);" +
 91 "	gl_TexCoord[0] = vec4(Texture,1.0);" + 
 92 "}";
 93