<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<geexlab>

    <window name="win3d01" title="glTF loading"
          width="800" height="600"
          gl_version_major="3" gl_version_minor="2" />


	<script name="init_scene" run_mode="INIT" filename="init.lua" />

	<script name="update_scene" run_mode="FRAME" filename="frame.lua" livecoding="1" />




	<script name="resize_scene" run_mode="SIZE" >
		<raw_data><![CDATA[

winW, winH = gh_window.getsize(0)

local aspect = 1.333
if (winH > 0) then
  aspect = winW / winH
end
gh_camera.update_persp(camera, camera_fov, aspect, 1, 1000.0)
gh_camera.set_viewport(camera, 0, 0, winW, winH)

		]]></raw_data>
	</script>






  <gpu_program name="lighting_prog" >
    <raw_data_vs><![CDATA[
#version 150
in vec4 gxl3d_Position;
in vec4 gxl3d_Normal;
in vec4 gxl3d_TexCoord0;
uniform mat4 gxl3d_ModelViewProjectionMatrix; // GeeXLab built-in uniform.
uniform mat4 gxl3d_ModelViewMatrix; // GeeXLab built-in uniform.
uniform mat4 gxl3d_ViewMatrix; // GeeXLab built-in uniform.
uniform vec4 light_position;
out vec4 Vertex_N;
out vec4 Vertex_L;
out vec4 Vertex_E;
out vec4 Vertex_UV;

void main()
{
  gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;
  Vertex_UV = gxl3d_TexCoord0;
  Vertex_N = gxl3d_ModelViewMatrix * gxl3d_Normal;
  vec4 view_vertex = gxl3d_ModelViewMatrix * gxl3d_Position;
  vec4 lp = gxl3d_ViewMatrix * light_position;
  Vertex_L = lp - view_vertex;
  Vertex_E = -view_vertex;
}
  ]]></raw_data_vs>
    <raw_data_ps><![CDATA[
#version 150
in vec4 Vertex_N;
in vec4 Vertex_L;
in vec4 Vertex_E;
in vec4 Vertex_UV;

out vec4 Out_Color;
void main()
{
  vec2 uv = Vertex_UV.xy;

  vec3 final_color = vec3(0.15, 0.10, 0.08);
  vec3 N = normalize(Vertex_N.xyz);
  vec3 L = normalize(Vertex_L.xyz);
  float lambertTerm = dot(N,L);
  if (lambertTerm > 0.0)
  {
    final_color += vec3(0.4, 0.6, 0.7) * lambertTerm;
    vec3 E = normalize(Vertex_E.xyz);
    vec3 R = reflect(-L, N);
    float specular = pow( max(dot(R, E), 0.0), 90.0);
    final_color += vec3(0.9, 0.9, 0.8) * specular;
  }
  Out_Color.rgb = final_color;
  Out_Color.a = 1.0;
}
    ]]></raw_data_ps>
  </gpu_program>



	<gpu_program name="color_prog" >
    <raw_data_vs><![CDATA[
#version 150
in vec4 gxl3d_Position;
in vec4 gxl3d_Color;
uniform mat4 gxl3d_ModelViewProjectionMatrix; // GXL3D built-in uniform.
out vec4 Vertex_C;
void main()
{
  gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;
  Vertex_C = gxl3d_Color;
}
  ]]></raw_data_vs>
    <raw_data_ps><![CDATA[
#version 150
in vec4 Vertex_C;
out vec4 FragColor;
void main()
{
  FragColor = Vertex_C;
}
    ]]></raw_data_ps>
  </gpu_program>



</geexlab>
