我需要调试一个GLSL程序,但我不知道如何输出中间结果.是否可以使用GLSL制作一些调试跟踪(如printf)?
这个主题不时出现在SO上,但通常是因为写得不好的问题而被删除.我看到很多这样的问题,然后在请求附加信息时从OP(通常的低代表)中沉默.如果输入对我来说足够好,我决定回答一个问题,它通常会在活动时每天获得一些投票,但几周之后问题就会被删除/删除,并且所有问题都从一开始就开始.所以我决定写这个Q&A所以我可以直接引用这些问题,而不会一遍又一遍地重写答案......
另一个原因也是这个META线程针对我,所以如果你有额外的输入随意评论.
如何使用C++将位图图像转换为ASCII艺术?
一些限制:
这是一个相关的Wiki页面ASCII艺术(感谢@RogerRowland)
在过去的几天里,我一直试图让Three.js纹理化.我遇到的问题是我的浏览器阻止纹理加载,这是通过遵循这里的说明解决的.
无论如何,我正在为我的一个班级制作一个太空导航游戏,演示如何在太空中航行太空船.所以,我渲染了一堆行星,地球就是其中之一.我在下面列出了我的地球渲染图片.它看起来没问题,但我想做的是通过在地球周围添加"氛围"使其看起来更逼真.
我环顾四周,并且发现了一些看起来非常整洁的创意来处理发光,但我不认为它们适用于我的情况.
这里的代码将地球添加到我的场景中(这是我从Three.js教程获得的代码的修改版本):
function addEarth(x,y){
var sphereMaterial =
new THREE.MeshLambertMaterial({
//color: 0x0000ff,
map: earthTexture
});
// set up the sphere vars
var radius = 75;
segments = 16;
rings = 16;
// create a new mesh with
// sphere geometry - we will cover
// the sphereMaterial next!
earth = new THREE.Mesh(
new THREE.SphereGeometry(
radius,
segments,
rings),
sphereMaterial);
earth.position.x = x;
earth.position.y = y;
// add the sphere to the scene
scene.add(earth);
}
Run Code Online (Sandbox Code Playgroud)

给定一个潜在的巨大整数值(采用C#字符串格式),我希望能够生成其十六进制等效值.普通方法在这里不适用,因为我们正在谈论任意大数,50位或更多.我见过的技术使用了这样的技术:
// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString("X");
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
Run Code Online (Sandbox Code Playgroud)
将无法工作,因为要转换的整数太大.
例如,我需要能够像这样转换字符串:
843370923007003347112437570992242323
到十六进制当量.
这些不起作用:
我有一个被调用的变量,average在我的 中DATASEG,它每次都会改变,因为用户每次输入不同的输入。我想要做的是转到图形模式(VGA),然后在那里打印您的平均值是:然后平均值我知道如何更改为这样的图形模式:
mov ax, 13h
int 10h
Run Code Online (Sandbox Code Playgroud)
打印平均值后,如果平均值高于 75,我想打印在下面你是个好学生,继续努力,如果不是。别担心,你会好起来的!提前致谢。
我正在考虑floor可用的功能math.h.它很容易使用:
#include <stdio.h>
#include <math.h>
int main(void)
{
for (double a = 12.5; a < 13.4; a += 0.1)
printf("floor of %.1lf is %.1lf\n", a, floor(a));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我想编写自己的实现怎么办?看起来像这样:
#include <stdio.h>
#include <math.h>
double my_floor(double num)
{
return (int)num;
}
int main(void)
{
double a;
for (a = 12.5; a < 13.4; a += 0.1)
printf("floor of %.1lf is %.1lf\n", a, floor(a));
printf("\n\n");
for (a = 12.5; a < 13.4; a += 0.1)
printf("floor of …Run Code Online (Sandbox Code Playgroud) 如何调试OpenGL着色器?例如.:
void main(void)
{
vec2 uv = gl_FragCoord.xy;
gl_FragColor = vec4(uv,222,1);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法让我知道紫外线的价值是多少?
我正在使用 GLSL 计算着色器编写基于 GPU 的实时光线跟踪渲染器。到目前为止,它运行得非常好,但是当涉及同时具有反射和折射时,我偶然发现了一个看似无法解决的问题。
我的逻辑告诉我,为了在物体(例如玻璃)上进行反射和折射,光线必须一分为二,一条光线从表面反射,另一条光线通过表面折射。这些光线的最终颜色将根据某个函数进行组合,并最终用作光线源自的像素的颜色。我的问题是我不能在着色器代码中分割光线,因为我必须使用递归来做到这一点。根据我的理解,着色器中的函数不能递归,因为由于与旧 GPU 硬件的兼容性问题,所有 GLSL 函数都类似于 C++ 中的内联函数。
是否可以在着色器代码中模拟或伪造递归,或者我什至可以在不使用递归的情况下同时实现反射和折射?我看不出没有递归它是如何发生的,但我可能是错的。
我正在尝试在 GLSL 中实现模拟双精度,并且观察到一种奇怪的行为差异,导致 GLSL 中出现细微的浮点错误。
考虑以下片段着色器,写入 4 浮点纹理以打印输出。
layout (location = 0) out vec4 Output
uniform float s;
void main()
{
float a = 0.1f;
float b = s;
const float split = 8193.0; // = 2^13 + 1
float ca = split * a;
float cb = split * b;
float v1a = ca - (ca - a);
float v1b = cb - (cb - b);
Output = vec4(a,b,v1a,v1b);
}
Run Code Online (Sandbox Code Playgroud)
这是我观察到的输出
统一的 GLSL 输出:
a = 0.1 0x3dcccccd
b …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)