4
$\begingroup$

Suppose I have the given Mathematica code,

Graphics3D[{Texture[ExampleData[{"ColorTexture", "GloriesPattern"}]], Sphere[{0, 0, 0}]}, Boxed -> False]

which gives me a nice coloured texture around the unit sphere as below:

sphere-color-texture

But, when I try using this code:

Graphics3D[{Texture[ExampleData[{"Texture", "Grass"}]], Green, Sphere[{0, 0, 0}]}, Boxed -> False]

it gives me a black&white texture as below:

sphere-texture

Is there a way with which I can even provide specific colors to such kind of example texture data?

$\endgroup$

3 Answers 3

5
$\begingroup$

The image you get from ExampleData[{"Texture", "Grass"}] is a grayscale image. The colors you see are due to the default "5-point" lighting. If you set Lighting -> "Neutral", you get:

Graphics3D[{Texture[ExampleData[{"Texture", "Grass"}]], 
  Sphere[{0, 0, 0}]}, Boxed -> False, Lighting -> "Neutral"]

enter image description here

If you want to convert this grayscale image to a colored one, you can use Colorize with whatever ColorFunction you want:

Graphics3D[{Texture[Colorize[ExampleData[{"Texture", "Grass"}], 
 ColorFunction -> "AvocadoColors"]], 
  Sphere[{0, 0, 0}]}, Boxed -> False, Lighting-> "Neutral"]

enter image description here

$\endgroup$
3
$\begingroup$
img = ExampleData[{"Texture", "Grass"}];
colors = DominantColors[img]
img = ColorReplace[img, Thread[colors -> {Green, Pink}]];
Graphics3D[{Texture[img], Green, Sphere[{0, 0, 0}]}, Boxed -> False]

enter image description here

$\endgroup$
1
  • $\begingroup$ Why are there some small white or light greyish patches in the output texture? $\endgroup$
    – codebpr
    Feb 20 at 14:35
2
$\begingroup$

You could also use AmbientLight as well.

Graphics3D[{AmbientLight[Darker@Green], 
  Texture[ExampleData[{"Texture", "Grass"}]], Green, 
  Sphere[{0, 0, 0}]}, Boxed -> False]

And from there choose what Lighting you like.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.