Thread Subject: adding patch to a rendered surf causes changes

Subject: adding patch to a rendered surf causes changes

From: Ethan

Date: 21 May, 2008 18:39:01

Message: 1 of 7

I used surf to render a matrix using phong shading.

e.g.:
p1=surf(X,Y,Z,'EdgeColor','none','FaceColor','interp','FaceLighting','phong');

Then I add a patch to the figure, e.g.:
 p2=patch( X2,Y2,Z2,[1 1 1]);

But when I do this the rendering of the original surface changes. It's no longer
"phongy" . I want to keep the surface looking good.

Any ideas on why this is happening and how to prevent it.

I can't see any properties changing so maybe it has to do with the lighting but
I'm not sure...



Subject: adding patch to a rendered surf causes changes

From: Michael Garrity

Date: 21 May, 2008 19:42:45

Message: 2 of 7

"Ethan " <emontag.nospam@leuzeusa.com> wrote in message news:g11q85$eto$1@fred.mathworks.com...
>I used surf to render a matrix using phong shading.
>
> e.g.:
> p1=surf(X,Y,Z,'EdgeColor','none','FaceColor','interp','FaceLighting','phong');
>
> Then I add a patch to the figure, e.g.:
> p2=patch( X2,Y2,Z2,[1 1 1]);
>
> But when I do this the rendering of the original surface changes. It's no longer
> "phongy" . I want to keep the surface looking good.
>
> Any ideas on why this is happening and how to prevent it.
>
> I can't see any properties changing so maybe it has to do with the lighting but
> I'm not sure...
>

My guess would be that it is because you're allowing MATLAB to
choose the setting of your figure's renderer property for you. If it sees
a scene with an object that wants phong lighting, then it'll choose the
ZBuffer renderer because that's the only one that supports phong. But
when it sees a very complicated patch object (are X2, Y2, and Z2
large?), then it might choose a different renderer that is better at large
patch objects.

You can check whether this is happening by calling this:

    get(gcf,'renderer')

before and after adding the patch object.

You can tell it which renderer you want it to use by setting the renderer
property yourself. That'll keep MATLAB from guessing incorrectly.

    -Mike Garrity
    -The MathWorks, Inc.


Subject: adding patch to a rendered surf causes changes

From: Kenneth Eaton

Date: 21 May, 2008 19:54:02

Message: 3 of 7

As Mike suggested, the renderer for the figure is probably
being changed, and I would guess that it is being changed
to OpenGL since OpenGL rendering doesn't support phong
lighting (gouraud lighting is the best you could do). You
probably just have to do what Mike said and manually set
the renderer so MATLAB doesn't change it.

Ken

Subject: adding patch to a rendered surf causes changes

From: Ethan

Date: 21 May, 2008 20:53:01

Message: 4 of 7

You guys are correct!
The renderer did change. So if I make it zbuffer, the surface looks fine.

Thanks!!!

But now I am having trouble making the patch transparent.

if I add the patch to the figure like so:

patchhandle=patch( [-1 -1 1 1 ], [5 5 5 5 ],[ 0 1 1 0],[1 1 1]);

to draw a rectangular white patch, what is the easiest way to make it partially
transparent?



Subject: adding patch to a rendered surf causes changes

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 21 May, 2008 21:17:58

Message: 5 of 7

In article <g1223d$f6k$1@fred.mathworks.com>,
Ethan <emontag.nospam@leuzeusa.com> wrote:
>You guys are correct!
>The renderer did change. So if I make it zbuffer, the surface looks fine.

>But now I am having trouble making the patch transparent.

Opengl is the only renderer that supports transparency.

http://www.mathworks.com/access/helpdesk/help/techdoc/creating_plots/f3-84337.html
--
  "And believe me, I was very lousy yesterday.
   I had nothing to say, and, by God, I said it."
                                          -- Walter Wellesley Smith

Subject: adding patch to a rendered surf causes changes

From: Kenneth Eaton

Date: 21 May, 2008 21:34:02

Message: 6 of 7

"Ethan " <emontag.nospam@leuzeusa.com> wrote in message
<g1223d$f6k$1@fred.mathworks.com>...
> You guys are correct!
> The renderer did change. So if I make it zbuffer, the
surface looks fine.
>
> Thanks!!!
>
> But now I am having trouble making the patch transparent.
>
> if I add the patch to the figure like so:
>
> patchhandle=patch( [-1 -1 1 1 ], [5 5 5 5 ],[ 0 1 1 0],
[1 1 1]);
>
> to draw a rectangular white patch, what is the easiest
way to make it partially
> transparent?
>
>
>

Unfortunately, the only way to get transparency is with
OpenGL rendering, and the only way to get phong lighting is
with zbuffer rendering. If you want transparency anywhere
in your axes, you're stuck with gouraud lighting.

Ken

Subject: adding patch to a rendered surf causes changes

From: Ethan

Date: 22 May, 2008 12:33:03

Message: 7 of 7

> Unfortunately, the only way to get transparency is with
> OpenGL rendering, and the only way to get phong lighting is
> with zbuffer rendering. If you want transparency anywhere
> in your axes, you're stuck with gouraud lighting.

This probably explains why the rendering changed unintentionally when I tried
to get the patch to be transparent. Now that I know this, I'll try to tweak the
settings so I can get it pretty with gouraud and openGL. Maybe it won't look as
nice but it'll be faster!

Thanks for the responses. I could have wasted another day on this if you guys
didn't help out!

E

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
surf Ethan 21 May, 2008 14:40:26
phong Ethan 21 May, 2008 14:40:26
patch Ethan 21 May, 2008 14:40:26
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com