xyz
Not sure why there is a difference in editor and when you run the scene.
Only 2 colour are appearing when scene is run.
Also when you zoom in colour disappear in editor, only one colour is visible.

  • xyz replied to this.

    sstelkar The problem is likely in u/v coordinate you use as an input to your stepping nodes. You should use object space UV, not screen space.

      xyz
      Is there an input for object uv, if it is not an elaborate process. Can you please show me how to get object uv.

      Also in unity position of world is used subtracting object position, so that there is a liquid flow effect.

      award
      basically I want to subtract object position from world space,to get liquid flow effect

      • xyz replied to this.

        sstelkar By "liquid flow" you mean keeping the gradient always horizontal when you rotate the bottle?

          xyz
          yes. That would only be possible if the colours do not change in y axis, even when the bottle is rotated. Need position node for this to work or anything that is a substitute in Godot. Thanks

          • xyz replied to this.

            sstelkar That has nothing to do with mix or lerp though, so you should rephrase your original question or open a new thread.

              sstelkar changed the title to create a gradient texture that does not change vertically when object is moved .

              sstelkar You could probably do it by fudging screen UVs but it's better to use object's UV for multiple reasons, one being a nice zoom independent preview in editor and the other is that tilting the bottle may hide considerable parts of the screen space gradient at the top/bottom. Instead, better to transform local uv space to stretch between top and bottom of bottle's rotated bounding box.

              Easiest way is to construct a shear matrix that shears the uv space around uv center (.5,.5) for a certain angle, to compensate for the tilt caused by rotation. Calculating this angle is the trickiest part, but here's the recipe:

              float scaleRatio = length(MODEL_MATRIX[0]) / length(MODEL_MATRIX[1]);
              float imageRatio = TEXTURE_PIXEL_SIZE.y / TEXTURE_PIXEL_SIZE.x;
              float shearAngle = atan(MODEL_MATRIX[0].y * scaleRatio * imageRatio, MODEL_MATRIX[0].x );

              If you don't have non-proportional scaling on the bottle sprite, simply remove scaleRatio from calculation.

              Once you have the angle, construct the shearMatrix with following basis vectors:

              shearMatrix = mat4(
              	vec4(1.0, sin(shearAngle), 0.0, 0.0), 
              	vec4(0.0, cos(shearAngle), 0.0, 0.0), 
              	vec4(0.0, 0.0, 1.0, 0.0), 
              	vec4(0.0, 0.5, 0.0, 0.0)
              );

              The above should be done in vertex function and the shearMatrix passed to fragment function as a varying.
              In fragment shader, subtract the object space UV from (.5,.5) to bring it to center and then multiply it with the shearMatrix. Use resulting V to drive your gradients.

                xyz
                Perfect. works as described.
                Support and speed of response was pleasantly surprising and fast.

                xyz
                Can you please tell me your years of experience in shader programming.
                Also since godot 4 has switched to vulkan, what is the future of godot shaders in coming years?

                  sstelkar So far from version to version the shader language has changed and improved incrementally. So not much breakage. That's the advantage of taking a well established language like GLSL as a basis and creating a simplified subset of it as your own language I suppose.

                  sstelkar Can you please tell me your years of experience in shader programming.

                  Hard to determine precisely 🙂. I've been tinkering with shaders on and off at least since OpenGL fixed functionality pipeline got officially deprecated with release of 3.2. standard. Can't remember exactly when that was.

                  sstelkar Also since godot 4 has switched to vulkan, what is the future of godot shaders in coming years?

                  Shaders are pretty much the only way to control GPUs. They won't go anywhere in the foreseeable future. Vulkan doesn't introduce any new shading languages as there's really no need for it. It supports a number of established and proven languages like GLSL, HLSL, OpenCL... Vulkan (and GL for that matter) will always compile any of them into same platform-independent assembly-like intermediate language SPIR, which can be easily translated by hardware drivers to actual GPU machine code.

                  Since Godot's shading language is basically GLSL with some "macros" added on top. Switching to Vulkan really makes no difference regarding its usage. GLSL is here to stay.

                  If you ask this to see if it'd pay off to learn GLSL or a similar language, the answer is - yes if you're genuinely interested in computer graphics programming. Almost all shading languages are very similar to C. So learning C may actually be a worthy time investment. It will introduce you to low-to-mid level programming approach that's very useful for games/graphics, as you often need to code close to hardware. But even more important is to learn the relevant math - trigonometry, vectors and matrices (linear algebra), and basics of calculus.

                    xyz Hard to determine precisely 🙂. I've been tinkering with shaders on and off at least since OpenGL fixed functionality pipeline got officially deprecated with release of 3.2. standard. Can't remember exactly when that was.

                    So ~14 years. xyz is quite the shader veteran.

                    sstelkar what is the future of godot shaders in coming years?

                    The lead developer of Godot, reduz, is very dedicated to backward compatibility. I know a lot of people were mildly traumatized when Unity split its render pipeline into 3 pipelines with 4 different, incompatible shader specifications. The core Godot developers will be careful not to do that, so Godot shaders should remain valid into the future.

                    • xyz replied to this.

                      award Sounds monolithic when you put it like this... but in that period I went on shader sabbaticals and shader hiatuses, including abstinence from using anything with electricity in it. But yeah, I like shaders. They run fast and produce instant visual results. High velocities and pretty pictures are among my top 10 favorite things in life 🙂

                      xyz
                      can you please share the complete example code, even if it is generated code. let me learn from it. in my case the bottle texture disappears after adding the line TEXTURE_PIXEL_SIZE

                      • xyz replied to this.

                        sstelkar I thought you'd do this in a visual shader. It's just a bunch of multiplications/divisions after all.