How can I transfer the clip_height into a percent value instead of an acual value?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobiLa

Having to tweak the values for each mesh is a little unpractical and unclean.

Do you have any idea or hint on how to accomplish having a %- value as a shader value?

:bust_in_silhouette: Reply From: MysteryGM

How can I transfer the clip_height into a percent value instead of an acual value?

The formula for converting a value to a percentage is (value/maxValue) * 100 or just value/maxValue to get a float.
Example: (40/80) *100 = 50% or 40/80 = 0.5

Do you have any idea or hint on how to accomplish having a %- value as a shader value?

Do you mean range? Like a parameter that is locked between 0 and 100?

uniform float Percentage: hint_range(0.0, 100.0, 0.1) = 50.0;

Having to tweak the values for each mesh is a little unpractical and unclean.

If you want to edit a value only once, then you should share the material between objects, don’t make a new one for every object.

I see I should have asked more precisely.

Please have a look at the answer I have linked, my question is totally based on that.
The shader code in this answer can make an object fade in from the bottom to the top. My ‘problem’ with that is that this is defined done by setting a clip_height, which is an absolute value and is different for each mesh, depending on its height. I don’t want to figure out the exact values for each mesh manually, I want to automate this.

One way I could think of is somehow getting the total height of the mesh in shader code and calculating clip_height based on the percent value instead of having it given as a parameter from the outside.

But there may be other and better ways, that’s why I asked the question so open, I am a total noob in terms of shader code, this is the first thing I’m doing with it.

Thanks in advance,
Tobi

TobiLa | 2018-11-01 07:00