OK, the graph shader has something called CurveMap and it's useful because you can normalize the input so it's range is between 0 and 1. Any of you shader gurus know how you can achieve this CurveMap in text shaders? From what I understand (which is little...) it doesn't seem to be possible because you don't have access to the full range of the input, you only have access to the current pixel information. So I assume that CurveMap node is fed in some more information than it's accessible through the text shaders, unless... you send this information from GDScript I don't think it's possible? But in any case if it is let me know, I think it will be helpful in general :). Thanks!<br><br>edit:&nbsp;Actually, I don't think that everything interesting for CurveMapping can be sent from GDScript so... never mind the last...

I'm actually not entirely clear on what you want/have an issue with, mind you this is so mostly because I don't really deal with 2D/text/font shaders usually, but if you could assemble an example scene with the issue in it I'd be willing to try and take stab at solving it...<br><br>edit: wait with text shaders do you mean shader language? Wouldn't lerping work the same? Also you can normalize:<br><br>

vec_type mix ( vec_type a,vec_type b, float c ) Linear Interpolate<br>vec_type mix ( vec_type a,vec_type b, vec_type c ) Linear Interpolate (Vector Coef.)<br>vec_type normalize ( vec_type ) Normalize to unit length

<br>no?<br><br>edit2: Also why do you want to use shader language if you seem to be more familiar with the nodal/graphical shader interface(-es)? Just for learning or some specific reason?<br><br>also the source for the shadergraph editor is located at:<br>

https://github.com/godotengine/godot/blob/master/tools/editor/plugins/shader_graph_editor_plugin.cpp<br>(GraphCurveMapEdit starts at line 318)<br><br>and<br><br>https://github.com/godotengine/godot/blob/master/tools/editor/plugins/shader_graph_editor_plugin.h<br>(GraphCurveMapEdit starts at line 86)<br>

<br>

:)<br><br>@Megalomaniak, I'm not more familiar with the shader graph, I just looked at the docs, looked at some tutorials and wanted to recreate some stuff in godot. After going a bit through the shader graph I noticed there are some differences compared to the shader language. Yes, I'm referring to the language :)... didn't know how to put it :D. Also it's not about 2D/3D, shader is still shader.<br><br>'mix' doesn't do that, neither 'normalize', just open up godot and look at the 'CurveMap' node in the shader graph, it's an operation that gets input and normalizes it, mind you this isn't the same as normalizing a vector which means just making it's length 1.<br><br>I was wondering how would one go about implementing that CurveMap in the shader language. I suspect it can't be implemented yet, but I can't be sure cause I'm a complete noob when it comes to shaders :D. And yes, I like text more than graphics :P, that's why I prefer shader language.<br><br>Also looking at the code doesn't help, I've already search for CurveMap and it seems it's only in those files related to the shader graph editor, so no shader language aparently... so yah :)

<blockquote class="Quote">

<a target="_blank" rel="nofollow">razvanc</a> said:

:)<br><br><br>'mix' doesn't do that, neither 'normalize', just open up godot and look at the 'CurveMap' node in the shader graph, it's an operation that gets input and normalizes it, mind you this isn't the same as normalizing a vector which means just making it's length 1.<br>

</blockquote>Assuming a scalar array for an input I see not why you couldn't normalize your gradient(i.e. remap) to a new length with mix(linear interpolation aka lerp) which is what I assumed you wanted to do. However I must have misunderstood(as I suspected) your problem, and I still don't know what exactly you are/were trying to achieve... and normalization indeed does scale a gradient to a zero to one range. a clamp clamps a gradient into a zero to one range by cutting of any values above one and below zero...<br><br>Also note that curvemap only takes zero to one scale values as input...<br>

Welp, I guess this kind of answers it :). I wasn't sure if CurveMap needs input in the range 0 - 1, with this it makes sense and doesn't actually do what I thought :D. So well, need to go back to the drawing board.

well, again, I'm not entirely clear on the technical issue you are specifically trying to solve here so if you would explain the actual issue you have, maybe we can figure out a solution for it.<br><br>As far as the lerp example, it might be only a partial solution however you could curve deform the result from the lerp afterwards for an example, also color ramp could be another solution perhaps?<br>

Welp, if you want specifics, I'm trying to understand this shader business. I mean after reading some stuff I have a pretty good understanding of what it is and what it's doing, but you know... putting it in practice is more when things go wrong :D.<br><br>I'm trying to figure out a way to make a mask that goes from 0 to 1 on an object, 0 being at the bottom of it and 1 at the top (so on the Y axis), no matter it's orientation in the world space. I'm pretty sure there's a simple way to do it based on the vertex locations or normals or something, I just haven't found it... cause again, practice :). And I was thinking of using the vertex Y coordinates but it doesn't work cause they have to be normalized to 0 - 1... so back to the drawing board

So you want to achieve this: https://youtu.be/TtQjrMbAIRA?t=17m42s <br><br>(edit)<br>ok, so the new forum software doesn't let me post the youtube link as a link with the specific timestamp for the video.<br>watch from 17m40s on-wards.<br>(/edit)<br><br>a dot product of world vector and tangent space normals should do it(essentially like in the video).<br><br>

uniform color diffuse;<br><br>vec3 YAxis = vec3(0, 1, 0);<br>vec4 invcamx = INV_CAMERA_MATRIX.x;<br>vec4 invcamy = INV_CAMERA_MATRIX.y;<br>vec4 invcamz = INV_CAMERA_MATRIX.z;<br>vec4 invcamw = INV_CAMERA_MATRIX.w;<br><br>mat3 invcam = mat3(invcamx.xyz, invcamy.xyz, invcamz.xyz);<br><br>vec3 world_normal = NORMAL invcam;<br>vec3 world_pos = (VERTEX - invcamw.xyz) invcam;<br><br>float special_k = dot(YAxis, world_normal); <br><br>DIFFUSE = diffuse.rgb;<br>EMISSION = vec3(special_k, special_k, special_k);

<p>the inverse cam matrix bit I took from the docs:</p><p>http://docs.godotengine.org/en/latest/reference/shading_language.html#examples<br></p><br><br>

I already know how to do a dot product between world up vector and normal vector, a tad simpler is my solution:<br><br>

vec3 up = vec3(0, 1, 0);<br>vec3 world_normal = (INV_CAMERA_MATRIX * vec4(NORMAL, 0)).xyz;<br>EMISSION = vec3(max(0, dot(world_normal, up)));

<br>But I'm not looking for this. I was looking for a calculation that assigns 0 to bottom most vertex and 1 to upper most, with all the others in between of course, so a gradient from 0 to 1 in world. I have no idea how to achieve that :D, I thought that CurveMap might help me but seems not. Anyway, thanks for the interest :)

ah, I see, I trust you can translate that into shader language on your own. I overwrote the vertex colors rather than using the varying/variable outputs but YMMV so don't feel compelled to use that, if your mesh is dense enough though, might help you save those 2 vars for other purposes, though:<br><br><img title="Image: http://picload.org/image/rrwaodir/scaling.png" src="http://picload.org/image/rrwaodir/scaling.png" alt=""><br><br>edit:ah, you solved it another way, without reloading the tab I didn't see your post before.&nbsp; Not sure why you are adding zero's there though.<br>

I'll give it a shot, thanks :-). Didn't think about writing to vertex color as I'm n00b at this :-P. I'm not adding 0, that's a uniform that I set from the inspector. Thanks, yours is based on normals, I'll definitely explore it.

I should have looked more carefully it is in the node name after all.<br><br>About the screenshot: Do note that my screenshot only gives you the gradient's scaling correction. the dot product gradient it is correcting there is object space and will rotate with the object. But yeah if you do the matrix multiplication with worldmatrix it should work(to be fair I'm saying that without bothering to test first :blush: - edit: - yeah, after worldmatrix multiplication might have to multiply by 2 not .5, should have tested first).<br><br>Also I've been testing on a UV Sphere, so who knows, perhaps too 'perfect' test case for error/issue finding. D:<br>

6 years later