[gameprogrammer] Re: Repeating part of a texture in GL
- From: Sami Näätänen <sn.ml@xxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Mon, 13 Nov 2006 13:21:35 +0200
On Saturday 11 November 2006 20:11, Scott Harper wrote:
> On Nov 2, 2006, at 11:54 AM, Sami Näätänen wrote:
> > On Wednesday 01 November 2006 00:47, Alan Wolfe wrote:
> >> heya
> >>
> >> If i have a texture loaded into memory that has alot of various
> >> tiles on it, how would i go about texturing one of those tiles
> >> onto a quad and having the texture repeat.
> >>
> >> I know i could do it by just making a bunch of quads, or by making
> >> the tile i want into it's own texture and using texture
> >> coordinates to make it repeat but is there any other way thats
> >> just quick and easy?
> >
> > I think only way is to use fragment shaders.
>
> Y'know, when I first read that, I thought to myself "what?? why go
> that far?" But now, having seen/read the rest of your message I
> realize I'm saying to myself instead "I KNEW there was a reason I
> liked fragment shaders aside from specular-maps and normal-maps
> etc...!" This is ridiculously amazing to me. Thank you very much
> for renewing my interest in GLSL and shaders. ^_^ I gotta go buy a
> book on this stuff! ^_^
Books are good in that sense that they will give you all the facts.
But shaders are still so new that there is huge possibilities to
discover. It is more like geting a hint of an idea and developing that
further in your mind. When one thinks it will be possible and useful
one can simply try to make the proof of concept version like I did.
> --Scott
>
> > Fragment shader:
> >
> > uniform vec2 MapPosition; // upper left corner map position
> > uniform vec2 MapSize; // Map size
> > uniform vec2 TileGrid; // How many tiles the Tiles texture has
> >
> > uniform sampler2D Map; // Tile map with 2 components (Red &
> > Alpha) uniform sampler2D Tiles; // Tiles side by side
> >
> > void
> > main() {
> > vec2 frag_pos = vec2( gl_TexCoord[0].st + MapPosition );
> > vec2 map_pos = vec2( floor( frag_pos ) / MapSize );
> >
> > frag_pos = fract(frag_pos) / TileGrid;
> > frag_pos += texture2D( Map, map_pos ).ra;
> >
> > gl_FragColor = texture2D( Tiles, frag_pos );
> > }
> >
> >
> > PS. This is in no way complete rendering system description, but
> > more like a proof of concept. One would extend this by computing
> > the areas that this pixel occupies and then blend these colors
> > accordingly. This is needed, because one pixel can be part of up to
> > four tiles. This kind of renderer will produce good looking free
> > zooming without any
> > visible tile borders.
> >
> > PS. PS. But all of that is left as an exercise. :)
>
> PS: Fun!
Indeed!
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] Re: Repeating part of a texture in GL
- From: Sami Näätänen
- [gameprogrammer] Re: Repeating part of a texture in GL
- From: Scott Harper
Other related posts:
- » [gameprogrammer] Repeating part of a texture in GL
- » [gameprogrammer] Re: Repeating part of a texture in GL
- » [gameprogrammer] Re: Repeating part of a texture in GL
- » [gameprogrammer] Re: Repeating part of a texture in GL
- [gameprogrammer] Re: Repeating part of a texture in GL
- From: Sami Näätänen
- [gameprogrammer] Re: Repeating part of a texture in GL
- From: Scott Harper