Volkovino

  • Dec 20, 2022
  • Joined Mar 21, 2021
  • 1 best answer
  • Below "uniform line" in shader gives "Expected datatype.-" error.

    struct points{
    	vec2 p[8];
    };
    uniform points pointsArray;

    Do I have syntax mistake?

    • Volkovino replied to this.
    • According to the documentation all GLSL types except void can be used as uniform. That does not include user defined data types.

      Am no crack in Godot shading language but know a bit about GLSL. There, that can't work. Any implementation of a C or C++ compiler is free to choose whatever memory layout it pleases for user-defined data types (here structs and classes, which are the same). So there must be a way to transmit that extra description together with a struct, like what datatypes come, how many bytes do they use, their memory order, is there any padding in between to fill spaces, and GDScript would have to do the same.

      GLSL and its C specification solves this with uniform blocks and pre defined memory layouts, and a set of functions to query a shader's interface, it's list of uniforms and other buffer objects. Unless Godot shading language offers an own way of handling these interfaces (that'll be a lot of work on all the platforms), I believe that you have to pass in all the uniforms one by one. Though that's very slow compared to a properly set up GLSL or Vulkan buffer object.

      But wait for a crack to show up with better knowledge about Godot shading language, maybe there's a way I'm not aware of.

    • It is the 2nd step of previous question (https://godotforums.org/d/30871-method-to-convert-png-inclalpha-into-2-files-in-etc1-format-via-2-uniforms)
      What I know regarding texture() and textureFecth() are detailed below.
      texture() uses float within the UV coordinates and needs an info such as nearest or linear in openGL.
      textureFecth() uses int within the texture/screen coordinates and needs an extra parameter "LOD"

      Previous reply (https://godotforums.org/d/22990-texelfetch-equivalent-in-gles2) is available for a similar help request .

      SIsilicon28 The second function only applies a filter if you setup the sampled texture to do so. Most if not all Godot textures have a filter property. If you disable that along with mipmaps you are guaranteed to have no filters applied to the texture.
      gba25 Thank you! It worked but texture still has very low accuracy. texelFetch was able to extract values from sampler2D with 32 bit float accuracy

      Success seems partial.

      I have converted a lot of Shadertoy codes from tectureFetch to texture together with int/float and UV/screen changes in Shadertoy and tranferring Godot. Almost % 50 of the code gives full success in 2 two mediums. others are not only have low accuracy problem and also full logic changes. And alot of missing.

      I believe there is a way to implement the multiple texture() functions with a mipmap/LODs (and maybe offsets for linear/bilinear/trilinear) instead of a single texelFetch() command dor a full equivalency.

      Maybe an array can work like in "vec4_type texture (sampler2DArray_type s, vec3 uv [, float bias])" with Mipmapped series.

      Can you help me please?

    • As understood, I am busy with GLES 2.0 and mostly oriented to 2D.

      I am trying to setup a performant template to convert/split a png file into 2 ETC1 files one includes rgb, other includes alpha. MipMap included to call texture with offsets (because no preset in godot shaders regarding nearest/linear/bilinear/trilinear options. i do not know the performance effects with these calls) later.
      Maybe mipmapped series can be added into ECT1 couples. So, maybe more than 2 Sampler2D required for one image.

      What i am looking for are listed below.
      110 figure out ETC1 format properties
      120 import ETC1 as mentioned above
      120a in editor manually
      120b on the fly with for multiple images

      130 texture function implementation pretending texel fetch (a separate help request will be for this one)

      I have checked some documentation

      1100
      https://registry.khronos.org/DataFormat/specs/1.1/dataformat.1.1.html#ETC1
      little bit confused. if you reply the other options it will be clearer.

      1200
      https://docs.godotengine.org/en/stable/tutorials/rendering/gles2_gles3_differences.html#texture-compression



      https://docs.godotengine.org/en/3.5/tutorials/assets_pipeline/importing_images.html#importing-textures

      1200a - If you fill a sample for this one it will be perfect.

      https://docs.godotengine.org/en/stable/classes/class_image.html
      1200b - sample code will be perfect

      Thanks in advance.

    • cybereality
      I am still grateful to you. You opened up a blocked path to me.
      So, and unfortunately for you, this means that a flood of questions (some maybe illiterated 🙁 ) will come soon.
      Hope to get your precious help regularly.

    • Tomcat

      The article (some short, some longer including transcripts) for each video is available at the link below the video

      • cybereality Hi,

        Thanks for quick reply.

        I know the base logic that gives the derivatives between the center pixel and each neighbour pixel on mentioned axis.
        But little confusing about the function parameters (vec2 pos, vec4 frag, vec2 pixel). Original dFdx/dFdy takes only one parameter. Still I am hesitant which info in parameters should be included in the function.

        Any possibility to give a sample code snippet to call the function from fragment() with some quick comments?
        e.g.:
        vec2 pos = .... ..... ..... ..... // ........... ............. ...............
        vec4 frag = .... .... ...... .... // ......... ............ ............. ...........
        vec2 pixel = .... ...... .... ..... // ......... ........... ........... ..............

        Thx in advance...

      • I have found a sample project regarding Anti Aliasing by Viewport Post Processing via Derivatives (dFdx, dFdy and fwidth) in GLES 3.0.
        Where can I get Anti Aliasing by Viewport Post Processing via another method in GLES 2.0?
        Thx in advance.

        • pos is the UV, frag is FRAGCOORD, and pixel is the width/height of one pixel or 1.0 / VIEWPORT_SIZE

      • I have found proper tutorials regarding Fragment Shaders in the net such as Book Of Shaders, Shadertoy, Processing, etc. Even I have shared my own self teaching material by converting godot shader language (GLES 2.0) as a tutorial template. https://godotforums.org/d/30669-2d-fragment-shader-tutorial-series-beginner-to-advanced-gles-20

        However I could not find any organised resource regarding vertex shaders in order to adapt into Godot Environment.
        I also need built in godot vertex function and varying, which transfers the infom into fragment shader, samples [2D, GLES 2.0] .
        Could you carry me away a starting point for those other than Official Godot Documents?

        Thx in advance

        • Godot uses it's own subset of GLSL, but it is effectively the same. I mean, not all the functions are ported over, and there are some differences in the built-ins, but it is essentially standard GLSL. So general OpenGL books should help you. I never actually learned OpenGL, but I did a lot of work with DirectX and HLSL is not all the different either. Once you see the logic and math and the algorithm, the slight syntax differences don't matter much.

      • Hi Everyone,

        I am a toddler as Godotista. When searching more optimised and performant results for a multi hundred nodes project, first tried GdQuest, then came across C++ native code support and shader infrastructure combined projects.

        I believe Godot is a perfect and easy interface, prototyper along GdScript and starting environment but should be combined with those support eventually.

        I have been concentrated to increase my C++ knowledge and to build shader infrastructure from scratch for 5 weeks.

        During this period, first fruit , maybe it is simple, appeared as my self teaching tutorial. I have converted a shadertoy file into a Godot Project as shown below. Another one for Book of Shaders is in process.

        Project Link: https://github.com/Volkovina/GLES-2.0-2D-Fragment-Shader-Tutorial-Series-in-Godot-Beginner-to-Advanced
        All the details are in Readme file in the Link.
        Godot Version: 3.4.4 Standard
        Shader: GLES 2.0
        Platform: Windows 10

        Hope it will be beneficial for every one.

        Note: Actually, recent month story started and goes on with the headlines below. still same.

        • final target: multi hundred moving objects representing flowing water in 2D
        • interim target: concave polygons
        • interim target: alpha shapes
        • interim target: post processing of the texture viewport which includes moving objects
        • interim target: anti-aliasing in post processing shader
        • interim target: vertex shader support to increase fragment shader performance
        • interim target: search a full vertex shader tutorial in GLSL 2.0 and interaction examples between frag-vertex
        • ...... goes on 🙂
      • All duly noted.
        for the noob indies (like me) ,which suck and filter info slow, it was enlightening for the recent developments.
        Now, I am aware about the possibilities and I can arrange the wide path to proceed regarding hardware, software, mobile market.

        Thank you for your intensive interest.

      • Thanks for all precious answers...

        There is an impossible issue regarding Nvidia may support older cards with Vulkan driver on a close date.
        There is a maybe about Godot 4.1 will support openGL in next stages.

        As far as I know from the info in the net,
        most of the Android systems, on little older mobiles, have no support for Gles 3.0 (maybe Vulkan too)
        For this reason, I use Gles 2.0 with Godot 3.x.

        I believe that brand new computer and brand new mobiles dependent development does not exactly fit with the Godot "free" philosophy, especially in these economical crisis days and specifically in third world countries.

        At least, can anybody tell me whether the devs will continue to develop Godot 3.x for some additional years?

        • I have tried godot 4 - alpha 4 & alpha 9 releases (win64). However, i received same messages below respectively. Almost same except line of the code depends on assert.


          My system is like that below.
          Processor: Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz 2.60 GHz
          Ram: 12 GB
          OS: Windows10 - x64
          Graphics Card: Embedded in Mainboard (driver details below)

          Can I use Godot 4 any beta or stable release eventually with this configuration?

          • The cheapest new GPU you can buy, that supports all the latest standards is the RX 6400.

            https://www.newegg.com/asrock-radeon-rx-6400-rx6400-cli-4g/p/N82E16814930068

            It's honestly a pretty weak card, but it's cheap, and for development of lower-end games it's probably okay (like I'm saying 2D games or classic 3D). However, you need a desktop computer and it looks like the OP is on a laptop. So their only option would be to buy a whole new laptop, which I would say is not a good idea to test alpha software. Godot 4.0 may be a year away from release, so it would make more sense to upgrade when it actually comes out (especially considering that GLES3 support may work by that time). Also, Godot 3.x still works fine and may be supported for another 2 years or who knows how long. So I think it would be premature to spend a bunch of money right now.

        • There is data communication between GDScript and OS via HARD DISK.
          for the clipboard "STRING" content, there is a way between them using OS.get/set_clipboard() methods via RAM.
          However, for the clipboard "IMAGE/TEXTURE" content, i could not find a way to communicate via RAM.

          For instance, godot has such capability to get screenshot using "get_viewport().get_texture().get_data()". But it is only for GdScript internal use.

          I believe Godot , which is flexible structure, must have this very basic method.

          I am working on a narrow scope word processing software project which will include rich text editing, graph editing (graph nodes etc.) and image transfers from/to OS, I have checked Emilio's base studies concerning those subject
          (
          But I could not find any clue regarding my issue. If godot can not provide such a service. I need to change my path soon.

          Am I incompetent to find an available service or gdscript has not a method for such thing?

          Thanks for any guiding in advance...

        • I tried to attach a gdscript code to a child node during the runtime. But no effect of the script on run. Need help!!!

          Thanks in advance.

          Codes are below.

          (attached script to the "parent" Node2D)

          extends Node2D
          
          func _ready():
          		$Line2D.set_script(load("res://drawing_line.gd"))  

          (drawing_line.gd - gdscript which I tried to attach to the child node)

          extends Line2D
          
          var line2D_coord_X1 = 697.1718063
          var line2D_coord_Y1 = 157.0043504
          var line2D_coord_X2 = 224.4594551
          var line2D_coord_Y2 = -55.62737387
          
          func _ready():
          	self.clear_points()
          	self.add_point(Vector2(line2D_coord_X1, line2D_coord_Y1))
          	self.add_point(Vector2(line2D_coord_X2, line2D_coord_Y2))
          • Welcome to the forum @Volkovino!

            I think the issue is that the code on the script you are attaching only has code in the _ready function, which is called when the node is added to the scene. Maybe try calling the _ready function manually after setting the script and seeing if that works?

            Something like:

            $Line2D.set_script(load("res://drawing_line.gd"))
            $Line2D._ready()