简体   繁体   中英

Shadows in mathematica Graphics3D

If I understood the Mathematica documentation correct ( haven't found examples either ) Graphics3D does not produce shadows of 3D objects, although Graphics3D has a Lighting-> option.

Question: Have you ever tried to produce Mathematica 3D objects with shadows ? If so have you solved this in Mathematica? Or have you exported the graphics to other 3D ( scene-graph ) viewers like for example J-Reality?

The shading model used by MMA , the so-called Phong shading , determines the pixel intensities based on a simple relationship between local surface orientation, light source direction(s), camera direction and diffuse and specular properties of the surface. No other aspect of the geometry is taken into account, which means that objects do not influence the pixel values of other objects even if they are between the object and the light source.

This means that the model doesn't generates shadows. It is not able to.

You could simulate shadows yourself by projecting your object's polygons on the ground plane or wall planes as applicable. That shouldn't be too difficult, but shadows on non-planar surfaces will be pretty hard.

Example:

polys = (PolyhedronData["GreatRhombicTriacontahedron", "Faces"] // 
      Normal // N) /. {x_, y_, z_}?VectorQ -> {x, y, z + 6}; 
     (* raise it slightly above ground plane*)

shadow = polys /. {x_, y_, z_}?VectorQ -> {x - z, y, 0};
         (* projection from a directional light source at 45 deg elevation *)

Graphics3D[{polys, EdgeForm[], FaceForm[Darker@Gray], shadow}, 
 Lighting -> {{"Directional", White, {{1, 0, 1}, {0, 0, 0}}}}, 
 Boxed -> False]

在此输入图像描述

Of course, you need to make sure that the lighting sources (point, spot, directional...) and your shadow projection are consistent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM