shading in meta[post/play] & PDF
There's a wonderful tutorial on drawing 3D graphics in PostScript on http://www.math.ubc.ca/~cass/graphics/manual/, specifically http://www.math.ubc.ca/~cass/graphics/manual/code/doughnut.eps as an example. And there's a detailed description on shading in PostScript in http://partners.adobe.com/public/developer/en/ps/PLRM.pdf, page 259 (I attached an example and have some more on computer if anyone is interested; I downloaded them from Adobe, but don't know the URL any more) or on shading in PDF in http://partners.adobe.com/public/developer/en/pdf/PDFReference16.pdf, page 272. (They're basically the same.) In metapost, "perfect" spheres can be drawn, like on http://www.gnu.org/software/3dldf/cdsmpls.html. But how can I add colour? Even if it would be too tricky to add colour and proper shading on the sphere - Is there any possibility to use advanced shading techiques described in PLRM inside metapost/metaplay for the most simple cases, say, like in the attached example? Metaplay allows circular and gradient shading and no others. I don't mind if I had to hard-code the shading. PSTricks allows some more advanced shading techniques and even direct PostScript code integration (with \special I think). Is anything similar possible in metapost/play? The spheres drawn directly in PostScript as in the examples above still have straight lines (well, I agree that with some mathematics it would be possible to draw them with proper splines as well). Thanks for all the suggestions, Mojca
Mojca Miklavec wrote:
There's a wonderful tutorial on drawing 3D graphics in PostScript on http://www.math.ubc.ca/~cass/graphics/manual/, specifically http://www.math.ubc.ca/~cass/graphics/manual/code/doughnut.eps as an example.
Thanks for the reference, it looks very interesting.
In metapost, "perfect" spheres can be drawn, like on http://www.gnu.org/software/3dldf/cdsmpls.html. But how can I add > colour?
The spheres in that example are really just circles. The "globe font" was done using Metafont, which doesn't support color at all. The sphere graphic at the beginning of that file was done using MetaPost, so the circles could be drawn in color, but I know this isn't what you mean. The glyphs from the globe font (which I plan to improve) could be colored, e.g., by using the macros defined in the `colordvi.tex' file supplied with `dvips'. Of course, a given glyph could only be printed or displayed in a single color. GNU 3DLDF does not yet possess a `sphere' type, but I plan to add one in the not-too-distant future. I also plan to add shading, but that is in the more distant future. The shading methods I'm (vaguely) familiar with operate on raster data and I haven't quite decided how to handle rasterization. I'm leaning toward using the PNG format rather than PostScript for this. I believe PostScript can be used for both vector and raster data, but my memory of the details is hazy.
The spheres drawn directly in PostScript as in the examples above still have straight lines (well, I agree that with some mathematics it would be possible to draw them with proper splines as well).
If you mean my spheres, that's an artefact of the PNG graphics. The PostScript versions look nicer. I believe that on commonly available devices, curves are ultimately drawn as short straight-line segments, though. In the code in that file, the circles have 64 points, and I thought the results were good enough. Raising it to some value x such that x % 4 == 0 and x > 64 might improve them, I haven't tried it. 32 wasn't enough. Laurence Finston http://www.gnu.org/software/3dldf/LDF.html
The answer to the mail follows, but to reformulate my question slightly: How can I make shading inside metapost(play) to produce exactly what's in the attached picture (smooth shades). Or more generally: how can I "hardcode" some PS/PDF code in .mp, not (yet) supported by metapost(play)? (PDF supports even 3D shapes (already shaded properly) since version 1.5 or 1.6, but I suppose that's another story anyway.) Here's the corresponding PostScript code: %!PS-Adobe-3.0 Resource-ProcSet %%Title: Hsbwheel.ps %%Creator: Henry McGilton, Adobe Systems Incorporated (modified!) %%EndComments 200 dup scale /X3 1.0 3 div def /X6 2.0 3 div def /Y3 1.0 3 div def /Y6 2.0 3 div def /middlecolor [ 1 1 1 ] def /topcolor [ 1 0 0 ] def /rightcolor [ 0.5 0 1 ] def newpath << /ShadingType 6 /ColorSpace /DeviceRGB /DataSource [ 0 0.0 0.0 X3 0.0 X6 0.0 1.0 0.0 1.0 .552 .552 1.0 0.0 1.0 0.0 Y6 0.0 Y3 0.0 0.0 0.0 0.0 0.0 0.0 middlecolor aload pop rightcolor aload pop topcolor aload pop middlecolor aload pop ]
shfill
showpage ************************************************************************ Laurence Finston wrote:
Mojca Miklavec wrote:
There's a wonderful tutorial on drawing 3D graphics in PostScript on http://www.math.ubc.ca/~cass/graphics/manual/, specifically http://www.math.ubc.ca/~cass/graphics/manual/code/doughnut.eps as an example.
Thanks for the reference, it looks very interesting.
In metapost, "perfect" spheres can be drawn, like on http://www.gnu.org/software/3dldf/cdsmpls.html. But how can I add > colour?
The spheres in that example are really just circles. The "globe font" was done using Metafont, which doesn't support color at all. The sphere graphic at the beginning of that file was done using MetaPost, so the circles could be drawn in color, but I know this isn't what you mean.
Well - the main question is how to add the proper (smooth shading) color once I calculate the grid points in one way or another.
The glyphs from the globe font (which I plan to improve) could be colored, e.g., by using the macros defined in the `colordvi.tex' file supplied with `dvips'. Of course, a given glyph could only be printed or displayed in a single color.
GNU 3DLDF does not yet possess a `sphere' type, but I plan to add one in the not-too-distant future. I also plan to add shading, but that is in the more distant future. The shading methods I'm (vaguely) familiar with operate on raster data and I haven't quite decided how to handle rasterization. I'm leaning toward using the PNG format rather than PostScript for this. I believe PostScript can be used for both vector and raster data, but my memory of the details is hazy.
Well, PostScript can be used for raster images, but that doesn't bring anything. The examples on Cass' page are actually done using *vector* graphics (colors are really calculated only in grid points, but then the color is interpolated by postscript interpreter): the perfect sphere coloring is thus really limited to "floating point accuracy" and printer capabilities.
The spheres drawn directly in PostScript as in the examples above still have straight lines (well, I agree that with some mathematics it would be possible to draw them with proper splines as well).
If you mean my spheres, that's an artefact of the PNG graphics. The PostScript versions look nicer. I believe that on commonly available devices, curves are ultimately drawn as short straight-line segments, though. In the code in that file, the circles have 64 points, and I thought the results were good enough. Raising it to some value x such that x % 4 == 0 and x > 64 might improve them, I haven't tried it. 32 wasn't enough.
No, I wasn't talking about the PNGs. I was talking about the PostScript pictures. http://www.math.ubc.ca/~cass/graphics/manual/code/doughnut.eps has a really *perfect* shading, but its edges are drawn using straight segments instead of drawing them with splines which damages slightly the whole impression of its perfectness. Some additional calculation for spline drawing would help, but I still find it easier to calculate the curves in metapost than in PostScript. Those "straight-line segments" on printers are just as straight as they are on any laser print-out of texts if I'm not wrong - i.e. not worth considering. Thank you, Mojca
On Wed, 19 Jan 2005, Mojca Miklavec wrote:
How can I make shading inside metapost(play) to produce exactly what's in the attached picture (smooth shades). Or more generally: how can I "hardcode" some PS/PDF code in .mp, not (yet) supported by metapost(play)?
This is a very difficult question. For an excellent introduction to shading and other subjects I recommend: Jones, Huw. _Computer Graphics through Key Mathematics_. Springer-Verlag London Limited 2001. ISBN 1-85233-422-3.
Here's the corresponding PostScript code:
Sorry, I don't know PostScript.
The spheres drawn directly in PostScript as in the examples above still have straight lines (well, I agree that with some mathematics it would be possible to draw them with proper splines as well).
To the best of my knowledge, spline curves are drawn by means of calculating short line segments. You can make the "time" parameter as small as you like, but you can't make it 0. I believe plotters can draw genuine curves---and it's a lot more fun to watch them work (it's like magic). They're not so great at filling in regions, though. Much to my regret, the computer center here got rid of the plotter. They're probably as obsolete as the ENIAC now, except perhaps for very high-quality work.
Thank you,
My pleasure. Laurence
Mojca Miklavec wrote:
How can I make shading inside metapost(play) to produce exactly what's in the attached picture (smooth shades). Or more generally: how can I "hardcode" some PS/PDF code in .mp, not (yet) supported by metapost(play)?
certain kind of native level 2 shaded can be done with the metafun macros (circular and linear vector based) a couple of years ago mathew baker and i played with more advanced features using functions and such but i need to locate that code; if you're willing to figure out what (in pdf) functionality is needed i can extend the current metapost shading handler with a few more alternatives [the function based ones, since that's what you're looking for]) [more a context mailing list issue than a metapost list issue] Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen wrote:
Mojca Miklavec wrote:
How can I make shading inside metapost(play) to produce exactly what's in the attached picture (smooth shades). Or more generally: how can I "hardcode" some PS/PDF code in .mp, not (yet) supported by metapost(play)?
certain kind of native level 2 shaded can be done with the metafun macros (circular and linear vector based)
a couple of years ago mathew baker and i played with more advanced features using functions and such but i need to locate that code;
if you're willing to figure out what (in pdf) functionality is needed i can extend the current metapost shading handler with a few more alternatives [the function based ones, since that's what you're looking for])
I'm not sure if I understood the question correctly (about what should I figure out). I would like to draw a sphere (possibly with different colors on different points of the sphere; which would then be interpolated across the whole surface). Problem description: I have a computer program, which carries the data about the grid points on a sphere (possibly with different colors defined in these points) and how the points are connected with each other to form a grid. I would take these triangles (or quadrilaterals), draw them transformed on the plane (with curves, not with straight lines) and fill them with the appropriate shading pattern (colors defined in corners of the triangles (darker according to normal vector) simply interpolated between the three points). Yet another possibility would probably be to use function-based shading and define a function which knows how the points have to be shaded on the sphere, but the latter seems more complicated and less universal. Problem reduction: Fill a mp closed path with any more complex shading. So I would probably need Type 6 or 7 shading (Type 4 would be OK as the picture can be clipped within metapost, so that the resulting sphere borders are not composed of straight lines; the articles on http://www.math.ubc.ca/people/faculty/cass/graphics/text/www/ which inspired me to do something so crazy actually use Type 4 shading). Type one is probably the most general one, so it should be OK too, just complicated to do. However: I'm not sure if, say, a (sampled) function to be passed to PDF can be specified in metapost elegantly. Page 746 of PDF Reference, version 1.6 also defines an interesting new feature: 3D objects (3D Artwork as they call it), but I haven't found anything else about that. In dvipdfm there's an example of using: \special{pdf: bt rotate 90 xscale 2.0 } These lines are to be used in TeX. MetaPost also knows a "special" command, I just don't know how to use it. (This is probably the "communication channel" to PDF when trying to implement some more exotic shadings.) I glimpsed the mp-spec.mp file, but I didn't yet understand how the parameters are passed to PDF.
[more a context mailing list issue than a metapost list issue]
So I left the metapost group out. Actually, 90% on the people here probably think I posted that to the wrong group anyway (in the sense of "Are you sure you didn't want to post that question to the 3D studio max mailing list?" :) The example above is probably not the most descriptive one, but having the possibility to add some more advanced shading patterns would be great. Thank you, Mojca
Mojca Miklavec wrote:
Problem description: I have a computer program, which carries the data about the grid points on a sphere (possibly with different colors defined in these points) and how the points are connected with each other to form a grid. I would take these triangles (or quadrilaterals), draw them transformed on the plane (with curves, not with straight lines) and fill them with the appropriate shading pattern (colors defined in corners of the triangles (darker according to normal vector) simply interpolated between the three points). Yet another possibility would probably be to use function-based shading and define a function which knows how the points have to be shaded on the sphere, but the latter seems more complicated and less universal.
Problem reduction: Fill a mp closed path with any more complex shading.
So I would probably need Type 6 or 7 shading (Type 4 would be OK as the picture can be clipped within metapost, so that the resulting sphere borders are not composed of straight lines; the articles on http://www.math.ubc.ca/people/faculty/cass/graphics/text/www/ which inspired me to do something so crazy actually use Type 4 shading). Type one is probably the most general one, so it should be OK too, just complicated to do.
However: I'm not sure if, say, a (sampled) function to be passed to PDF can be specified in metapost elegantly.
i searched my machine extensively but it seems that i lost some code that could be used as starting point for that;
Page 746 of PDF Reference, version 1.6 also defines an interesting new feature: 3D objects (3D Artwork as they call it), but I haven't found anything else about that.
there is a section about shading, the function numbers differ;
In dvipdfm there's an example of using: \special{pdf: bt rotate 90 xscale 2.0 }
These lines are to be used in TeX. MetaPost also knows a "special" command, I just don't know how to use it. (This is probably the "communication channel" to PDF when trying to implement some more exotic shadings.)
take a look at supp-mpe.tex, all we need is some variant on \defineMPspecial{31} {\startMPshading{16}% type 3 \setMPshadingcolors{4}{5}{6}{10}{11}{12}% \immediate\pdfobj {<>}% \immediate\pdfobj {<>}% \stopMPshading} (plus some more depending on what parameters need to be passed)
I glimpsed the mp-spec.mp file, but I didn't yet understand how the parameters are passed to PDF.
[more a context mailing list issue than a metapost list issue]
So I left the metapost group out. Actually, 90% on the people here probably think I posted that to the wrong group anyway (in the sense of "Are you sure you didn't want to post that question to the 3D studio max mailing list?" :) The example above is probably not the most descriptive one, but having the possibility to add some more advanced shading patterns would be great.
if you can locate the right stuff in the pdf ref manual we can see what can be done (off list); i can add more 'special' handlers to the mp to pdf converted Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Page 746 of PDF Reference, version 1.6 also defines an interesting new feature: 3D objects (3D Artwork as they call it), but I haven't found anything else about that.
there is a section about shading, the function numbers differ;
? How? (I was talking only about shading types, not about function types at all anyway, but the number *should* be the same.)
take a look at supp-mpe.tex, all we need is some variant on
\defineMPspecial{31} {\startMPshading{16}% type 3 \setMPshadingcolors{4}{5}{6}{10}{11}{12}% \immediate\pdfobj {<>}% \immediate\pdfobj {<>}% \stopMPshading}
(plus some more depending on what parameters need to be passed)
Thanks for pointing it out. This piece of code is very nice (however the whole bunch of code that resides in the file ... I wonder how you managed to put all that stuff together :)
if you can locate the right stuff in the pdf ref manual we can see what can be done (off list); i can add more 'special' handlers to the mp to pdf converted
Here are some more examples: http://partners.adobe.com/public/developer/ps/sdk/index_archive.html http://partners.adobe.com/public/developer/en/ps/sdk/TN5600.SmoothShading.pd... http://partners.adobe.com/public/developer/en/ps/sdk/sample/smooth.zip (I didn't want to send the material to the list and I didn't find the links until now.) I'll try to make the drawings I need (in PostScript for the beginning) and collect the ideas of how the things have to be implemented (which features supported and how). I'm in no way such a 'superwoman' to be able to do dozens of things efficiently in one day as you do, but I'll do my best; exams are approaching, so it may take me slightly longer - please apologize me. Thanks again for being prepared to help. I'll write back as soon as I have something to report. Mojca
In metapost, "perfect" spheres can be drawn, like on http://www.gnu.org/software/3dldf/cdsmpls.html. But how can I add colour?
You could use the intersection points of the circles as the corners of rectangles and fill the latter. The more circles you use, the better the results will be. The very primitive surface hiding I've implemented will almost certainly fail, so you'll have to do this by hand or implement it yourself. You may be able to implement surface hiding and/or shading by operating on the MetaPost file generated by GNU 3DLDF, or by the PostScript file generated by MetaPost. Laurence
participants (5)
-
h h extern
-
Hans Hagen
-
Laurence Finston
-
Mojca Miklavec
-
Mojca Miklavec