GeeXLab
Current version: 0.17.x
»GeeXLab homepage

FurMark
Current version: 1.19.1
»FurMark homepage
»FurMark 1.9.x Submissions

GPU Caps Viewer
Current version: 1.37.0.0
»GPU Caps Viewer homepage
»GPU DB Submissions

GPU Shark
Current version: 0.10.0.4
»GPU Shark homepage


Blogs
»JeGX's HackLab

Geeks3D's Articles
»GPU Memory Speed Demystified

»Multi-Threading Programming Resources

»GeForce and Radeon OpenCL Overview

»How to Get your Multi-core CPU Busy at 100%

»How To Make a VGA Dummy Plug

»Night Vision Post Processing Filter


PhysX FluidMark
Current version: 1.5.2
»FluidMark homepage
»FluidMark 1.4.x Submissions

TessMark
Current version: 0.3.0
»TessMark homepage

ShaderToyMark
Current version: 0.3.0
»ShaderToyMark homepage
»ShaderToyMark Scores

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

3D Graphics Search Engine:

The Geeks Of 3D

 
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





GeeXLab demos


GLSL - Mesh exploder


PhysX 3 cloth demo


Normal visualizer with GS


Compute Shaders test on Radeon


Raymarching in GLSL



Geeks3D latest news


Geeks3D forum news


Misc
»Texture DataPack #1
»Asus Silent Knight CPU Cooler
Page generated in 0.010749101638794 seconds.