Recently I was playing with different effect created with fragment shaders and encountered a problem I think should be quite trivial to solve, but I still wasn't able to find the right solution.
My effects render a transformed texture, but read not only the texel at UV passed from vertex shader, but also also its neighbours (like i.e. a blur shader). The problem is that the input texture is not sampled whole, but I only read a part of it, so my quad geometry used to render this texture is set to render a given region (like with textures created from texture atlases or SubTextures). Now, I want to clamp my texture reads to only the region set in my geometry. This cannot be done automatically (using tex
param clamp
), so I need to manually clamp my UVs to the desired region. To do this, I need minU, maxU, minV and maxV, obviously.
And here's the real problem: How do I do it? 🙂 Right now, I pass this four values to the fragment shader using fragment shader constants (I calculate the values in AS3 and pass them as a 4-value Vector.<Number>). This is OK, but if I'd like to batch more than one geometries (using the same program and sharing the same texture, but displaying different regions of the texture atlas or parent texture), then I'd have to pass these values along with the geometry, not as fragment shader constants, because there can only be one set of such constants per draw call and every subtexture drawn needs a different set of min/max values.
I managed to find this example: http://wonderfl.net/c/isXYI of drawing a wireframe, which (I guess) also needs to know the same information, but I have still wasn't able to find out how it's done. Can anybody help me with doing this using Starling?