Some shader uniforms not initalized when applied to a 'Text' object?

  • I will file this as bug if needed, please let me know. However, I am checking if I am missing something fundamental.

    I am creating a new shader and found that the pixelSize uniform was set to 0,0 when I applied the effect to a 'Text' object. I checked this through running remote preview and using spector.js to inspect the uniforms for the effect when the 'Text' object is rendered with the shader. When I apply the same shader to a Sprite object it works fine.

    After seeing that, I tried some other built-in effects on the 'Text' object, to see if I could see a similar error. I found that when I applied 'Bulge' to a text object, the text disappeared in the editor. I then tried remote preview and spector.js with this and found that srcOriginStart and srcOriginEnd were both set to 0,0. So the bulge shader also 'failed'.

    I found that the effects started to work when I stacked another shader (any shader) on the text object (so then there would be multiple renders to multiple FB and then the uniforms were properly set for the fragment shaders.)

    Should I be doing something special with my shader to make it work with the 'Text' object? If there is, likely the same thing should be applied to the builtin Bulge effect also (and perhaps others?)

    Here's the spector.js output for looking at the Bulge effect on the text object:

    Thanks for the help Ashley!

  • Currently the source rectangle and pixel size parameters are only set when rendering an image-based object like a Sprite. This is because those values come from the sprite sheet (the pixel size being derived from the source sprite sheet texture size, and the source rectangle being set from the area of the spritesheet being rendered for the current sprite). It might be tricky to figure out how to apply those to non-spritesheet objects like Text.

  • Thanks. The uniforms do get set when you have 2 or more effects on text. Are they then set to the intermediate FB source rectangle and pixelSize? That’s my work around for now to stack two effects on the text object.

    Could you do the same when it’s just one effect? Don’t you render the text to an intermediate texture already and you should know the source rectangle and pixelSize of that intermediate texture and could set the uniforms based on that?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The effect compositor is super complicated. It has lots of separate special paths, and it knows about the source texture for Sprites and intermediate surfaces, but not Text objects (which is only significant on the first draw).

  • Thanks for the reply and info.

    Do you see any issue with my work around then? Apply a simple shader first that does not use the texture uniforms and then after that apply the shader with that uses the uniforms, since they are then set and available (works for me now.)

    I know there could be some perf impact, but will deal with if we have to.

  • Well, that imposes a performance cost on all games, for one very specific case.

    Frankly the effect compositor is so brutally complicated I'd rather not touch it. Working with it is an absolute nightmare and it's been really hard to get even small changes right in the past.

  • Oh sorry, maybe I was not clear, I’m just going to do the work around in my game for that one object put two shaders). I am not asking for a change to C3. I may even make a dummy shader to try to lower the perf impact a little. I just wanted to see if you thought that was ok.

  • Ashley,

    Thanks for the link on the shader compositor, very interesting reading.

    For now, what I have done is remove the pixelSize uniform from my shader and instead pass in similar values for the text object custom effect via user uniforms. I pass it '1.0/Text.width' for my own pixelSizeUser.x and '1.0/Text.height' for pixelSizeUser.y. This seems to work ok so far for iPhone mobile, safari and chrome on MacOS, with both high and low quality fullscreen and multiple resolutions. If the text box size changes, I must update the uniforms. Also if I spawn a Text object with the effect, I also must update the uniforms for the Text object spawned.

    I understand your comment on the complexity, I see different behavior of the effect compositor on mobile and desktop with existing effects, so I see that adding more uniforms, etc. may be difficult.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)