- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我第一次尝试将 bool 值传递到我的顶点着色器中;到目前为止我只使用过 float 。
所讨论的 bool 值是特定于原语的,因此不能作为统一传递。然而,对于任何给定图元的所有顶点,它具有相同的值。
从 Khronos 规范看来,“variing”是将数据传递到片段着色器的唯一方法,但毫不奇怪地声明“variing bool my_bool;”在我的顶点着色器中定义时会导致解析器错误。
我将 bool 值传递到我的顶点着色器中:
attribute bool a_my_bool;
我定义了一个变量来尝试传递给片段着色器:
varying bool v_my_bool;
void main() {
// ...
v_my_bool = a_my_bool;
}
有人可以告诉我如何实现我的目的吗?
最佳答案
来自The OpenGL® ES Shading Language version 1.0.17 (PDF)的§4.3.5 :
The varying qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4, or arrays of these.
从§4.3.3开始:
The attribute qualifier can be used only with the data types float, vec2, vec3, vec4, mat2, mat3, and mat4. Attribute variables cannot be declared as arrays or structures.
因此,根据规范,您不能拥有attribute bool
,更不用说variing bool
了。
如果您确实需要每个顶点一个 bool 值,您可以使用 0.0 表示 false,使用 1.0 表示 true。测试时,检查 x > 0.5
。例如:
// vertex shader
attribute float a_my_bool;
varying float v_my_bool;
void main() {
// ...
v_my_bool = a_my_bool;
}
// fragment shader
varying float v_my_bool;
void main() {
if (v_my_bool > 0.5) {
// my_bool is true
// ...
} else {
// my_bool is false
// ...
}
}
只要每个三角形中的所有顶点都具有相同的值,就应该可以工作。如果它们不一致,那么同一个三角形的不同片段最终会表现不同。 (如果坚持使用 0.0 和 1.0,最接近“奇数”角的三角形的四分之一的行为将与其余部分不同。)
关于opengl-es - OpenGL ES (2.0) 着色语言 : How to input boolean into vertex shader and pass to fragment shader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8863196/
我在使用 dijkstra 时遇到了这个错误:TypeError:不可排序的类型:Vertex() dijkstra(g, g.get_vertex('a')) File "C:/Use
我对为自定义类实现迭代器感到困惑。我正在尝试为 std::set 实现一个迭代器,其中我的 Vertex 类声明为: class Vertex{
我正在尝试学习和实现有向图,但在执行程序时遇到了一些困难。 // ADD Function public boolean addVertex(Vertex v) { boolean added
我是 OpenGL 的初学者,我试图每 5 秒将大量“对象”从一个位置移动到另一个位置。如果我在顶点着色器中计算位置,fps 急剧下降,难道不应该在 GPU 上完成这些类型的计算吗? 这是顶点着色器代
我正在学习使用 Boost 图形库。我已经按照此处的说明定义了一个自定义结构来存储有关顶点的信息:Modifying vertex properties in a Boost::Graph . str
我正在尝试使用 boost::adjacency list 和捆绑属性创建一个 TreeMap 来存储每个顶点的父级,我想以一种它们不会失效的方式存储顶点描述符以防万一我删除了一个顶点,所以我使用了
要定义一个从 int 到 struct vertex 的映射,我应该定义 map[int]vertex 还是 map[int]*vertex?首选哪一个? 我扩展了 Chickencha 的代码: p
我创建了一个 VBO(顶点缓冲区对象)和 VAO(顶点数组对象)并执行了以下操作: glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo)
我用 HBase 设置了 Titan。 我删除图中的所有顶点 全部删除后显示为空。 gremlin> g.V.count() ==>0 但是如果我重新登录泰坦,那么图中会有一堆空顶点 gremlin>
我正在探索使用计算着色器将骨骼变形应用于网格顶点,而不是使用流输出的顶点着色器。我发现计算着色器的执行速度比顶点着色器慢得多,但在我把它写下来之前,我想确定我没有做错什么。 使用我的 100,000
这里我有一个有向图G,我需要判断是否存在一组顶点不相交的循环,以便每个顶点都属于一个循环。 我不确定这是否可以在多项式时间内完成或者它是否是 NP-Complete?谁能至少指出我正确的方向? 最佳答
要检测一个点是否在多边形中,您可以从该点到无穷远投影一条线,然后查看它与多少个多边形顶点相交......足够简单。我的问题是,如果射线在其中一个点上与多边形相交,则将其视为与两个线段相交,并被视为在多
我在 VehicleHistoryGraph 数据库中创建了一个 Message 类型的顶点,并向其中加载了 50,000 个该类型的顶点。 当我尝试使用此 SQL 语句一次删除所有顶点时 - DEL
所以我正在尝试将 Graph 类作为另一个项目的一部分。顶点存储在由 unordered_map 定义的邻接表中。我正在尝试创建一个散列函数以允许我的 Vertex 类存储在此 map 中,但我不知道
我正在尝试使用 Parma Polyhedra 库 [1]枚举(凸)多面体的顶点,例如,我有一个由四个约束指定的矩形: Constraint_System cs; cs.insert(x >= 0);
我开始了解 Visual Studio 2017 中的 OpenGL。按照 www.learnopengl.com 教程并通过了纹理检查点,转换是目前的主要问题。 我使用预先获取的统一位置 ID 将我
有一个预定的笔记本,它使用 BigQuery 客户端和具有所有者权限的服务帐户。当我手动运行单元格时,它会更新 BQ 表。 BQ 和 Vertex AI 都有一个项目。 我发现了一个类似的问题,但是
我在 R 中使用 Igraph 包,当我通过 V(graph) 访问顶点名称列表时,我得到以下结果: Vertex sequence: [1] "d66cp96igcdnt25brjeics9d11
我有一个 U-SQL 脚本,它在数据湖中存储的多个 JSON 文件上运行,当我针对单个文件运行该脚本时,一切正常,但是打开它以针对我的所有文件运行每次都会出现以下错误,并且作业永远不会超过“准备”阶段
我正在尝试实现 phong 阴影,但无济于事。我正在一点一点地构建着色器(这本身可能是一个问题),但这就是我目前所处的位置。我希望它将我的结果(犹他茶壶)输出为黑色背景上的白色图像。当我从顶点着色器中
我是一名优秀的程序员,十分优秀!