gpt4 book ai didi

opengl - 从噪声纹理推导出不确定性值?

转载 作者:行者123 更新时间:2023-12-01 05:13:40 25 4
gpt4 key购买 nike

我正在尝试实现 Sketchy Drawings .我参与了该过程的一部分,该过程要求使用噪声纹理来推导不确定性值,该值将为边缘图提供偏移量。

这是我的环面边缘图的图片:

enter image description here

这是我按照建议使用 Perlin 函数得到的噪声纹理:

enter image description here

我将这些保存为纹理 edgeTexturenoiseTexture分别。

现在我被困在您必须通过从噪声纹理得出的不确定性值来偏移边缘图的纹理坐标的部分。这张图来自书中:

enter image description here

offs = turbulence(s, t); 
offt = turbulence(1 - s, 1 - t);

我暂时忽略了 2x2 矩阵。这是我当前的片段着色器尝试及其产生的结果:
#version 330

out vec4 vFragColor;

uniform sampler2D edgeTexture;
uniform sampler2D noiseTexture;

smooth in vec2 vTexCoords;

float turbulence(float s, float t)
{
float sum = 0;
float scale = 1;
float s1 = 1;
vec2 coords = vec2(s,t);

for (int i=0; i < 10; i++)
{
vec4 noise = texture(noiseTexture, 0.25 * s1 * coords);
sum += scale * noise.x;
scale = scale / 2;
s1 = s1 * 2;
}

return sum;
}

void main( void )
{
float off_s = turbulence(vTexCoords.s, vTexCoords.t);
float off_t = turbulence(1 - vTexCoords.s, 1 - vTexCoords.t);

vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t));
}

enter image description here

显然我对 vTexCoords 的补充很远,但我不明白为什么。我已经尝试了其他几个湍流函数定义,但没有一个接近所需的输出,所以我认为我的整体方法在某处存在缺陷。非常感谢这里的任何帮助,如果我不清楚,请发表评论。环面所需的输出看起来就像我想象的粗略绘制的圆圈。

最佳答案

您的湍流函数将返回 (0,1) 范围内的值。首先,您需要更改它以获得以 0 为中心的值。这应该在函数的循环内完成,否则您最终会得到一个奇怪的分布。所以首先,我认为你应该改变这一行:

vec4 noise = texture(noiseTexture, 0.25 * s1 * coords);


vec4 noise = texture(noiseTexture, 0.25 * s1 * coords) * 2.0 - 1.0;

然后,您需要缩放偏移量,以便您不会对离正在绘制的片段太远的边缘纹理进行采样。改变:
vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t));


vFragColor = texture(edgeTexture, vTexCoords + vec2(off_s, off_t) * off_scale);

哪里 off_scale是通过实验选择的一些小值(可能约为 0.05)。

关于opengl - 从噪声纹理推导出不确定性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597785/

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