Degradation of image when used as texture in 3D graphics
Don't rasterize. I think Texture
is doing its own rasterization, so you are seeing the results of a double rasterization.
img =
Texture[
Graphics[
Table[Disk[{j, i}, Sqrt[i]/6], {i, 25}, {j, 50}],
PlotRange -> {{1, 50}, {-5, 25}}, ImageSize -> 600]];
SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi},
Mesh -> None,
TextureCoordinateFunction -> ({#5, #4} &),
PlotStyle -> img,
Lighting -> {{"Ambient", White}}]
m_goldberg's solution jogged my memory and the problem is even a pitfall:
- Use
Rasterize[..., "Image"]
to avoid double rasterization
Note that Rasterize[Grapphics[. . .]]
is not an Image
:
gr2d = Graphics[Table[Disk[{j, i}, Sqrt[i]/6], {i, 25}, {j, 50}],
PlotRange -> {{1, 50}, {-5, 25}}, ImageSize -> 1000];
Rasterize[gr2d] // Head
Graphics
Alexey's solution applied:
tex1 = Rasterize[gr2d, "Image"] // Texture;
SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None,
TextureCoordinateFunction -> ({#5, #4} &), PlotStyle -> tex1,
Lighting -> {{"Ambient", White}}]
But I would like to ask in advance, What if I only have the high quality rasterized image but not its original form? That rasterized image surely is clear enough for a very high quality texture but Mathematica returns a poor quality result.
This is not a problem, in fact it is the solution, if you have an actual Image
rather than a Raster
.
img = gr2d // Image;
tex2 = Texture[img];
SphericalPlot3D[1, {u, 0, Pi}, {v, 0, 2 Pi}, Mesh -> None,
TextureCoordinateFunction -> ({#5, #4} &), PlotStyle -> tex2,
Lighting -> {{"Ambient", White}}]