Difference between revisions of "Sculpted Prims: Technical Explanation"

From Second Life Wiki
Jump to navigation Jump to search
m (Sculpted Prim Explanation moved to Sculpted Prims Explained: A slight change to bring it in line with the de facto naming convention.. I feel this title reflects the purpose of the page in relation to the portal and faq pages most accurately.)
Line 17: Line 17:
==Sampling==
==Sampling==


64x64 textures are common for position maps, but in practice the highest level of detail for sculpted prims in Second Life is a grid of 32x32 vertices, and the lower level of detail uses 16x16 vertices. It is unclear at this point whether Second Life is sampling individual pixels but fewer of them total, or averaging blocks of pixels together (for example, a bicubic resizing of the image to a lower resolution first). Either way it is recommended to use 64x64 images (twice the maximum level of detail) to make sure lower resolutions don't result in unexpected sampling problems.
64x64 textures are common for position maps, but in practice the highest level of detail for sculpted prims in Second Life is a grid of 32x32 vertices, and the lower level of detail uses 16x16 vertices. Second Life samples individual pixels but fewer of them total.  


For example, a sphere at the highest level of detail requires a mesh of 32 x 33 vertices, the top row of which is then averaged together to glom all of those vertices into a single one to form the North pole. The same thing happens to the bottom row. If we have a 64x64 texture, this grid of vertices is sampled from the texture at the points:
(0,0)  (2,0)  (4,0)  ...  (60,0) (62,0)
(0,2)  (2,2)  (4,2)  ...  (60,2) (62,2)
  .                                .
  .                                .
  .                                .
(0,60) (2,60) (4,60) ... (60,60) (62,60)
(0,62) (2,62) (4,62) ... (60,62) (62,62)
(0,63) (2,63) (4,63) ... (60,63) (62,63)
Notice the last row, needed to get the 33rd row of vertices.
In general, if we have a 2^n by 2^n texture, and we are making a grid of 2^m by (2^m)+1 vertices, then the (i,j)th vertex position (0 <= i < 2^m, 0 <= j <= 2^m) is determined by the pixel at:
(2^(n-m)*i, 2^(n-m)*j) if j != 2^m
(2^(n-m)*i, (2^n) - 1) if j == 2^m
It is recommended to use 64x64 images.


==Examples==
==Examples==

Revision as of 10:58, 22 May 2007

Introduction

Sculpted prims are three dimensional meshes created from textures. Each texture is a spherical mapping of vertex positions, where at full resolution each pixel would be one vertex (this is almost never the case, see Sampling). Each row of pixels (vertices) links back to itself, and for every block of four pixels two triangles are formed (total number of triangles is more because of the wrapped edges and the poles).

Sculpted-prim-explanation.png

Pixel Format

The alpha channel (if any) in position maps is currently unused, so we have 24 bits per pixel giving us 8 bits per color channel, or values from 0-255. Each color channel represents an axis in 3D space, where red green and blue map to X, Y, and Z respectively. The color values map to an offset from the origin of the object <0,0,0>, with values less than 127 being negative offsets and values greater than 127 being positive offsets. An image that was entirely <127,127,127> pixels (flat gray) would represent a single dot in space at the origin, although it's unclear how Second Life will handle zero-volume sculpted prims like this. A sculpted prim intrinsically has a size of one meter, so the color values from 0-255 map to offsets from -0.5 to 0.5 meters. Combined with the scale vector that all prims in Second Life possess, sculpted prims have the same maximum dimensions as regular procedural prims (10 meter diameter).


Texture Mapping

The position map of a sculpted prim also doubles as the UV map, describing how a texture will wrap around the mesh. The image is already an explanation of what vertices correlate to what pixel, which is used to generate UV coordinates for vertices as they are created. This presents a big advantage for texture mapping over procedural prims created in Second Life because you can do all of your texturing in a 3D modeling program such as Maya, and when you export the position map you know the UV coordinates will be exactly preserved in Second Life.


Sampling

64x64 textures are common for position maps, but in practice the highest level of detail for sculpted prims in Second Life is a grid of 32x32 vertices, and the lower level of detail uses 16x16 vertices. Second Life samples individual pixels but fewer of them total.

For example, a sphere at the highest level of detail requires a mesh of 32 x 33 vertices, the top row of which is then averaged together to glom all of those vertices into a single one to form the North pole. The same thing happens to the bottom row. If we have a 64x64 texture, this grid of vertices is sampled from the texture at the points:

(0,0)  (2,0)  (4,0)  ...  (60,0) (62,0)
(0,2)  (2,2)  (4,2)  ...  (60,2) (62,2)
  .                                 . 
  .                                 .
  .                                 .
(0,60) (2,60) (4,60) ... (60,60) (62,60)
(0,62) (2,62) (4,62) ... (60,62) (62,62)
(0,63) (2,63) (4,63) ... (60,63) (62,63)

Notice the last row, needed to get the 33rd row of vertices.

In general, if we have a 2^n by 2^n texture, and we are making a grid of 2^m by (2^m)+1 vertices, then the (i,j)th vertex position (0 <= i < 2^m, 0 <= j <= 2^m) is determined by the pixel at:

(2^(n-m)*i, 2^(n-m)*j) if j != 2^m (2^(n-m)*i, (2^n) - 1) if j == 2^m

It is recommended to use 64x64 images.

Examples

A pack of sculpture maps available for download: sculpt-tests.zip


An apple sculpt shown in the sculptedpreview program Sculpted-preview-03.png


An S-shaped sculpture shown in the latest version of sculptedpreview, with the sculpture map also applied as the texture map Sculpted-preview-04.png