Is it possible to sample a sprite that is not being rendered but using the same texture as the one that is? For instance, I have 5 sprites on a texture (spritesheet) and I’m currently rendering the first sprite in the sheet, is it possible to sample the from the 5th sprite?
I know if 5 sprites are going horizontal then sprite 5 can be sampled by sampling vTex.x * 5.0 if I’m rendering the 1st sprite. Just wondering if an easier way of doing that besides making the users manually inputting the sampler rectangle if the sprites are not always the same size or layout
It's possible, but Construct's spritesheeting algorithm is non-deterministic so you don't know ahead of time which images are on the spritesheet. However you can simply set the texture and draw it via its texture co-ordinates for a different image; if it happens to be on the same texture Construct will batch it in to the same draw, otherwise it will switch texture.
Still it's a weird question and asking the user to enter UVs is definitely not the type of thing you should be doing, especially since spritesheets can be completely rearranged at the drop of a hat, so any user-inputted UVs will quickly become invalid. As ever, it's best to explain what your overall goal is, rather than the specific details of a particular approach that might not be the right one.
Develop games in your browser. Powerful, performant & highly capable.
In the transition effect, I’d like to add the ability to mask out a sprite using the sampled reference sprite. As of right now, it’s good for scene transitions bc it either draws the reference pixel transparent or a color based on how dark the reference pixel is. So let’s say you have an enemy and when he dies, you want him to burn away to transparent (using a cloud texture to sample) or swipe to transparent (using a linear ramp texture to sample), to achieve the effect, when drawing the enemy sprite, you need access and to not only the enemy sprite, but the reference sprite as well, which is normal when dealing with masking effects.
So my thought was, since you can’t pass in a custom sampler image (binding another image to texture slot 1 or 2), another option would be since the texture is already bound, all I would need is the texture coordinates if the sampler sprite is part of the same sprite sheet. lol ya, I would never make the user manually input the rectangle that’s why I was wondering if it was possible to aquire a predetermined rectangle of another sprite on the sheet so the user doesn’t have to. Another option would be to use the reference location by sampling the sprites neighbor by using vTex.x + uvWidth and have the reference the same size as the sampled sprite. But again, don’t want to do that because I don’t want a bunch things a user has to think about when using an effect.
It’s not super important, was just curious if there was a something in place that I could grab the reference rectangle from. Otherwise i won’t add it since it’s not really essential and I’ll just start working on the next effect/addon. Thanks Ashley
I don't think it's possible to work out the correct texture co-ordinates to use from GLSL alone. Construct doesn't currently support using additional textures as inputs to shaders. Currently the workaround is to use a sprite positioned exactly on top of another one, and implement the shader as a background-blending effect, combining the foreground and background shaders. It's a bit of a hack but it does work, it's how the normal mapping shader works.
Definitely understandable and ya, it does work well. If I find a way in the future that doesn’t require additional I’ll add it in but we will see. I’ll just move on to the next effect then. Thanks for your time
My other hack to get at another texture for an effect was to make the sprite 2x wide, put the second texture into the right half of the sprite and then have the effect combine the textures as needed in the left half and render the right half as transparent, regardless of its content. I _think_ this has similar performance as rendering one sprite, then overlaying with another and rendering again as Ashley suggests (which we do for the normal map effects now.) I know there's also the possibility of discarding the fragment for the right half, but I have seen mixed comments on how performant that is. It also is less dynamic, in terms of your need to pre-bake the other texture in and you would need to do that for each frame of animation.
The other hack I used, was putting a second texture depth data into the alpha channel, but that only works if the actual sprite does not need alpha, and also I have a sneaking suspicion it has some other side effects, even if the shader zeros out the alpha on the output color. It's also a pain to get a 'clean' insertion of data only into the alpha channel with Gimp, Photoshop, etc. without affecting the RGB components.
I've also made the request to add more texture sources for effects/sprites, but so far no response.
This is the effect that used the 2x sprite hack:
Thanks for the info. Ya I’ll end up figuring some way to do it somewhere down the road. Just keeping it easy for users might be a bit a tricky, but should be doable