HLSL tex2D() - 梯度从何而来?
当我在像素着色器中对纹理进行采样时,纹理单元需要根据被着色的像素周围的纹理梯度来选择 mipmap。
有一个函数 tex2Dgrad() 允许我手动提供有关渐变的信息,而 tex2Dlod() 允许我手动选择 mipmap 但如果我只调用tex2D() 那么额外的梯度信息从何而来呢?
tex2D() 是纹理映射最常见的情况,在大多数着色器中使用,但我不知道渐变来自哪里。 Mipmapping 显然有效,所以它一定来自某个地方。
我想使用计算的 U
和 V
坐标在像素着色器中使用纹理作为查找表,但我不想要任何意外的'magic'tex2D()中。
我是否需要使用 tex2Dlod() 来避免这种情况?我读到 tex2Dlod()
比 tex2D()
慢。
When I sample a texture in a pixel shader the texture unit needs to select a mipmap based on the texture gradient around the pixel being shaded.
There's a function tex2Dgrad()
which allows me to supply info about the gradient manually and tex2Dlod()
which allows me to select a mipmap manually but if I just call tex2D()
then where does the extra gradient information come from?
tex2D()
is the most common case for texture mapping, used in most shaders, but I have no idea where the gradient comes from. Mipmapping obviously works so it must come from somewhere.
I want to use a texture as a lookup table in a pixel shader using calculated U
and V
coordinates but I don't want any unexpected 'magic' happening in tex2D()
.
Do I need to use tex2Dlod()
to avoid this? I read that tex2Dlod()
is slower then tex2D()
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GPU 一次对 4 个像素的“四边形”进行着色,用于纹理提取的梯度来自根据相邻像素对计算的有限差分。这就是 GPU 能够为像素着色器中的任意表达式生成偏导数的方式。如果您可以为作为纹理坐标传入的值计算更准确的解析导数,则 tex2Dgrad 函数会很有用。
GPUs shade a 'quad' of 4 pixels at a time and the gradients used for texture fetches come from the finite differences calculated from adjacent pairs of pixels. This is how the GPU is able to generate partial derivatives even for arbitrary expressions in the pixel shader. The tex2Dgrad function can be useful if you can calculate more accurate analytical derivatives for the values you are passing in as texture coordinates.