gpt4 book ai didi

opengl - GLSL:删除死代码会导致视觉错误

转载 作者:行者123 更新时间:2023-12-01 15:20:09 24 4
gpt4 key购买 nike

尝试在 opengl 着色器中编写光线跟踪器时,我遇到了很多奇怪的问题。我试图确定错误的来源是否是我自己,通常情况是这样,但我得出的结论是,其中一些问题可能只是我的图形驱动程序中的错误(我在 ATI 上)。在这些情况下,我刚刚实现了变通办法。

但我刚遇到一些我不确定如何解决的问题(至少没有真正奇怪的代码),事实上我无法将我的一些数据从统一数组切换到纹理缓冲区,因为那一刻我删除了对统一数组的引用(它不再做任何事情;我已经删除了数据的任何实际使用),我的着色器看起来像这样:

https://dl.dropboxusercontent.com/u/39921754/bug_pic_0.png

为此:

https://dl.dropboxusercontent.com/u/39921754/bug_pic_1.png

请注意,移动相机也会导致您看到的内容发生不规律的变化。

这是我为获得这些结果而改变的方法:(有问题的行已被注释掉,它们访问统一数组 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com