[SOLVED] shaderUniform to load Textures

  • #1, by caligarimarteTuesday, 05. September 2017, 15:22 7 years ago
    I am trying to load a Texture into a Shader via ShaderUniform, as shown in the API: 
    graphics.shaderUniform("_t_texture", "vispath:data.png") 
    So, I have added uniform sampler2D _t_Sterne to the Fragment Shader and the Vertex Shader (I suppose both need it), further down in the Fragment Shader I call the Texture via vec4 Sterne = texture2D(_t_Sterne, fract(uvVarying.xy)), then adding it to the Result. In the Script executing the Shader I have written the Following:
    local eff = shaderCompile(Shaders["Wolkenshader02"].Compiled)
    
    
    
    Objects[obj].ShaderSet = eff
    
    
    
    graphics.shaderUniform(eff, "_t_Sterne", "vispath:graphics/bg/sterne_generell01b.png") 
    

    I am sure the Path is correct, and I suppose that the Way I have written the shaderUniform (prefixing the Name with "_t_") might be correct, but I am not entirely sure. I have also tried around with Variations of the Code, in the Script and in the Shader, but it doesn't work.
    Additionally, I actually had my Shader set up in the Form that is using the Shader-Toolkit, in Order to use the automatically updating bind()-Function, and I would prefer to let it stay that Way, but it looks like the bind()-Function won't accept such Texture-Input. My Script thusly looks like this:
    local obj = "QuistaClouds"
    
    local eff = "Wolkenshader02"
    
    
    
    shaderRemoveEffect(eff)
    
    
    
    bind(eff, "time", field("getTime()*0.001"))
    
    bind(eff, "SunX", field("0.115"))
    
    bind(eff, "daytime", field("Values.Daytime.Int * 0.0125"))
    
    bind(eff, "daytimeFine", field("Values.DaytimeFine.Int * 0.00001"))
    
    
    
    shader_effects[eff] = { shader = Shaders[eff].Compiled }
    
    shaderAddEffect(eff)
    
    shaderRemoveEffect(eff)
    
    Objects[obj].ShaderSet = shader_effects[eff].num.num 
    

    So, how do I use ShaderUniform (or possibly even bind()) to input a Texture? What is it that doesn't work about the Method I have tried?

    Forum Fan

    145 Posts


  • #2, by caligarimarteFriday, 08. September 2017, 15:33 7 years ago
    Please, can I get an Answer? I know that I could possibly generate the Stars in the Shader itself, but that would be so much more inefficient and performance-heavy than just using a Texture. And I know I could use a second, separate Object for the Stars behind my Cloud-&-Sun-Object, but managing a Multitude of Objects and making sure all their Shaders interact with one another synchronously can become quite a Hassle if it has to be done for all Scenes with a visible Sky.

    Forum Fan

    145 Posts

  • #3, by SimonSFriday, 08. September 2017, 15:43 7 years ago
    The prefix _t_ is only to tell system that this is supposed to be a texture, do not put the _t_ prefix in the shader.

    Thread Captain

    1580 Posts

  • #4, by caligarimarteFriday, 08. September 2017, 16:28 7 years ago
    Thank you, that was a big Help to steer me into the right Direction. I had already tried that before and it didn't work, but now knowing that's the Way to go, I realized what the more essential Problem was, namely that I had written:
    graphics.shaderUniform(shaderCompile(Shaders[eff].Compiled), "_t_Sterne", "vispath:graphics/bg/sterne_generell01b.png") 
    Which only seems to work for the No-Shadertoolkit-Form, but with the Shadertoolkit-Form I had to write this:
    graphics.shaderUniform(shader_effects[eff].num.num, "_t_Sterne", "vispath:graphics/bg/sterne_generell01b.png")  

    Now it works. Thank you very much! smile

    [EDIT: If anyone stumbles onto this now after it has been solved, here is a little Video of what my Sky-Shader now looks like with that rather likable starry Nightsky...]

    Forum Fan

    145 Posts