0 votes

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?

related to an answer for: Fade in animation of 3D object
asked Oct 31, 2018 in Engine by TobiLa (163 points)

1 Answer

0 votes

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.

answered Nov 1, 2018 by MysteryGM (1,424 points)

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.