简体   繁体   English

什么是纹理采样器2D查找GLSL中的纹理坐标P

[英]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 . 我一直在浏览OpenGLSL ES 3.0规范 ,但找不到关于内置函数texture(sampler, p)定义P的vec2 。我知道它是vec2

Is it a normalized floating point between 0.0 and 1.0 defining a scaler from top left to button right? 它是在0.0到1.0之间的标准化浮点,定义了从左上方到右按钮的缩放比例吗?

Or is it a texel look up from 0 to dimension size minus 1 like the texelFetch() function? 还是像texelFetch()函数一样,将texel从0查找到尺寸大小减去1?

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." 此处指出“纹理坐标可以被规范化或在texel空间中”。 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. 如前所述, texelFetch()系列函数通过指定图像数据的实际整数texel坐标来访问特定texel。

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. 相反,用于GLSL函数的texture()的纹理坐标与实际的texel坐标之间的映射要复杂一些。

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. 首先,将纹理坐标定义为浮点,并且从概念上讲,采样纹理表示评估连续的 1-,2-或3D函数,而不访问离散数组。 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. 您应该意识到,第一个区别是在通常情况下对纹理进行采样并不意味着要寻址单个纹理像素,而是要使用多个纹理像素,以及使用滤波模式(以及其他情况,例如tex坐标)定义在操作过程中必须对哪些texel进行特征处理。

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. 为“普通” 2D纹理的texcoords被限定为使得(0,0)限定了左下角纹理像素的左下角 ,和(1,1)的右上像素的右上角。 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 ). 请注意,此定义意味着当您要在整数texel坐标(i,j)的texel中心位置进行精确采样时,0 <= i <= texWidth -1和0 <= j <= texHeight -1使用纹理坐标((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. 如果指定了[0,1]范围之外的纹理坐标,则使用纹理的环绕模式来确定如何将其映射到该范围。 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. GLES 3支持Sampler Objects ,使您可以独立于纹理对象指定采样器状态。 In traditional GL, texture objects do contain the sampler state. 在传统的GL中,纹理对象确实包含采样器状态。 Sampler Objects allow you to optionally override that state. 采样器对象使您可以选择覆盖该状态。

Here It states "Texture coordinates may be normalized or in texel space." 此处指出“纹理坐标可以被规范化或在texel空间中”。 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. 好吧,这是指台式机GL,而不是GLES3。您给出的链接实际上是在您从中退出paraghaph之后对此进行解释的。 Rectangle textures use a mapping where [0,width) x [0,height) represents the whole image in texture coordinates, not the normalized [0,1] range. 矩形纹理使用一种映射,其中[0,width)x [0,height)以纹理坐标表示整个图像,而不是规范化的[0,1]范围。 But in ES3, rectangle textures are not supported, so that is irrelevant here. 但是在ES3中,不支持矩形纹理,因此此处无关紧要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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