CG: Adjusting a UV-scalar for FOV


Nevermind; I’ve decided that I’m not happy with the effect that this shader is producing, and am experimenting with a different direction. My thanks for any time given to this, however!


I’m currently working on a pencil shader. The shader isn’t a post-process applied to a buffer texture (unlike my previous experiment with this), but rather is applied to the intended geometry. The “shading lines” come from a single large texture, with UV-coordinates based on the fragment’s screen-position (calculated from the vertex position using the model-view matrix, I believe it is), like so:

        float z = l_screenVtxPos.z;
        l_screenVtxPos.z = 0;
        float scalar = 1.2/z;
        float2 uv = float2(l_screenVtxPos.x*scalar, l_screenVtxPos.y*scalar);

All of this works well enough–for a given field of view. Unfortunately, it doesn’t take into account changes in field-of-view, and as a result altering the field-of-view produces an apparent “scaling” of the “shading” image, which makes the effect inconsistent.

I’ve spent some time trying to figure out how to adjust the scaling of the UV-coordinates to account for this–I’ve tried simple scalings by FOV/(some reference FOV), or the inverse; I’ve tried multiplying by the chord- or arc- length associated with the FOV angle (admittedly assuming a radius of one); I think that I’ve even tried bringing the z-value from the code above into the calculation–in short, I’ve tried several things, and variations of those things. Alas, thus far I’ve had little success, and I’m stuck.

Does anyone know how I might adjust my UV-coordinates to account for changes in field-of-view?