- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试在 opengl 着色器中编写光线跟踪器时,我遇到了很多奇怪的问题。我试图确定错误的来源是否是我自己,通常情况是这样,但我得出的结论是,其中一些问题可能只是我的图形驱动程序中的错误(我在 ATI 上)。在这些情况下,我刚刚实现了变通办法。
但我刚遇到一些我不确定如何解决的问题(至少没有真正奇怪的代码),事实上我无法将我的一些数据从统一数组切换到纹理缓冲区,因为那一刻我删除了对统一数组的引用(它不再做任何事情;我已经删除了数据的任何实际使用),我的着色器看起来像这样:
为此:
请注意,移动相机也会导致您看到的内容发生不规律的变化。
这是我为获得这些结果而改变的方法:(有问题的行已被注释掉,它们访问统一数组 quad_vertex_indices)
bool Collide_KDTree(Ray ray, out Surface surface)
{
float t_entry, t_exit;
if(!RayBox(ray.tail, ray.head, scene_bounds.position, scene_bounds.extent, t_entry, t_exit))
return false;
uint node_indices[TREE_DEPTH];
float node_exits[TREE_DEPTH];
uint top= 0;
node_indices[top]= kd_nodes.length()- 1;
node_exits[top++]= t_exit;
while(top> 0)
{
uint node_index_foo= node_indices[top- 1];
KDNode node= kd_nodes[node_indices[top- 1]];
t_exit= node_exits[top- 1];
top--;
if(node.node_type== NodeType_Parent)
{
uint near_index, far_index;
if(ray.tail[node.split_axis] < node.split)
{
near_index= node.left_index_or_offset+ 1;
far_index= node.right_index_or_count+ 1;
}
else
{
near_index= node.right_index_or_count+ 1;
far_index= node.left_index_or_offset+ 1;
}
float t_intersection;
RayAxisAlignedPlane(ray.tail, ray.head, node.split_axis, node.split, t_intersection);
if(t_intersection> t_exit)
{
node_indices[top]= near_index;
node_exits[top++]= t_exit;
}
else if(t_intersection< t_entry)
{
if(t_intersection< 0)
{
node_indices[top]= near_index;
node_exits[top++]= t_exit;
}
else
{
node_indices[top]= far_index;
node_exits[top++]= t_exit;
}
}
else if(t_intersection> t_entry && t_intersection< t_exit)
{
if(t_intersection< 0)
{
node_indices[top]= near_index;
node_exits[top++]= t_exit;
}
else
{
node_indices[top]= far_index;
node_exits[top++]= t_exit;
node_indices[top]= near_index;
node_exits[top++]= t_intersection;
}
}
}
else
{
float shortest_distance= INFINITY;
bool collision_detected= false;
uint primitive_offset= node.left_index_or_offset;
uint primitive_count= node.right_index_or_count;
for(uint i= primitive_offset; i< (primitive_offset+ primitive_count); i++)
{
uint primitive_index= primitive_indices[i];
if(primitive_index< QUAD_COUNT)
{
uint quad_index= primitive_index;
vec3 intersection;
//uint foo0= quad_vertex_indices[quad_index* 4+ 0];
//uint foo1= quad_vertex_indices[quad_index* 4+ 1];
//uint foo2= quad_vertex_indices[quad_index* 4+ 2];
//uint foo3= quad_vertex_indices[quad_index* 4+ 3];
vec3 vertex0= vertices[texelFetch(test_texture_buffer, int(quad_index* 4+ 0)).r];
vec3 vertex1= vertices[texelFetch(test_texture_buffer, int(quad_index* 4+ 1)).r];
vec3 vertex2= vertices[texelFetch(test_texture_buffer, int(quad_index* 4+ 2)).r];
vec3 vertex3= vertices[texelFetch(test_texture_buffer, int(quad_index* 4+ 3)).r];
if(RayQuad(ray.tail, ray.head, vertex0, vertex1, vertex2, vertex3, quad_normals[quad_index], intersection))
{
float this_distance= distance(ray.tail, intersection);
if(this_distance< shortest_distance)
{
surface.position= intersection;
surface.normal= quad_normals[quad_index];
surface.material= materials[quad_material_indices[quad_index]];
shortest_distance= this_distance;
collision_detected= true;
}
}
}
else
{
uint sphere_index= primitive_index- QUAD_COUNT;
vec3 intersection;
if(RaySphere(ray.tail, ray.head, spheres[sphere_index].position, spheres[sphere_index].radius, intersection))
{
float this_distance= distance(ray.tail, intersection);
if(this_distance< shortest_distance)
{
surface.position= intersection;
surface.normal= normalize(intersection- spheres[sphere_index].position);
surface.material= materials[sphere_material_indices[sphere_index]];
shortest_distance= this_distance;
collision_detected= true;
}
}
}
}
if(collision_detected && (shortest_distance/ length(ray.head))< t_exit)
return true;
t_entry= t_exit;
}
}
return false;
在我看来,这只是一个编译器问题,但如果不是,那很好,因为这意味着我可以修复它。
有谁知道这可能是什么原因造成的,我的选择是什么?我有时间限制,所以我正在考虑做一个 hack 来让它工作(即只留下线路,或类似的东西)
最佳答案
恐怕它看起来确实很像着色器编译器错误。统一数组应该从着色器程序中优化(除非它在其他地方被引用),无论这些行是否被注释掉。
可能值得检查程序对象的制服(使用 glGetActiveUniform),无论是否注释这些行。
此外 - 尝试在不同的硬件上运行它。
关于opengl - GLSL:删除死代码会导致视觉错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16364582/
我有类似下面的代码: ... id: myComponent signal updateState() property variant modelList: [] Repeater { mo
我正在处理一些我无法展示的私有(private)代码,但我已经制作了一些示例代码来描述我的问题: 主.c: #include #include #include #include typede
这个问题在这里已经有了答案: 关闭10 年前。 Possible Duplicate: what are the differences in die() and exit() in PHP? 我想
在编写 Perl 模块时,在模块内部使用 croak/die 是一个好习惯吗? 毕竟,如果调用者不使用 eval block ,模块可能会使调用它的程序崩溃。 在这些情况下,最佳做法是什么? 最佳答案
我有一些搜索线程正在存储结果。我知道当线程启动时,JVM native 代码会代理在操作系统上创建新 native 线程的请求。这需要 JVM 之外的一些内存。当线程终止并且我保留对它的引用并将其用作
我刚刚花了很多时间调试一个我追溯到 wantarray() 的问题。 .我已将其提炼为这个测试用例。 (忽略 $! 在这种情况下不会有任何有用信息的事实)。我想知道为什么wantarray在第二个示例
我看到一些代码是这样做的: if(something){ echo 'exit from program'; die; } ...more code 和其他只使用 die 的人: if
我正在尝试将此表格用于: 如果任何 $_POST 变量等于任何其他 $_POST 变量抛出错误。 如果只有几个,那不是问题,但我有大约 20 个左右所以如果我想这样做,我将不得不像这样 但这
每次我运行: hadoop dfsadmin -report 我得到以下输出: Configured Capacity: 0 (0 KB) Present Capacity: 0 (0 KB) DFS
我是一名优秀的程序员,十分优秀!