% the code below illustrates phong/gouraud shading and mach banding clf; colormap('default') echo on [x,y,z] = sphere(8); h = surf(x,y,z); vn=x; vn(:,:,2)=y; vn(:,:,3)=z;set(h,'VertexNormals',vn) set(h,'EdgeColor','none','FaceColor',[1 0 0]); axis equal; light('Position',[1 -1 1]); lighting flat fprintf('here is the actual shape (polygon mesh)\n') pause(5) lighting phong fprintf('here is phong shading; observe:\n') fprintf('+ interior shading looks pretty convincing, \n') fprintf(' but outside shape not a smooth curve \n') fprintf('+ the highlight is perhaps a bit "washed out", \n') fprintf(' suggesting that matlab does color clipping by pinning\n') pause(5) lighting gouraud fprintf('here is gouraud shading; observe: \n') fprintf('+ the polygonal shape of the highlight \n') fprintf('+ mach banding, e.g. the "starry" aspect of the highlight\n') pause(5) clf; colormap('default') a = 30; x = [1:a a-1:-1:2]; x = [x x x]; x = x(ones(1,length(x)),:); y = x'; z = max(x,y); surf(z); axis equal; shading flat fprintf('consider this smooth shape of intensities\n') pause(5) imagesc(z); colormap(gray); fprintf('do not the "grid edges" look especially bright,\n') fprintf('although the intensity varies linearly?\n') fprintf('and what is with the "diagonal black grid"?\n') fprintf('all of this is (related to) mach banding')