Why does reversing an axis direction change shading properties?

I am working on an interactive GUI. Part of the GUI contains an axis which is used render 3D objects. I need to use a left-handed coordinate system in this axis. Thus I run the line below to flip the z-axis
set(gca,'ZDir','reverse')
When I do this, the lighting of the object becomes very flat:
Compare this with the rendering before flipping the z-axis:
Anyone know why this would be? I much prefer the way the second (non-flipped) rendering looks. Any way to reproduce this 'shiny' look and still have a flipped z-axis?
Thanks, Justin

 Réponse acceptée

Star Strider
Star Strider le 10 Oct 2012
Modifié(e) : Star Strider le 10 Oct 2012
The position of the light changed with respect to its original z-axis position when you reversed the direction of the z axis. You will probably have to reposition it with respect to the reversed z axis to put it back where it was originally with respect to your viewing angle.

4 commentaires

Thanks for the tip. I explored changing the light position but it hasn't solved my problem. I found out that the problem is related to the transparency (alpha) of the object.
In this linked image, I show four cases, w/ and w/o z-axis flipping and w/ and w/o transparency. The only case that gives me problems (and the case that I actually want to use) is w/ z-axis flipping and w/ transparency. In other words, I want the bottom right image to look like the bottom left image. Any ideas? I don't think its a light position problem because flipping the z-axis doesn't have an impact for the opaque object.
Thanks, Justin
Star Strider
Star Strider le 11 Oct 2012
Modifié(e) : Star Strider le 11 Oct 2012
I agree, the problem is alpha and not the axis reversal. (I have a patch isosurface script that I like that I experimented with.) An alpha value of <1 (even 0.99) prevents reflection. I even experimented with material properties ( 'shiny' and 'metal' ) and lighting and couldn't get it to be in any way reflective.
It seems counterintuitive that anything less than a perfectly-opaque surface would have no reflectivity at all. (In the real world, even ‘perfect’ glass is reflective if it has a smooth surface!)
I suggest that you bring this up with TMW Tech Support. It may be a bug, or it may be that we're both missing something in the documentation, or there could be a work-around for it that’s hidden somewhere in the documentation and we simply haven’t found it.
Please post TMW’s fix for it if they have one. Otherwise, I'll wait for the bug fix to be published.
I'll look into this more. I'll let you know if I find something. Thanks for your help!
Thank you!
It is my pleasure to help — I wish I actually could have found the answer. The only success I can claim is that I read everything I could find in the documentation and tried every fix that occurred to me.

Connectez-vous pour commenter.

Plus de réponses (1)

Matt Fig
Matt Fig le 11 Oct 2012
Modifié(e) : Matt Fig le 11 Oct 2012
I am not sure if this will help at all. It might help if you provide some code. Here is what I did to simulate what I see in your images:
figure
ax(1) = subplot(1,2,1);
sphere(300);
L = light;
box
ax(2) = subplot(1,2,2);
sphere(300);
L(2) = light;
box
axis(ax,'equal')
H = findobj('type','surf');
set(H,'edgecolor','none')
set(H,'facecolor',[.5 .5 .5])
set(ax(2),'zdir','reverse');
Now if this looks like what you see, and is similar to what you did, then have a look at what this command does:
set(gcf,'render','z')
Now we can move the light to make things the same:
set(L(2),'pos',[1 0 -1])

6 commentaires

Thanks for the idea. This works but for some reason it prevents me from changing the transparency of the object. i.e., changing the 'FaceAlpha' property has no effect after running set(gcf,'render','z'). Run this code to see what I mean:
figure
ax(1) = subplot(1,2,1);
sphere(300);
L = light;
box
ax(2) = subplot(1,2,2);
sphere(300);
L(2) = light;
box
axis(ax,'equal')
H = findobj('type','surf');
set(H,'edgecolor','none')
set(H,'facecolor',[.5 .5 .5])
set(H,'FaceAlpha',.8)
set(ax(2),'zdir','reverse');
set(gcf,'render','z')
set(L(2),'pos',[1 0 -1])
Any ideas?
Star Strider
Star Strider le 12 Oct 2012
Modifié(e) : Star Strider le 12 Oct 2012
The best I can come up with for documentation on that is Figure Properties — Renderer. I didn't even know it existed until now, much less its import to correct figure appearance.
Matt — If this isn't correct, please provide the correct link.
Justin — Thank you for raising this problem. I learned something.
EDIT — It may be time to contact TMW with a bug report on this problem if Matt's 'Renderer' fix didn't solve your problem.
Yes, it is the renderer. Sorry, I am used to using partial property names in MATLAB (because I can, as long as no ambiguity between properties arises). Since there is only one figure property that begins with an 'R' (Renderer), and this property has only one option that begins with a 'Z' (Zbuffer), this actually will set it:
set(gcf,'r','z');
But of course it can be confusing to people who don't know this!
Anyway, glad your issue is fixed!
Justin Solomon
Justin Solomon le 12 Oct 2012
Modifié(e) : Justin Solomon le 12 Oct 2012
Sorry, I spoke too soon about this being a perfect solution. See my edited comment above. Does 'Zbuffer' not support transparency?
Matt Fig
Matt Fig le 12 Oct 2012
Modifié(e) : Matt Fig le 12 Oct 2012
That's the catch. And this is a well known issue that MATLAB has had forever. Only opengl supports both lighting and transparency... If you open up the doc and search for:
renderer transparency
you will find these things discussed. Opengl is often buggy, and system dependent. It looks like you have stumbled upon yet another opengl issue. If you read the doc for opengl, you may find one of the settings works for you, but I doubt it.....
Ok. That makes sense. I can't have my cake and eat it too it seems. Anyways, thanks a lot for your help. I learned a lot. I may search around the Opengl documentation for a solution. I'll post if I find anything.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by