Colouring a unit cube red=x, green=y, blue=z

I’m experimenting with the shader editor to extend how Grant colours the dinosaur scene mountains.

Here are 3 unit squares, each with a vertex at the origin. One in the xy plane, one in yz and one in xz.

cube-in-viewport2

The shader should generate a colour where the amount of red equals the value of the x coordinate, green the y and blue the z.

Although the resulting colours look similar to what I’d expect, the colour at the origin seems wrong. At (0,0,0) I’d expect the colour to be black. If check that by changing the Combine Color node to receive (0,0,0)

the cube does indeed go black.

rgb-zero

Anyone know why my material doesn’t work as expected?

1 Like

Im quite sure the Vertex on (0,0,0) is indeed black. Its hard to spot, as it turns to color very fast.
You can try to insert Float Curve node between separator and combine nodes and adjust the Curve, so it will change how the numbers are mapped.
For what you expect, youd probably need to use math node with log 2, but Id have to check it and Im on my phone rn. But the curve node should work for this, so you can adjust the ramp to your liking

3 Likes

Thanks Medial, I was unaware that those Float Curve nodes were available to be played with.

Making the curves non linear, I can at least get an object that looks darker near the origin.

cube-float-curve-in-viewport

Now however, the transition in for example the x=0 plane between green and blue seems to be along a ‘horizontal’ line rather than along a ‘diagonal’. Similarly red & blue.

1 Like

Oh yes, I got the issue aswell. It comes (partially) from the fact, that your cube is 2x2x2, so it gives values from 0 to 2 on each dimension, while color node expects values from 0 to 1. Everything over 1 gives full saturation. If you reduce the size to 1x1x1 it looks like this:

with such curves

Alternatively you can use map range node:
obraz

To get the same results with default cube

2 Likes

Bending the shape of the float curve around, to look more like yours, does give me something more like a diagonal boundary between one colour and another.

cube-in-viewport3

Using red = x^2, green = y^2, blue = z^2 also looks better.

cube-in-viewport4

Thanks.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms