DPlot Forum Index DPlot
http://www.dplot.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Undocumented light source shading in version 2.0.1.4

 
Post new topic   Reply to topic    DPlot Forum Index -> General discussion
View previous topic :: View next topic  
Author Message
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Wed Oct 26, 2005 7:32 pm    Post subject: Undocumented light source shading in version 2.0.1.4 Reply with quote

If you work with 3D views of 3D surfaces you might be interested in this. New light source shading hasn't been tested thoroughly enough to make it "official", but you can still access these features with a macro command (or, for programmers, a call to DPlot_Command). The pertinent macro/DDE command is:

[ContourLighting(method,ambient)]

where
method = 0 for no lighting (the default)
=1 for Gouraud shading
=2 for Phong shading

(A description of these models is way beyond the scope of this topic. Google the names if you're interested.)

ambient = ambient light fraction, 0->1.
0 = no ambient light. Planes at steep angles to the view angle will be very dark.
1 = all ambient light. This is effectively the same as no lighting with the addition of needless calculations (don't use 1, in other words Smile).

Here's an example: The topo map of a mountain shown on the Features page with no lighting looks good with the border lines of the grid cells drawn. The border lines give depth perception; it is relatively plain to see which locations are at a given elevation. As with all thumbnail images below, click to see a larger view.



Without the border lines, though, the surface is basically a blob:



There's no depth perception and it's all but impossible to make out any features of the surface. Yes, the example is an extreme case as it only uses 2 colors, but additional colors only help somewhat.

With [ContourLighting(1,0.15)] we get this:



Much better. Want the surface to appear smoother? Here's Phong shading with [ContourLighting(2,0.15)]:



Lighting geek notes:
Both the Gouraud and Phong models used by DPlot are greatly simplified by an assumption: The only light source is in the direction of the view point, infinitely far away. This does 2 things to help speed calculations: 1) there is no variation in light intensity with distance from the source, 2) the vector to the light source is the same from all locations on the surface.

This "feature" is unlikely to change. There won't be any options to add additional light sources or to move the one light source. There won't be any options to add specular reflections and material properties. Shadows aren't calculated (actually there's no need with this setup, since the light source is in the same direction as your eyeballs and DPlot doesn't do perspective corrections). In other words the examples you see here are likely as good as it will ever be, other than fixing problems you find.

Memory requirements
What does this cost, in terms of processing speed? Surprisingly little for reasonable-sized plots. For example a 401x401 grid cell surface (160801 points) takes 3.4 seconds to draw unlit, 3.8 seconds with Gouraud shading, and 4.2 seconds with Phong shading on my system at 1280x1024 resolution. Your results will of course vary, but this should give you an idea of the relative costs for small and medium data sets. Where lighting will cause problems is with very large data sets. For points on a rectangular grid with NX x NY grid cells, Gouraud shading requires an additional 16*NX*NY bytes, and Phong shading requires an additional 80*NX*NY bytes. For randomly-spaced NN points generating NT triangles, Gouraud shading requires an additional 8*NT bytes, Phong shading requires 40*NT+12*NN bytes. For a million or more data points this can be the difference between disk thrashing and... well, not disk thrashing.

One fortunate effect of plotting very large data sets, though, is that Gouraud shading approaches the visual quality of Phong shading the smaller the triangles are. So for large data sets it is strongly suggested that you start with Gouraud shading. If that's good enough, good. If it isn't... prepare to wait a while. Of course if you want your surface to have a faceted appearance then Gouraud shading is the best solution in any case.

Try it out
If the word "macro" made you cringe, don't worry as there's really not much to it. Select File>Macro. Type a name that you'll remember, say "Light1" for Gouraud shading or "Light2" for Phong shading. Click Edit/Create. In the macro editor window type:

ContourLighting(1,0.15)

for Gouraud shading and 15% ambient light, or, for example,

ContourLighting(2,0)

for Phong shading and no ambient light.

Click the Save button, then close the editor. To run the macro, select File>Macro, select the name from the list of macros, then click 'Run'.

Bugs?
These new features have been tried on a wide variety of surfaces with good results, but of course you may find specific cases that give strange results. If that happens please let me know, either here in the forums or by private e-mail at support@dplot.com
_________________
Visualize Your Data
support@dplot.com


Last edited by DPlotAdmin on Fri Feb 24, 2006 6:31 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website
DPlotAdmin
Site Admin


Joined: 24 Jun 2003
Posts: 2310
Location: Vicksburg, Mississippi

PostPosted: Mon Oct 31, 2005 9:55 am    Post subject: Reply with quote

No longer "undocumented" in version 2.0.1.5. You can access lighting parameters using Options>Contour Options.
_________________
Visualize Your Data
support@dplot.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    DPlot Forum Index -> General discussion All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group