License from €75 Log in
DE EN FR ES IT CZ

Passing _t_texture to shader doesn't work

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 10 years ago
    I get flat black instead of texture. I have suspicions, that's something to do with uv, but it's just wild guess.

    Lua code (i disable shaders by setting *.ShaderSet to "-1" and unregistering event):
    local shaderHP = shaderCompile(Shaders.high_pass.Compiled)
    
    
    function shaderHPLoop()
      graphics.shaderUniform(shaderHP,"_t_mountains", "vispath:mountains.png")
    end
    
    
    function highPassShader()
      Scenes["001-001_scene"].ShaderSet = shaderHP
      Objects.kittan.ShaderSet = shaderHP
      registerEventHandler("mainLoop", "shaderHPLoop")
    end

    And fragment shader (i ommited everything, that's irrelevant):
    varying vec2 uvVarying;
    uniform sampler2D _t_mountains;
    
    void main ()
    {
    vec4 mountains = texture2D (_t_mountains, uvVarying); 
    gl_FragColor = vec4(mountains.r,.3,.4, 1.0); // f.e. red channel is flat black
    }


    VS5.b1188, texture file path is correct (mentioning, because no error like "nil" is generated if path is not correct, so easy to make a mistake here)

  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 10 years ago
    You missunderstood how this works.
    Name the uniform just mountains:
    uniform sampler2D mountains;

    Then you need to change the code:
    vec4 col = texture2D (mountains, uvVarying); 
    gl_FragColor = vec4(col.r,.3,.4, 1.0); // f.e. red channel is flat black

    and then access it like this:
    graphics.shaderUniform(shaderHP,"_t_mountains", "vispath:mountains.png")

    btw. you only need to set the texture once, if you don't change it.
  4. · 10 years ago
    Thank You!

    It's working perfectly, that prefix is stripped underway, now i get it. And yes, i know about setting it once, it's was just a sign of desperation, when started with "hit and miss" tests.

    This is my first project in Lua, with all coding experience from before just some simple javascripts, and frankly - i'm hooked. Here i first time understood importance of shaders overall, not just in VS, now i see diferently, how graphics of most games work. Thanks for this enlightenment too.

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?