Jonathan Hartley avatar Jonathan Hartley committed a142121

tidy and annotate shaders (probably will delete a lot of these commments once they are safely recorded in Hg)

Comments (0)

Files changed (2)

 Next
 ----
 
-* ambient light level should be a uniform shader var 
-  demo should populate this using world.background_color
-
 * function to truncate a shape - is this the same as transform towards its dual?
 
 * Add good shapes from previous programs
 Talk Outline
 ------------
 
-   1. Inspirations - Effective non-photo-realistic work in gaming, movies and
-      the demo scene. (1m)
-   2. A convenient & Pythonic way to model 3D polyhedra, and some neat
-      generators to convert these into OpenGL arrays at runtime. (7m)
-   3. Composition of polyhedra to create more complex shapes. (3m)
-   4. The resulting performance characteristics: What works well from Python,
-      and what doesn't. (2m)
-   5. Koch tetrahedron & tetrix, aka Sierpinski tetrahedron. (1m)
-   6. Surprisingly effective 3D models created from small bitmaps. (1m)
-   7. Automatic generation of trees, mazes, complex spaces. (3m)
-   8. Algorithmic modification of existing shapes, such as bevels, geometric
-      duals, and polyhedron stellation. (2m)
-   9. Shapes that morph: Rearranging vertices on the fly (5m)
-  10. Questions (5m)
+   * Inspirations - Effective non-photo-realistic work in gaming, movies and
+     the demo scene. (1m)
+   * A convenient & Pythonic way to model 3D polyhedra, and some neat
+     generators to convert these into OpenGL arrays at runtime. (7m)
+   * Algorithmic modification of existing shapes, such as bevels, geometric
+     duals, and polyhedron stellation. (2m)
+   * Composition of polyhedra to create more complex shapes. (3m)
+   * The resulting performance characteristics: What works well from Python,
+     and what doesn't. (2m)
+   * Koch tetrahedron & tetrix, aka Sierpinski tetrahedron. (1m)
+   * Surprisingly effective 3D models created from small bitmaps. (1m)
+   * Automatic generation of trees, mazes, complex spaces. (3m)
+   * Shapes that morph: Rearranging vertices on the fly (5m)
+   * Questions (5m)
 
 
 Infrastructure
   each adjacent participating face. Assume colors are fixed across the whole
   surface?
 
-* better shaders: incorporate the lighting shaders from pyopengl tutorials,
-  and provide a class which binds named uniforms to instance attributes
-  or somesuch. Does pyopengl already have such a class?
-* Control over ambient and directional light sources, as uniforms
-* Point light source(s) - pass in locations, colors, as uniforms
-* per pixel lighting so that specular highlights in middle of flat faces
-  look good
-* Textures. See:
-    http://www.lighthouse3d.com/opengl/glsl/index.php?textureComb
+* better shaders:
+    * ambient light level should be a uniform
+    * demo should populate this using world.background_color
+    * directional light position should be a uniform
+    * directional light color should be a uniform
+    * point light source position should be a uniform
+    * point light source color should be a uniform
+    * specular highlights from directional light
+    * specular highlights from point light
+    * demo should include a moving object that acts as point light source
+    * per pixel lighting so that specular highlights in middle of flat faces
+      look good
+    * Textures. See:
+      http://www.lighthouse3d.com/opengl/glsl/index.php?textureComb
+    * if skybox is drawn, demo should draw a 'sun' or 'moon' or somesuch
+      in direction of directional light source
 
 * Allow each gameitem to specify its own shader program
 

gloopy/shaders/lighting.vert

 
 // both parameters must be normalised
 float dLight( 
-    in vec3 light_pos, 
+    in vec3 light_dir, 
     in vec3 surface_norm
 ) {
-    float value = dot(surface_norm, light_pos);
-    // cheat to make directional light extend right across dark side of objects
+    float value = dot(surface_norm, light_dir);
+    // cheat to make effects of directional light extend across the dark side
+    // of objects. Hopefully this will be less necessary when more than one
+    // lightsource is in the scene.
     value = 0.5 + value * 0.5;
     return max(0.0, value);
 }
 
-//uniform vec4 Global_ambient;
+// ambient light color:
+//uniform vec4 global_ambient;
+
+// light source direction
+//uniform vec3 Light_direction;
+
+// light's color:
+//uniform vec4 light_color;
+
+// light_ambient is a bit pointless. I'm content to assume a lightsource
+// doesn't contribute to the ambient light level
 //uniform vec4 Light_ambient;
-//uniform vec4 Light_diffuse;
-//uniform vec3 Light_location;
+
+// presumably it usually makes perfect sense to use the same value - namely
+// color - for both of these, since a material's scattering of incoming light
+// is identical regardless of whether that light is from a directional source,
+// or ambient
 //uniform vec4 Material_ambient;
-//uniform vec4 Material_diffuse;
+//uniform vec4 material_diffuse;
 
 void main()
 {
-    vec3 light_pos = vec3(0.2670, 0.267 * 3.0, 0.2673 * -2.0);
-    vec4 Global_ambient= vec4(0.1, 0.1, 0.1, 1.0);
-    vec4 Light_diffuse = vec4(1.0, 1.0, 1.0, 1.0);
-    vec4 Material_diffuse = vec4(1.0, 1.0, 1.0, 1.0);
+    vec3 light_dir = vec3(0.2670, 0.267 * 3.0, 0.2673 * -2.0);
+    vec4 global_ambient= vec4(0.1, 0.1, 0.1, 1.0);
+    vec4 light_color = vec4(1.0, 1.0, 1.0, 1.0);
+    vec4 material_diffuse = vec4(1.0, 1.0, 1.0, 1.0);
 
     gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0);
     float diffuse_weight = dLight(
-        normalize(gl_NormalMatrix * light_pos),
+        normalize(gl_NormalMatrix * light_dir),
         normalize(gl_NormalMatrix * normal)
     );
     
-    // Light_ambient * Material_ambient +
     baseColor = (
-        Global_ambient * color
-        + color * Light_diffuse * diffuse_weight
+        global_ambient * color
+        + color * light_color * diffuse_weight
+        // + color * Light_ambient
     );
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.