N = 30;    % Increase number of vertices in each direction
iso = .8;  % Change isovalue to .1 to display a sphere
lin = linspace (-1, 1, N);
[x, y, z] = meshgrid (1.2*lin, 1.2*lin, lin);
val = (x).^2 + (y).^2 - iso/2.7*cos (2*pi*z);
val(x>0 & (y-x)>0) = NaN;
fv = isosurface (x, y, z, val, iso);

clf;
subplot (2, 2, 1);
view (140, 20);
axis equal
hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none');
isonormals (x, y, z, val, hp, 'negate');
hl = light ('Position', [1 0 .5]);
lighting gouraud
title ({'BackFaceLighting', '''reverselit''', 'isonormals(...,''negate'')'});

subplot (2, 2, 2);
view (140, 20);
axis equal
hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', 'BackFaceLighting', 'unlit');
isonormals (x, y, z, val, hp, 'negate');
hl = light ('Position', [1 0 .5]);
lighting gouraud
title ({'BackFaceLighting', '''unlit''', 'isonormals(...,''negate'')'});

subplot (2, 2, 3);
view (140, 20);
axis equal
hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none');
isonormals (x, y, z, val, hp);
hl = light ('Position', [1 0 .5]);
lighting gouraud
title ({'BackFaceLighting', '''reverselit''', 'isonormals(...)'});

subplot (2, 2, 4);
view (140, 20);
axis equal
hp = patch (fv, 'FaceColor', 'r', 'EdgeColor', 'none', 'BackFaceLighting', 'unlit');
isonormals (x, y, z, val, hp);
hl = light ('Position', [1 0 .5]);
lighting gouraud
title ({'BackFaceLighting', '''unlit''', 'isonormals(...)'});

print -dpng light_reverselit.png

