(shaders) shader_get_uniform always returns -1

Discussion in 'Programming' started by sir_derp, Jun 11, 2019.

Tags:
  1. sir_derp

    sir_derp Member

    Joined:
    Jul 12, 2016
    Posts:
    27
    I'm trying to write a shader to swap one color for another, but shader_get_uniform won't work, so I can't edit the data in the shader.

    the fragment shader

    shaders5.PNG the vertex shader:
    shaders4.PNG
    and the code that calls shader_get_uniform:
    shaders6.PNG
     
  2. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    I hate it when people ask the same question in two different places and I wonder if I should bother answering in both places. Anyway,

    Define a uniform variable with the "uniform" keyword.

    uniform vec4 skin_default;

    "Attributes" are per vertex, and are defined by the vertex format, and written to a vertex buffer. You'll thus also need to restore your attributes appropriately before your shader will work.

    "Varying" variables are passed from the vertex shader to the fragment shader, and interpolated between each vertex in a primitive for every fragment.
     
    Binsk likes this.
  3. sir_derp

    sir_derp Member

    Joined:
    Jul 12, 2016
    Posts:
    27
    I could've sworn I had tried that already. Any idea what the syntax error is with the if statement in this one? All the compiler says is that there is a syntax error at line 22, even if make the statement one long line.

    shaders_if.PNG
     
  4. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    Like the guy on your reddit thread wrote, I don't think (int) is a thing.

    By the way you might be able to get away with testing for equality between two colors like this: float(color1 == color2).

    If you get problems to do with floating point precision (not sure if that is likely to happen), there's a couple of other ways you can test for "equality" that should overcome that problem.
     
  5. sir_derp

    sir_derp Member

    Joined:
    Jul 12, 2016
    Posts:
    27
    what kind of programming language doesn't have a way to cast variables?
     
  6. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    you can do int(something)

    But you don't even need to because you are doing an equality test between two different vectors of floats anyway. Integers shouldn't even be coming into the problem.
     
  7. sir_derp

    sir_derp Member

    Joined:
    Jul 12, 2016
    Posts:
    27
    the problem is that with floats there is no guarantee that two floats will resolve as equal, even if they actually are.
     
  8. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    1,984
    I don't know if you will face that problem in this exact situation, but if you do, you can use something like

    vec3 diff = color.rgb - test_color;
    float equality = float(dot(diff,diff) < 0.00001);

    or

    float equality = float( ivec3(color*255.0) == ivec3(test_color*255.0));

    ivec3 is a vector of 3 ints. equality test is done on a component-wise basis.
     
    Last edited: Jun 12, 2019
  9. sir_derp

    sir_derp Member

    Joined:
    Jul 12, 2016
    Posts:
    27
    nevermind, I made it work, more or less
     

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