Let me break it down even further, because there may be a simple solution I
haven't thought of.

I want to texture a group of sprites that have different rotation values.
Instead of texturing them so that each sprite has a separate image input,
I'm using a shader like this:

uniform sampler2D texture;
uniform vec2 resolution;
void main()
{
vec2 position = (-( gl_FragCoord.xy / resolution.x ) * 1.0) ;

//Multiply color by texture
gl_FragColor = gl_Color * texture2D(texture, position);
}


This will keep the texture rectified to the screen, while the geometry
moves every which way.

But, I'd like to be able to place this in a 3D transform and have the
texture appear to get smaller when moving back in Z, and perhaps translate
x/y/z as well, while having the texture appear to be parallel to screen no
matter what the rotation value (or perhaps controlled by virtual cam value).

Messing with the gl texture matrix/sprite with image input was a bit of a
sidetrack from my original thought, and won't work in tandem with this
fragment shader. I was at least endeavoring to get the texture rotation
worked out, and interfacing with the current matrix values obtained from
inside 3D transform/trackball. My code for the matrix mult is essentially
the same as the kineme gl matrix mult, but invoking it on the texture
matrix instead.

On Thu, Aug 16, 2012 at 1:13 PM, George Toledo <[email protected]> wrote:

> Here's a picture to illustrate what I'm talking about.
>
> I just tried moving the rotation point out to z~1.7 through 1.735 ish
> (where I vaguely remember the eye origin being). It didn't seem to make a
> difference in correcting the texture.
>
> So, I'm rotating the sprite 30 degrees X rotation using a 3D transform.
> I'm "getting" that matrix inside of the transform. Then, I'm inverting it,
> but...I'm applying those modelview matrix values to the texture matrix.
> This results in the incorrect output.
>
> If I'm rotating the sprite at 0,0,0, and I'm correcting the texture from
> there too (though I did try moving the virtual rotation matrix point out,
> as previously stated).
>
> On Thu, Aug 16, 2012 at 1:01 PM, George Toledo <[email protected]> wrote:
>
>>
>>
>> On Thu, Aug 16, 2012 at 12:32 PM, Christopher Wright <
>> [email protected]> wrote:
>>
>>> > Is there math that can be done to offset "rotate" the texture
>>> correctly?
>>> >
>>> > I think if I could find some decent example code for affine tiling, I
>>> could figure out how to do what I wish to, but google has been lacking in
>>> results so far.
>>>
>>> it's general matrix math.  Rotations take place about the origin;
>>>  therefore, to rotate about an arbitrary point in 2-space (or axis in
>>> 3-space, or plane in 4-space) you simply translate by the difference,
>>> rotate, and then re-transform (to "put it back").  so you'll have a
>>> translation matrix, a rotation matrix, and a third translation matrix.
>>>  Multiply them all together, and you should be good to go.  Order of
>>> multiplications matters (it's non-commutative, unlike scalar
>>> multiplication), so do some experiments to find the right order (it's
>>> "backwards" iirc, but I could be forgetting/over-simplifying)
>>>
>>>
>> I'm sure I'm not comprehending something here.
>>
>> So, what if there is no "difference" and the rotation is around origin?
>> There would be no translation matrix needed, it would "just work"? What I'm
>> finding is that Z rotation works fine, but Y and X "stretch"/"pinch" out
>> funny. Or is it that the Z value of the texture matrix the same as the clip
>> point of projection space, and if I translate by that, it would look
>> right(?).
>>
>>
>>
>>
>>
>>>
>>> > Thanks,
>>> > George Toledo
>>> > _______________________________________________
>>> > Do not post admin requests to the list. They will be ignored.
>>> > Quartzcomposer-dev mailing list      (
>>> [email protected])
>>> > Help/Unsubscribe/Update your Subscription:
>>> >
>>> https://lists.apple.com/mailman/options/quartzcomposer-dev/christopher_wright%40apple.com
>>> >
>>> > This email sent to [email protected]
>>>
>>> --
>>> Christopher Wright
>>> [email protected]
>>>
>>>
>>>
>>>
>>
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to