Source code of the vertex shader

Property definitions

gamnit $ GamnitProgramFromSource :: vertex_shader_source
	# Source code of the vertex shader
	fun vertex_shader_source: Text is abstract
lib/gamnit/programs.nit:498,2--499,43

gamnit $ Simple2dProgram :: vertex_shader_source
	redef var vertex_shader_source = """
		// Vertex coordinates
		attribute vec4 coord;

		// Vertex color tint
		attribute vec4 color;

		// Vertex translation
		attribute vec4 translation;

		// Vertex scaling
		attribute float scale;

		// Vertex coordinates on textures
		attribute vec2 tex_coord;

		// Model view projection matrix
		uniform mat4 mvp;

		// Current world time, in seconds
		uniform float time;

		// Rotation matrix
		attribute vec4 rotation_row0;
		attribute vec4 rotation_row1;
		attribute vec4 rotation_row2;
		attribute vec4 rotation_row3;

		// Animation speed, frames per seconds
		attribute float a_fps;

		// Number of frames in the animation
		attribute float a_n_frames;

		// World coordinate of the animation (for aspect ratio)
		attribute vec2 a_coord;

		// Animation texture coordinates of the first frame
		attribute vec2 a_tex_coord;

		// Animation texture coordinates difference between frames
		attribute vec2 a_tex_diff;

		// Animation start time, in reference to `time`
		attribute float a_start;

		// Number of loops to play of the animation
		attribute float a_loops;

		mat4 rotation()
		{
			return mat4(rotation_row0, rotation_row1, rotation_row2, rotation_row3);
		}

		// Output to the fragment shader
		varying vec4 v_color;
		varying vec2 v_coord;

		// Is there an active animation?
		varying float v_animated;

		void main()
		{
			vec3 c; // coords

			float end = a_start + a_loops/a_fps*a_n_frames;
			if (a_fps != 0.0 && (a_loops == -1.0 || time < end)) {
				// in animation
				float frame = mod(floor((time-a_start)*a_fps), a_n_frames);
				v_coord = a_tex_coord + a_tex_diff*frame;
				c = vec3(a_coord, coord.z);
				v_animated = 1.0;
			} else {
				// static
				v_coord = tex_coord;
				c = coord.xyz;
				v_animated = 0.0;
			}

			gl_Position = (vec4(c * scale, 1.0) * rotation() + translation)* mvp;
			v_color = vec4(color.rgb*color.a, color.a);
		}
		""" @ glsl_vertex_shader
lib/gamnit/flat/flat_core.nit:638,2--720,26

gamnit $ BlinnPhongProgram :: vertex_shader_source
	redef var vertex_shader_source = """
		// Vertex coordinates
		attribute vec4 coord;

		// Vertex translation
		attribute vec4 translation;

		// Vertex scaling
		attribute float scale;

		attribute float alpha;

		// Vertex coordinates on textures
		attribute vec2 tex_coord;

		// Vertex normal
		attribute vec3 normal;

		// Camera model view projection matrix
		uniform mat4 mvp;

		// Actor rotation
		attribute vec4 rotation_row0;
		attribute vec4 rotation_row1;
		attribute vec4 rotation_row2;
		attribute vec4 rotation_row3;

		mat4 rotation()
		{
			return mat4(rotation_row0, rotation_row1, rotation_row2, rotation_row3);
		}

		// Lights config
		uniform lowp int light_kind;
		uniform vec3 light_center;
		uniform mat4 light_mvp;

		// Coordinates of the camera
		uniform vec3 camera;

		// Output for the fragment shader
		varying vec2 v_tex_coord;
		varying vec3 v_normal;
		varying vec4 v_to_light;
		varying vec4 v_to_camera;
		varying vec4 v_depth_pos;
		varying float v_alpha;

		void main()
		{
			mat4 rotation = rotation();
			vec4 pos = (vec4(coord.xyz * scale, 1.0) * rotation + translation);
			gl_Position = pos * mvp;
			v_depth_pos = (pos * light_mvp) * 0.5 + 0.5;

			// Pass varyings to the fragment shader
			v_tex_coord = vec2(tex_coord.x, 1.0 - tex_coord.y);
			v_normal = normalize(vec4(normal, 0.0) * rotation).xyz;
			v_to_camera = normalize(vec4(camera, 1.0) - pos);

			if (light_kind == 0) {
				// No light
			} else if (light_kind == 1) {
				// Parallel
				v_to_light = normalize(vec4(light_center, 1.0));
			} else {
				// Point light (and others?)
				v_to_light = normalize(vec4(light_center, 1.0) - pos);
			}

			v_alpha = alpha;
		}
		""" @ glsl_vertex_shader
lib/gamnit/depth/more_materials.nit:318,2--390,26