Fill image with custom shader data

Home Forums Monkey 2 Programming Help Fill image with custom shader data

Tagged: 

This topic contains 9 replies, has 3 voices, and was last updated by  nerobot 2 months, 2 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #10283

    nerobot
    Participant

    Hi everyone.

    I want to fill image with some data that produced by shader.

    What I need is to pass some variables to my shader:

    I tried to use Image.Material.SetTexture() and so on – no effect. Please help.

    #10285

    nerobot
    Participant

    Yay, I got it myself! 🙂

    No GLWindow required, just mojo.Window.

    I missed Material.SetInt() method to pass iterations counter, so need to cast types inside of shader.

    #10286

    Mark Sibly
    Keymaster

    I’ll add SetInt if you want – just post an issue to github to remind me!

    #10287

    nerobot
    Participant

    You can pass texture to shader by two ways:

    1. _image.Material.SetTexture( “myTex”,_tex )
      • in shader name will be m_myTex
    2. _image.SetTexture( 0,_tex )
      • in shader name will be m_ImageTexture0

    Note: _image.Material.SetTexture( 0,_tex ) don’t raise an exception but is incorrect.

    (0 -> toString -> “0”)

    #10288

    abakobo
    Participant

    Great to see that custom glsl shaders have some kind of interface now!

    #10294

    nerobot
    Participant

    Why Image.Shader property is read-only? I want to change shader on the fly. Is it possible?

    Canvas class just grab shader when render image,

    so I think we can change it and that should break nothing.

    #10295

    Mark Sibly
    Keymaster

    Yes, it’s possible, although to be honest I can’t see why you’d want to change shader on the fly.

    I do tend to make things read only by default if there doesn’t seem to be an obvious reason to allow them to be writeable. I find this generally keeps object logic much simpler and often allows for future optmizations.

    [edit]Pushed to develop branch![/edit]

    #10296

    nerobot
    Participant

    In my case, I want to bring MaskTexture property into Image class.

    To apply texture as a mask I was going to use shader processing, and for that purpose I need to switch default ‘sprite’ shader with ‘sprite-masked’.

    Maybe you’ll add this as a core part or mojo.

    I’ll post my approach with masks in code libs soon.

    #10301

    Mark Sibly
    Keymaster

    Not sure what you mean by a MaskTexture here – is this like storing the alpha channel in a separate texture?

    But the idea is/was that if you want to use a different shader with an image, you need to specify it when constructing or loading the Image. You could also do things like add Image.LoadMasked() style class extensions.

    A quick thought though: Image is not really designed for extension the way mojo3d’s material is. Maybe it should be?

    Material has a protected SetShader method so subclasses (like PbrMaterial and WaterMaterial) can change their shader ‘on the fly’ if necessary. The idea is that material will eventually have a protected InvalidateShader() method, and a protected virtual OnValidateShader:Shader() method. InvalidateShader() would be invoked when certain properties are modified, and OnValidateShader() would return different shaders depending on material property values. For example, if a material’s NormalTexture property is null, OnValidateShader() could return a non-bumpmapped variation of its shader. A lot of this is just theory though and has not been implmented yet. I’m kind of afraid it might be overkill, and will just be too complex to be useful.

    In this case, Material.Shader is not writeable as this defeats the purpose of giving material subclass control over the shader. That said, it would be possible to write a CustomMaterial subclass or similar that did allow you to write Shader.

    Image could work in a similar way, or perhaps even subclass Material too.

    #10302

    nerobot
    Participant

    Thanks for information!

    There is what I do: http://monkeycoder.co.nz/forums/topic/image-with-texture-mask/

    Maybe there is built-in support for this and I missed it.

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

You must be logged in to reply to this topic.