Passing _t_texture to shader doesn't work

  • #1, z stroncisSaturday, 06. May 2017, 23:43 hodinky 8 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)

    Bažant

    42 Posts


  • #2, z SimonSSunday, 07. May 2017, 00:15 hodinky 8 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.

    Kapitán

    1582 Posts

  • #3, z stroncisSunday, 07. May 2017, 01:22 hodinky 8 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.

    Bažant

    42 Posts