我正在使用 GLSL 计算着色器编写基于 GPU 的实时光线跟踪渲染器。到目前为止,它运行得非常好,但是当涉及同时具有反射和折射时,我偶然发现了一个看似无法解决的问题。
我的逻辑告诉我,为了在物体(例如玻璃)上进行反射和折射,光线必须一分为二,一条光线从表面反射,另一条光线通过表面折射。这些光线的最终颜色将根据某个函数进行组合,并最终用作光线源自的像素的颜色。我的问题是我不能在着色器代码中分割光线,因为我必须使用递归来做到这一点。根据我的理解,着色器中的函数不能递归,因为由于与旧 GPU 硬件的兼容性问题,所有 GLSL 函数都类似于 C++ 中的内联函数。
是否可以在着色器代码中模拟或伪造递归,或者我什至可以在不使用递归的情况下同时实现反射和折射?我看不出没有递归它是如何发生的,但我可能是错的。
我有一个java项目谁制作了"windows'迷宫"并使用光线投射算法.这是一个截图:
就像你可以看到所有的墙都有相同的高度.我想做同样的事,但身高不同
private void castRay(int xOnScreen,double angle,double direction) {
R rx = castRayInX(angle,direction);
R ry = castRayInY(angle,direction);
// In case of out-of-space rays
if (rx.getDistance()==Double.MAX_VALUE && ry.getDistance()==Double.MAX_VALUE) {
graphics.setColor(BACKGROUND);
graphics.drawLine(xOnScreen,0,xOnScreen,this.image.getHeight());
return;
}
double distance = rx.getDistance();
double normal = rx.getNormal();
Color c = rx.getColor();
double coef = Math.cos((angle+direction+Math.PI)-normal);
Plot collision = rx.getPlot();
if (ry.getDistance()<rx.getDistance()) {
distance = ry.getDistance();
normal = ry.getNormal();
c = ry.getColor();
coef = Math.cos((angle+direction+Math.PI)-normal);
collision = ry.getPlot();
}
coef = Math.abs(coef);
int factor = map.length*SQUARE_SIZE;
double d …Run Code Online (Sandbox Code Playgroud) 我是OpenGl的专家,因此,我正在尝试仅学习4.x的现代OpenGl。一旦完成了基础教程(例如旋转多维数据集),我就决定尝试创建一个仅处理多维数据集的基于体素的程序。该程序的目标是快速,使用有限的CPU能力和内存以及动态的,因此映射大小可以更改,并且只有在数组中表示已填充块时才绘制块。
我有一个VBO,它具有由三角形构成的多维数据集的顶点和索引。首先,如果我告诉renderGl着色器使用render函数,然后在完成后绑定VBO,则执行此循环
绘制立方体循环:
//The letter_max are the dimensions of the matrix created to store the voxel status in
// The method I use for getting and setting entries in the map are very efficient so I have not included it in this example
for(int z = -(z_max / 2); z < z_max - (z_max / 2); z++)
{
for(int y = -(y_max / 2); y < y_max - (y_max / 2); y++)
{
for(int x = -(x_max / 2); x …Run Code Online (Sandbox Code Playgroud) opengl ×2
c ×1
c++ ×1
glsl ×1
graphics ×1
java ×1
math ×1
opengl-4 ×1
optimization ×1
performance ×1
raycasting ×1
raytracing ×1
recursion ×1