My Account


RSS
oZone3D.Net RSS Feeds»RSS 2.0 Feeds

Blogs
»The Geeks Of 3D
»Demoniak3D Blog
»JeGX's Infamous Lab

Sponsors

Modul8: real time video mixing and compositing


Link to Us

oZone3D.Net 100% Realtime 3D

»All Links

Search
Google
Web
oZone3D.Net

Web Partners

www.benchmarkhq.ru
www.tdt3d.com
www.steph3d.net
www.g-truc.net
www.worldpcspecs.com


Banners Exchange

cgindia.blogspot.com
grapejuice.c.la
www.game-lab.com
www.cooki3d.org


Links Exchange

»CYGAD's 3DXtra
 
The Art of Texturing Using The OpenGL Shading Language

By Jerome Guinot aka 'JeGX' - jegx [at] ozone3d (dot) net

Initial draft: April 15, 2006


[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Conclusion

»Next Page



7 - Texture Rectangles

Texture rectangles are a particular type of 2D texture. They use non-normalized texture coordinates and support NPOTD (Non-Power Of Two Dimensions) images. At the fixed functions level, texture rectangles seem to be supported by nVidia and ATI but at the GLSL level, only nVidia supports them.

In OpenGL, texture rectangles use the same functions as normal 2D textures but the texture target is GL_TEXTURE_RECTANGLE_NV, or GL_TEXTURE_RECTANGLE_ARB instead of GL_TEXTURE_2D.

With regular 2D textures, texture coordinates are normalized - i.e they are in the range [0.0 - 1.0]. With texture rectangles, the coordinates vary from 0.0 to texture_width for the s coordinate and from 0.0 to texture_height for t. Then take care to correctly initialize your texture coordinates before doing a texture fetching: a multiplication by texture_width for s and by texture_height for t should be enough.

At the GLSL level, we access to texture rectangles using the samplerRect sampler and the textureRect() function. The sampler2DRect sampler as well as the texture2DRect() function are also accepted.

The following image, from the DEMO_Texture_Rectangle.xml demo, shows the rendering of a 480x640 image using a texture rectangle:


Texture Rectangle
Fig. 21 - the DEMO_Texture_Rectangle.xml demo

And here is the demo's shader:

[Vertex_Shader]
		
uniform vec2 tex_dims;

void main()
{	
	gl_TexCoord[0] = gl_MultiTexCoord0 * vec4(tex_dims, 1.0, 1.0);
	gl_Position = ftransform();		
}
[Pixel_Shader]

uniform samplerRect colorMap;

void main (void)
{
	gl_FragColor = textureRect( colorMap, gl_TexCoord[0].st);
}

The tex_dims variable contains the dimensions of the texture and the first instruction of the vertex shader allows to unnormalize the texture coordinates. The rest of the shader (including the pixel shader) is now well known!

A the time of writing, this shader works on Geforce FX, 6xxx et 7xxx based graphics boards only.

On nVidia boards, texture rectangles are the only way to access to floating point textures required in GPGPU applications (see for example the project on fractals rendering: Mandelbrot project ).





[ Index ]

Introduction | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Page 7 | Page 8 | Conclusion

»Next Page







Language:


Demoniak3D
Current Version: 1.23.0
»Demoniak3D
»Download
»Libraries and Plugins
»Demos
»Online Help - Reference Guide
»Codes Samples


GPU Caps Viewer
Current Version: 1.4.2
»GPU Caps Viewer
»GPU DB Submissions


FurMark
Current Version: 1.3.0
»FurMark
»Benchmark Submissions
Page generated in 0.070825815200806 seconds.