OpenGL 批处理渲染器中的纹理渗色/损坏
Textures Bleeding / Corruption in OpenGL Batch Renderer
正在使用 C++ 开发引擎并基于 Cherno's video series 实现了批处理渲染器。这似乎工作了一段时间。最近注意到,在处理该项目的两台计算机中的一台上,精灵的一个纹理奇怪地渗入另一个纹理。
经过一些研究,我们特别注意到,出血是根据渲染顺序发生的。第一个渲染的精灵没有问题,后面的精灵大部分是正确的,一小部分像素来自最后一个绘制的精灵的纹理。
我们认为问题与着色器有关,但也有可能是批处理渲染器出了问题。
顶点着色器
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec4 aColor;
layout (location = 2) in vec2 aTexCoord;
layout (location = 3) in int aTexIndex;
out vec4 ourColor;
out vec2 TexCoord;
flat out int TexIndex;
uniform mat4 uViewProjection;
void main()
{
gl_Position = uViewProjection * vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = aTexCoord;
TexIndex = aTexIndex;
}
片段着色器
#version 330 core
out vec4 FragColor;
in vec4 ourColor;
in vec2 TexCoord;
flat in int TexIndex;
uniform sampler2D ourTextures[32];
void main()
{
FragColor = texture(ourTextures[TexIndex], TexCoord) * ourColor;
}
批量Renderer.h
#pragma once
#include "glm/glm.hpp"
#include "Shader.h"
#include "Memory/SmartPointers.h"
namespace Engine::Graphics
{
// TODO: move this struct to a different header.
struct Vertex
{
glm::vec3 pos;
glm::vec4 col;
glm::vec2 texCoords;
i32 texIndex;
};
struct BatchData
{
GLuint VAO = 0;
GLuint VB = 0;
GLuint IB = 0;
uint32_t indexCount = 0;
Vertex* vertexBuffer = nullptr;
Vertex* vertexBufferCurrentOffset = nullptr;
GLint* textureSlotsArray = nullptr;
i32 textureSlotIndex = 0;
glm::mat4x4 currentViewMatrix = glm::mat4x4();
};
class BatchRenderer
{
public:
void Init(SharedRef<Shader>& startShader);
void Destroy();
GLuint GetVAOID();
static uint32_t GetMaxBatchSize();
static uint32_t GetNoTexID();
static uint32_t GetQuadsDrawnThisFrame();
static uint32_t GetDrawCallsThisFrame();
static void ResetQuadCounter();
static void ResetDrawCallCounter();
void BeginBatch();
void EndBatch();
void Flush();
void SetShader(SharedRef<Shader>& shaderPassed);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, const glm::vec4& colour);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID, const glm::vec4& colour);
void UpdateViewMatrix(const glm::mat4x4& newMatrix);
SharedRef<Shader> shaderRef;
BatchData m_batchData;
friend class BatchManager;
};
}
批处理Renderer.cpp - 重要功能,如有任何遗漏,请随时提出。
void BatchRenderer::Init(SharedRef<Shader>& startShader)
{
#ifdef _DEBUG
assert(m_batchData.vertexBuffer == nullptr && "Batch Renderer already initialized.");
#endif
shaderRef = startShader;
shaderRef->Bind();
GLint maxTextures;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextures);
MAX_TEXTURES_PER_BATCH = maxTextures;
if (MAX_TEXTURES_PER_BATCH > 32)
{
MAX_TEXTURES_PER_BATCH = 32;
}
m_batchData.vertexBuffer = new Vertex[MAX_VERT_COUNT_PER_BATCH];
glGenVertexArrays(1, &m_batchData.VAO);
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
glGenBuffers(1, &m_batchData.VB);
glBindBuffer(GL_ARRAY_BUFFER, m_batchData.VB);
glBufferData(GL_ARRAY_BUFFER, MAX_VERT_COUNT_PER_BATCH * sizeof(Vertex), nullptr, GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(0 * sizeof(float)));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(7 * sizeof(float)));
glEnableVertexAttribArray(2);
//glVertexAttribPointer(3, 1, GL_UNSIGNED, GL_FALSE, sizeof(Vertex), (void*)(9 * sizeof(float)));
glVertexAttribIPointer(3, 1, GL_INT, sizeof(Vertex), (void*)(9 * sizeof(float)));
glEnableVertexAttribArray(3);
uint32_t* indices = new uint32_t[MAX_INDEX_COUNT_PER_BATCH];
uint32_t offset = 0;
for (size_t i = 0; i < MAX_INDEX_COUNT_PER_BATCH; i += 6)
{
indices[i] = 0 + offset;
indices[i + 1] = 1 + offset;
indices[i + 2] = 2 + offset;
indices[i + 3] = 2 + offset;
indices[i + 4] = 3 + offset;
indices[i + 5] = 0 + offset;
offset += 4;
}
glGenBuffers(1, &m_batchData.IB);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_batchData.IB);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_INDEX_COUNT_PER_BATCH * sizeof(uint32_t), indices, GL_STATIC_DRAW);
delete[] indices;
m_batchData.textureSlotsArray = new GLsizei[MAX_TEXTURES_PER_BATCH];
m_batchData.textureSlotsArray[0] = noTexID;
GLint* samplers = new int32_t[MAX_TEXTURES_PER_BATCH];
samplers[0] = 0;
for (GLint i = 1; i < MAX_TEXTURES_PER_BATCH; i++)
{
m_batchData.textureSlotsArray[i] = 0; //zero out data
samplers[i] = i;
}
glUniform1iv(shaderRef->GetUniformIndex("ourTextures"), static_cast<int>(MAX_TEXTURES_PER_BATCH), samplers);
}
void BatchRenderer::Destroy()
{
#ifdef _DEBUG
assert(m_batchData.vertexBuffer != nullptr && "Batch Renderer not initialized, cannot destroy.");
#endif
glDeleteVertexArrays(1, &m_batchData.VAO);
glDeleteBuffers(1, &m_batchData.VB);
glDeleteBuffers(1, &m_batchData.IB);
delete[] m_batchData.vertexBuffer;
delete[] m_batchData.textureSlotsArray;
}
void BatchRenderer::BeginBatch()
{
m_batchData.vertexBufferCurrentOffset = m_batchData.vertexBuffer;
}
void BatchRenderer::EndBatch()
{
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
GLsizeiptr totalSize = (uint8_t*)m_batchData.vertexBufferCurrentOffset - (uint8_t*)m_batchData.vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, m_batchData.VB);
glBufferSubData(GL_ARRAY_BUFFER, 0, totalSize, m_batchData.vertexBuffer);
}
void BatchRenderer::Flush()
{
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
shaderRef->SetMat4x4("uViewProjection", m_batchData.currentViewMatrix);
for (i32 i = 0; i < m_batchData.textureSlotIndex; i++)
{
glBindTextureUnit(i, m_batchData.textureSlotsArray[i]);
}
glDrawElements(GL_TRIANGLES, m_batchData.indexCount, GL_UNSIGNED_INT, nullptr);
m_batchData.indexCount = 0;
m_batchData.textureSlotIndex = 1;
#ifdef EDITOR
drawCallsThisFrame++;
#endif
}
void BatchRenderer::DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID, const glm::vec4& colour)
{
if (m_batchData.indexCount > QUICK_LOWER_INDEX_ACCESS || m_batchData.textureSlotIndex >= MAX_TEXTURES_PER_BATCH)
{
EndBatch();
Flush();
BeginBatch();
}
i32 textureIndex = -1;
for (i32 i = 0; i < m_batchData.textureSlotIndex; i++)
{
if (m_batchData.textureSlotsArray[i] == textureID)
{
textureIndex = i;
break;
}
}
if (textureIndex == -1)
{
textureIndex = m_batchData.textureSlotIndex;
m_batchData.textureSlotsArray[m_batchData.textureSlotIndex] = static_cast<i32>(textureID);
m_batchData.textureSlotIndex++;
}
m_batchData.vertexBufferCurrentOffset->pos = { position1.x, position1.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 0.0f, 0.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position2.x, position2.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 1.0f, 0.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position3.x, position3.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 1.0f, 1.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position4.x, position4.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 0.0f, 1.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.indexCount += 6;
#ifdef EDITOR
quadCountThisFrame++;
#endif
}
如上所述,如果该信息有用,则该错误仅出现在处理该项目的 2 台 PC 中的 1 台上(AMD RX 580 存在错误)。
ourTextures[TexIndex]
是未定义的行为,因为ourTextures
是采样器数组,而 TexIndex
是片段着色器输入。片段着色器输入不是 Dynamically uniform expression.
请参阅您使用的 GLSL 版本 3.30(来自 OpenGL Shading Language 3.30 Specification - 4.1.7 Samplers):
Samplers aggregated into arrays
within a shader (using square brackets [ ]) can only be indexed with integral constant expressions
查看 GLSL 版本 4.60(最新)(来自 OpenGL Shading Language 4.60 Specification - 4.1.7. Opaque Types):
(此规则适用于 GLSL 4.00 之后的所有版本)
When aggregated into arrays within a shader, these types can only be indexed with a dynamically uniform expression, or texture lookup will result in undefined values.
因此,无论是在您使用的 GLSL 版本中,还是在最新版本中,采样器数组都不能通过顶点着色器输入(属性)进行索引。
从 GLSL 4.00 开始,可以通过统一索引采样器数组,因为通过统一变量索引是 dynamically uniform expression.
我建议使用 s sampler2DArray
(参见 Sampler)而不是 sampler2D
.
的数组
当您使用 sampler2DArray
时,您根本不需要任何索引,因为 "index" 在纹理查找时被编码在纹理坐标的第三个分量中(参见 Texture
)。
正在使用 C++ 开发引擎并基于 Cherno's video series 实现了批处理渲染器。这似乎工作了一段时间。最近注意到,在处理该项目的两台计算机中的一台上,精灵的一个纹理奇怪地渗入另一个纹理。
经过一些研究,我们特别注意到,出血是根据渲染顺序发生的。第一个渲染的精灵没有问题,后面的精灵大部分是正确的,一小部分像素来自最后一个绘制的精灵的纹理。
我们认为问题与着色器有关,但也有可能是批处理渲染器出了问题。
顶点着色器
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec4 aColor;
layout (location = 2) in vec2 aTexCoord;
layout (location = 3) in int aTexIndex;
out vec4 ourColor;
out vec2 TexCoord;
flat out int TexIndex;
uniform mat4 uViewProjection;
void main()
{
gl_Position = uViewProjection * vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = aTexCoord;
TexIndex = aTexIndex;
}
片段着色器
#version 330 core
out vec4 FragColor;
in vec4 ourColor;
in vec2 TexCoord;
flat in int TexIndex;
uniform sampler2D ourTextures[32];
void main()
{
FragColor = texture(ourTextures[TexIndex], TexCoord) * ourColor;
}
批量Renderer.h
#pragma once
#include "glm/glm.hpp"
#include "Shader.h"
#include "Memory/SmartPointers.h"
namespace Engine::Graphics
{
// TODO: move this struct to a different header.
struct Vertex
{
glm::vec3 pos;
glm::vec4 col;
glm::vec2 texCoords;
i32 texIndex;
};
struct BatchData
{
GLuint VAO = 0;
GLuint VB = 0;
GLuint IB = 0;
uint32_t indexCount = 0;
Vertex* vertexBuffer = nullptr;
Vertex* vertexBufferCurrentOffset = nullptr;
GLint* textureSlotsArray = nullptr;
i32 textureSlotIndex = 0;
glm::mat4x4 currentViewMatrix = glm::mat4x4();
};
class BatchRenderer
{
public:
void Init(SharedRef<Shader>& startShader);
void Destroy();
GLuint GetVAOID();
static uint32_t GetMaxBatchSize();
static uint32_t GetNoTexID();
static uint32_t GetQuadsDrawnThisFrame();
static uint32_t GetDrawCallsThisFrame();
static void ResetQuadCounter();
static void ResetDrawCallCounter();
void BeginBatch();
void EndBatch();
void Flush();
void SetShader(SharedRef<Shader>& shaderPassed);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, const glm::vec4& colour);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID);
void DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID, const glm::vec4& colour);
void UpdateViewMatrix(const glm::mat4x4& newMatrix);
SharedRef<Shader> shaderRef;
BatchData m_batchData;
friend class BatchManager;
};
}
批处理Renderer.cpp - 重要功能,如有任何遗漏,请随时提出。
void BatchRenderer::Init(SharedRef<Shader>& startShader)
{
#ifdef _DEBUG
assert(m_batchData.vertexBuffer == nullptr && "Batch Renderer already initialized.");
#endif
shaderRef = startShader;
shaderRef->Bind();
GLint maxTextures;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextures);
MAX_TEXTURES_PER_BATCH = maxTextures;
if (MAX_TEXTURES_PER_BATCH > 32)
{
MAX_TEXTURES_PER_BATCH = 32;
}
m_batchData.vertexBuffer = new Vertex[MAX_VERT_COUNT_PER_BATCH];
glGenVertexArrays(1, &m_batchData.VAO);
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
glGenBuffers(1, &m_batchData.VB);
glBindBuffer(GL_ARRAY_BUFFER, m_batchData.VB);
glBufferData(GL_ARRAY_BUFFER, MAX_VERT_COUNT_PER_BATCH * sizeof(Vertex), nullptr, GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(0 * sizeof(float)));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(7 * sizeof(float)));
glEnableVertexAttribArray(2);
//glVertexAttribPointer(3, 1, GL_UNSIGNED, GL_FALSE, sizeof(Vertex), (void*)(9 * sizeof(float)));
glVertexAttribIPointer(3, 1, GL_INT, sizeof(Vertex), (void*)(9 * sizeof(float)));
glEnableVertexAttribArray(3);
uint32_t* indices = new uint32_t[MAX_INDEX_COUNT_PER_BATCH];
uint32_t offset = 0;
for (size_t i = 0; i < MAX_INDEX_COUNT_PER_BATCH; i += 6)
{
indices[i] = 0 + offset;
indices[i + 1] = 1 + offset;
indices[i + 2] = 2 + offset;
indices[i + 3] = 2 + offset;
indices[i + 4] = 3 + offset;
indices[i + 5] = 0 + offset;
offset += 4;
}
glGenBuffers(1, &m_batchData.IB);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_batchData.IB);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_INDEX_COUNT_PER_BATCH * sizeof(uint32_t), indices, GL_STATIC_DRAW);
delete[] indices;
m_batchData.textureSlotsArray = new GLsizei[MAX_TEXTURES_PER_BATCH];
m_batchData.textureSlotsArray[0] = noTexID;
GLint* samplers = new int32_t[MAX_TEXTURES_PER_BATCH];
samplers[0] = 0;
for (GLint i = 1; i < MAX_TEXTURES_PER_BATCH; i++)
{
m_batchData.textureSlotsArray[i] = 0; //zero out data
samplers[i] = i;
}
glUniform1iv(shaderRef->GetUniformIndex("ourTextures"), static_cast<int>(MAX_TEXTURES_PER_BATCH), samplers);
}
void BatchRenderer::Destroy()
{
#ifdef _DEBUG
assert(m_batchData.vertexBuffer != nullptr && "Batch Renderer not initialized, cannot destroy.");
#endif
glDeleteVertexArrays(1, &m_batchData.VAO);
glDeleteBuffers(1, &m_batchData.VB);
glDeleteBuffers(1, &m_batchData.IB);
delete[] m_batchData.vertexBuffer;
delete[] m_batchData.textureSlotsArray;
}
void BatchRenderer::BeginBatch()
{
m_batchData.vertexBufferCurrentOffset = m_batchData.vertexBuffer;
}
void BatchRenderer::EndBatch()
{
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
GLsizeiptr totalSize = (uint8_t*)m_batchData.vertexBufferCurrentOffset - (uint8_t*)m_batchData.vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, m_batchData.VB);
glBufferSubData(GL_ARRAY_BUFFER, 0, totalSize, m_batchData.vertexBuffer);
}
void BatchRenderer::Flush()
{
glBindVertexArray(m_batchData.VAO);
shaderRef->Bind();
shaderRef->SetMat4x4("uViewProjection", m_batchData.currentViewMatrix);
for (i32 i = 0; i < m_batchData.textureSlotIndex; i++)
{
glBindTextureUnit(i, m_batchData.textureSlotsArray[i]);
}
glDrawElements(GL_TRIANGLES, m_batchData.indexCount, GL_UNSIGNED_INT, nullptr);
m_batchData.indexCount = 0;
m_batchData.textureSlotIndex = 1;
#ifdef EDITOR
drawCallsThisFrame++;
#endif
}
void BatchRenderer::DrawQuad(const glm::vec2& position1, const glm::vec2& position2, const glm::vec2& position3, const glm::vec2& position4, uint32_t textureID, const glm::vec4& colour)
{
if (m_batchData.indexCount > QUICK_LOWER_INDEX_ACCESS || m_batchData.textureSlotIndex >= MAX_TEXTURES_PER_BATCH)
{
EndBatch();
Flush();
BeginBatch();
}
i32 textureIndex = -1;
for (i32 i = 0; i < m_batchData.textureSlotIndex; i++)
{
if (m_batchData.textureSlotsArray[i] == textureID)
{
textureIndex = i;
break;
}
}
if (textureIndex == -1)
{
textureIndex = m_batchData.textureSlotIndex;
m_batchData.textureSlotsArray[m_batchData.textureSlotIndex] = static_cast<i32>(textureID);
m_batchData.textureSlotIndex++;
}
m_batchData.vertexBufferCurrentOffset->pos = { position1.x, position1.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 0.0f, 0.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position2.x, position2.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 1.0f, 0.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position3.x, position3.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 1.0f, 1.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.vertexBufferCurrentOffset->pos = { position4.x, position4.y, 0.0f };
m_batchData.vertexBufferCurrentOffset->col = colour;
m_batchData.vertexBufferCurrentOffset->texCoords = { 0.0f, 1.0f };
m_batchData.vertexBufferCurrentOffset->texIndex = textureIndex;
m_batchData.vertexBufferCurrentOffset++;
m_batchData.indexCount += 6;
#ifdef EDITOR
quadCountThisFrame++;
#endif
}
如上所述,如果该信息有用,则该错误仅出现在处理该项目的 2 台 PC 中的 1 台上(AMD RX 580 存在错误)。
ourTextures[TexIndex]
是未定义的行为,因为ourTextures
是采样器数组,而 TexIndex
是片段着色器输入。片段着色器输入不是 Dynamically uniform expression.
请参阅您使用的 GLSL 版本 3.30(来自 OpenGL Shading Language 3.30 Specification - 4.1.7 Samplers):
Samplers aggregated into arrays within a shader (using square brackets [ ]) can only be indexed with integral constant expressions
查看 GLSL 版本 4.60(最新)(来自 OpenGL Shading Language 4.60 Specification - 4.1.7. Opaque Types):
(此规则适用于 GLSL 4.00 之后的所有版本)
When aggregated into arrays within a shader, these types can only be indexed with a dynamically uniform expression, or texture lookup will result in undefined values.
因此,无论是在您使用的 GLSL 版本中,还是在最新版本中,采样器数组都不能通过顶点着色器输入(属性)进行索引。
从 GLSL 4.00 开始,可以通过统一索引采样器数组,因为通过统一变量索引是 dynamically uniform expression.
我建议使用 s sampler2DArray
(参见 Sampler)而不是 sampler2D
.
的数组
当您使用 sampler2DArray
时,您根本不需要任何索引,因为 "index" 在纹理查找时被编码在纹理坐标的第三个分量中(参见 Texture
)。