小编138*_*138的帖子

禁止GLSL中的递归?

尝试编写以下递归调用时遇到此错误.我在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)

c++ opengl raytracing glsl

4
推荐指数
1
解决办法
3231
查看次数

浮点运算在g ++和clang ++之间有所不同吗?

我遇到了一个似乎与平台相关的错误.我得到了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)

c++ g++ clang ieee-754

1
推荐指数
1
解决办法
350
查看次数

标签 统计

c++ ×2

clang ×1

g++ ×1

glsl ×1

ieee-754 ×1

opengl ×1

raytracing ×1