简体   繁体   中英

What is texture coordinate P in texture sampler2d lookup GLSL

I've been looking through the OpenGLSL ES 3.0 Spec , but I can't find anything on how the built in function, texture(sampler, p) defines P. I know it is a vec2 .

Is it a normalized floating point between 0.0 and 1.0 defining a scaler from top left to button right?

Or is it a texel look up from 0 to dimension size minus 1 like the texelFetch() function?

Or is it even more complicated and be defined in the texture properties somehow? Here It states "Texture coordinates may be normalized or in texel space." But I am skeptical as I don't see any place to set a texture to normallized.

As you already noted, the texelFetch() family of functions access a specific texel by the actual integer texel coordinates the image data is specified in.

In contrast, the mapping between the texture coordinates used for the texture() familiy of GLSL functions and the actual texel coordinates is a bit more complex.

First, texture coordinates are defined as floating point, and conceptually, sampling textures represents evaluating a continuous 1-,2- or 3D- function, not accessing a discrete array. The filter modes of course define which values you get when sampling inbetween the data points provided in the texture itself. You should be aware that the first difference is that sampling a texture does in the general case not imply that a single texel is addressed, but multiple texels are used, and the filter mode (as well as further circumstances like the screen space derivatives of the tex coords) defines which texels have to be feteched during the operatin.

The texcoords for "ordinary" 2D textures is defined such that (0,0) defines the bottom left corner of the bottom left texel, and (1,1) the top right corner of the top right pixel. Note that this definition implies that when you want to sample exactly at the texel center location for integer texel coordinates (i,j) with 0 <= i <= texWidth -1 and 0 <= j <= texHeight -1, you will have to use the texture coordinates ( (i+0.5)/texWidth, (j+0.5) / texHeight ).

If texture coordiantes outside the [0,1] range are specified, the texture's wrapping mode are used to determine how this is mapped to the range. You have basically the option to clamp them, or to repeat the texture (mirrored and not mirrored).

Or is it even more complicated and be defined in the texture properties somehow?

The filter and wrap modes are part of the sampler state. GLES 3 supports Sampler Objects , which allow you to specify the sampler state independent of the texture object. In traditional GL, texture objects do contain the sampler state. Sampler Objects allow you to optionally override that state.

Here It states "Texture coordinates may be normalized or in texel space." But I am skeptical as I don't see any place to set a texture to normallized.

Well, this refers to desktop GL, not GLES 3. The link you gave actually explains this right after the paraghaph you qouted from. Rectangle textures use a mapping where [0,width) x [0,height) represents the whole image in texture coordinates, not the normalized [0,1] range. But in ES3, rectangle textures are not supported, so that is irrelevant here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM