#simple gradient shader

1 messages · Page 1 of 1 (latest)

spring tide
#

thats how its visible in the shadergraph output

wicked ravine
#

here are the previews:

#

it seems even unity knows what's happening

#

object space must not really go from -1 to 1

spring tide
#

1 question, why are you adding 1 and multiplying by 0.5?

wicked ravine
#

if we imagined it did go from -1 to 1:
adding 1: now it's 0 to 2
dividing by 2: now its 0 to 1
perfect for lerp

spring tide
#

isnt object space by default 0-1 ?

wicked ravine
#

what is saturate doing?

spring tide
#

makes sure values dont go below 0 and beyond 1

wicked ravine
#

that definitely looks like 0-1

#

but the 0 starts at the center

#

making the overall shape -1 to 1

spring tide
#

it seems 0 is at centre but its at the bottom

#

maybe you can remove the saturate node and check?

wicked ravine
#

sure

#

saturate appears unnecessary likely because sample grad already clamps to 0-1

spring tide
#

yeah you're right

wicked ravine
#

I may have to continue ignoring this behavior

spring tide
#

you can add an offset to the shader by subtracting x value from the object space Y axis. put it right after the split

wicked ravine
#

but that offset would have to be different per object

#

the key may be relying on UVs instead of vertex position

#

but Im not good with UVs yet

spring tide
#

Oh you just have to swap out the object space node with the uv node

rancid nebula
#

If you have a 5x5x5 cube, the tallest point in object space is 2.5, lowest point -2.5

#

Sampling a gradient works in 0-1 range, but you can multiply or remap it to a different range

#

in: 0, 1 out: -2.5, 2.5 in case of a 5 unit cube

#

If you want the gradient to adapt to an object's dimensions, you need to get them from the bounds outside of the shader and pass them in as properties

#

This is what Blender does with its "generated" texture coordinates which you may be confusing object space with

spring tide