Mark: Texture shader problem ;(

About Monkey 2 Forums Monkey 2 Programming Help Mark: Texture shader problem ;(

This topic contains 4 replies, has 2 voices, and was last updated by  AdamStrange 1 year, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9552

    AdamStrange
    Participant

    I’ve got shaders and i’ve got textures

    The texture is a Mojo/Graphics/Texture:

    tex:Textur = Texture.Load( “asset::chars64x64_font.png”, TextureFlags.Dynamic )

    it uses:

    tex.Bind( 0 )

    to bind the texture to the shader

     

    the shader is custom, but uses:

    uniform sampler2D TextureSampler;

    in the fragment to get the texture

     

    How do I bind tex2 to the shader?

    I know it would be Tex2.Bind(1)

    But it would need a uniform name for the shader to find it.

    What would you suggest is the right way to do this? I know it has something to do with Texture.ValidateGLTexture(), but can’t fathom where the text would be put?

    anyone have any suggestions?

    #9561

    Mark Sibly
    Keymaster

    Youi need to use glGetUniformLocation to get the location of the texture from the shader, then glUniform1( n ) to set this uniform to the texture unit the texture is bound to.

    Do not use Texture.Bind(), this is very much part of the mojo shader system and will change in future. I will also be making it ‘Internal’ soon (along with a bunch of other @hidden stuff) now that I have ‘Internal’.

    Instead, use ValidateGLTexture() to retrieve the gl texture handle and glActiveTexture to select the unit you want to bind it to. So the whole process is something like:

    Local unit:=0   ‘up to you < GL_MAX_TEXTURES or whatever it is…
    Local location:=glGetUniformLocation( program,”SamplerNameInShader” )

    glUseProgram( program )
    glUniform1i( location,unit )
    glActiveTexture( GL_TEXTURE0+unit )
    glBindTexture( GL_TEXTURE_2D,texture.ValidateGLTexture() )

    #9569

    AdamStrange
    Participant

    thanks Mark. I’m looking into the code snippet above and will report

    #9571

    AdamStrange
    Participant

    Brilliant… After a bit of tweaking and working out where best to put things it worked – 2 textures YAY 🙂

     

    Small question about the Texture class.

    How would I copy an Image into a Texture?

    I would like to have one of the Textures updated regularly with the contentment from an Image

    i’m currently using:

     

    _image.GetTexture(0).ValidateGLTexture()

     

    is this correct?

    #9572

    AdamStrange
    Participant

    OK. Heres the result i was looking for:

    this is NOT a traditional shadow caster. is is operating in 2d and then being combined in 3d taking the 2d dimensions.

    it should be able to handle many (well around 50-150) point lights without affecting fps. I will need to do trials now

    the FPS is a rock solid 60 – not 6 (the 0 got clipped)!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.