1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

There's any way to get data from shader to gml?

Discussion in 'Programming' started by Edgamer63, Dec 2, 2019.

  1. Edgamer63

    Edgamer63 Member

    Joined:
    Jan 24, 2018
    Posts:
    77
    Hello, as question says... There's any way to get data from shader to pass into a variable to gml?... not shader_get_uniform() .... Some kind of manipulating a buffer (For get values outside of shader) to get the data? :O .
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,220
    You can transfer a surface manipulated by that shader to a buffer.
    Look up buffer_get_surface().
     
    Edgamer63 likes this.
  3. Edgamer63

    Edgamer63 Member

    Joined:
    Jan 24, 2018
    Posts:
    77
    So, the only way to pass normal data into gml from shader is only buffer_get_surface() ? :O
     
  4. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    897
    shaders work on the gpu to manipulate images. Because it works through the gpu it's able to do calculations extremely fast and it's also why you can't just use normal gml to make sharers.
    because of where the data is stored for the shaders use it can not permanently save data, in fact (I could be mistaken) but all data in the shader is cleared after every pixel.
    But the shader can manipulate data instead. That's what it's doing when it modifies an image. It's just changing the rgba channels to match what you want and then rendering that instead of the original.
    If you use a shader on a surface you are changing the data that is stored inside of that surface.
    surfaces are stuctured internally in a way that makes drawing them to the screen very quick. However if you want to get a single pixel (using surface_getpixel) it's actually really slow:
    that is why you should use buffer_get_surface because that will restructure the data to make getting all the data out of that surface quick.

    However it is in general rare that you should need to get the data straight out of a shader like this. You are trying to extract normal data? For what though? normal data is usually used in shaders so you can just use the created surface or image as an input for the shader that needs it.
    If you need to save out the normal data to a file just save the surface directly.
     
  5. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    2,009
    You could replace "GML" with "Unity" or "Unreal Engine" or whatever and the answer is the same, because that's how shaders work. It is akin to a script. You set up the shader, you run it, the shader does its magic, and the only stuff you get out of it is whatever graphical manipulation you set it up to do. Well, you could inject your values into the graphic data and then read them out, that's what some stuff does to speed themselves up with GPU processing.
    Or to put it more appropriately, GPUs have their own languages, so shaders must be written in them (GML only supports GLSL I recall). Technically, YoYo could write their own vertex and fragment stuff and then have it intepreted into GLSL but there'd really be no point in that. (Well, blend modes are GPU shader pipeline manipulation, so they've actually done that already.)
     
  6. Edgamer63

    Edgamer63 Member

    Joined:
    Jan 24, 2018
    Posts:
    77

    Well, is for storing some float,int or whatever values; if it's possible.

    Thanks :D
     
  7. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    897
    Again, it's rare that you should need a shader for it. I'm sure whatever you are doing there is a better way, it's like asking how to cut a steak with a spoon. You'll have to take extra steps and it would be easier to just get a knife. But I'm not here to question that.
    Your best bet to get data out of a shader is to retrieve it from a surface / image that it draws to. You can use the get pixel functions but they run very slow so be cautious if you use them. Other than that I can't think of any other ways.
     
    Edgamer63 likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice