尝试编写以下递归调用时遇到此错误.我在GLSL中看到过很多关于递归Ray跟踪实现的演示,所以我假设GLSL支持递归.
这不是这种情况吗?
OpenGL返回编译时错误消息:
Error: Function trace(vec3, vec3, vec3, int) has static recursion
Run Code Online (Sandbox Code Playgroud)
这是我的函数定义:
vec3 trace(vec3 origin, vec3 direction, vec3 illum, int order)
{
float dist;
int s_index = getSphereIntersect(origin, direction, dist);
//if light hit
float light_dist = 200;
for(int k = 0; k < L_COUNT;k++)
if(s_intersects(l_center[k], l_radius[k],
origin, direction,
light_dist))
if(light_dist < dist )
return l_color[k]; //light is pure color
if (s_index != -1)
{
illum = s_color[s_index];
for(int j = 0; j < L_COUNT; j++)
{
float ambient = …Run Code Online (Sandbox Code Playgroud) 我遇到了一个似乎与平台相关的错误.我得到了clang ++和g ++的不同结果,但仅限于我的32-Debian Machine.我一直认为IEEE 754是标准化的,所有遵守标准的编译器都会有相同的行为.如果我错了,请告诉我,我对此非常困惑.另外,我意识到依赖浮点比较通常不是一个好主意.
#define DEBUG(line) std::cout <<"\t\t" << #line << " => " << line << "\n";
#include <iostream>
int main() {
double x = 128.0, y = 255.0;
std::cout << "\n";
DEBUG( x/y)
DEBUG( ((x/y) == 128.0/255.0))
DEBUG( (128.0/255.0) )
DEBUG( ((x/y)-(x/y)))
DEBUG( ((x/y)-(128.0/255.0)) )
DEBUG( ((128.0/255.0)-0.501961) )
std::cout << "\n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我的输出
[~/Desktop/tests]$ g++ float_compare.cc -o fc
[~/Desktop/tests]$./fc
x/y => 0.501961
((x/y) == 128.0/255.0) => 0
(128.0/255.0) => 0.501961
((x/y)-(x/y)) => 0
((x/y)-(128.0/255.0)) => …Run Code Online (Sandbox Code Playgroud)