Opengl GLSL:删除死代码会导致视觉错误
我在尝试在opengl着色器中编写光线跟踪器时遇到了很多奇怪的问题。我试图确定错误的来源是否是我自己,通常情况下是这样,但我得出的结论是,其中一些问题可能只是我的图形驱动程序中的错误(我使用ATI)。在这些情况下,我刚刚实现了变通方法 但我遇到了一些我不确定如何解决的问题(至少在没有真正奇怪的代码的情况下),我无法将我的一些数据从统一数组切换到纹理缓冲区,因为当我删除对统一数组的引用时(这不再起任何作用;我已经删除了数据的任何实际使用),我的着色器的外观如下所示: 为此: 请注意,移动摄影机也会导致所看到的内容发生不稳定的变化 以下是我正在改变的获得这些结果的方法:(有问题的线被注释掉了,它们访问统一数组quad_vertex_索引)Opengl GLSL:删除死代码会导致视觉错误,opengl,buffer,glsl,textures,dead-code,Opengl,Buffer,Glsl,Textures,Dead Code,我在尝试在opengl着色器中编写光线跟踪器时遇到了很多奇怪的问题。我试图确定错误的来源是否是我自己,通常情况下是这样,但我得出的结论是,其中一些问题可能只是我的图形驱动程序中的错误(我使用ATI)。在这些情况下,我刚刚实现了变通方法 但我遇到了一些我不确定如何解决的问题(至少在没有真正奇怪的代码的情况下),我无法将我的一些数据从统一数组切换到纹理缓冲区,因为当我删除对统一数组的引用时(这不再起任何作用;我已经删除了数据的任何实际使用),我的着色器的外观如下所示: 为此: 请注意,移动摄影机
bool Collide_KDTree(光线、外表面)
{
浮动t_入口,t_出口;
if(!RayBox(ray.tail、ray.head、scene_bounds.position、scene_bounds.extent、t_entry、t_exit))
返回false;
uint节点索引[树深度];
浮动节点_退出[树_深度];
uint-top=0;
node_index[top]=kd_nodes.length()-1;
节点_退出[top++]=t_退出;
而(顶部>0)
{
uint node_index_foo=node_index[top-1];
KDNode node=kd_nodes[node_index[top-1];
t_exit=节点_exit[top-1];
顶部--;
if(node.node\u type==NodeType\u父节点)
{
uint近U指数、远U指数;
if(光线尾[node.split\u轴]t_出口)
{
节点索引[顶部]=接近索引;
节点_退出[top++]=t_退出;
}
否则如果(t_交叉口t_入口和t_交叉口
}
在我看来,这只是一个编译器问题,但若不是,那个就太好了,因为这意味着I c
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;