查找由半径定义的磁盘内部的点
我遇到了一个我试图理解在半径定义的磁盘中找到点的着色器。
此函数diskpoint
如何工作?
float HASHVALUE = 0.0f;
vec2 RandomHashValue()
{
return fract(sin(vec2(HASHVALUE += 0.1, HASHVALUE += 0.1)) * vec2(43758.5453123, 22578.1459123));
}
vec2 DiskPoint(in float radius, in float x1, in float x2)
{
float P = radius * sqrt(1.0f - x1);
float theta = x2 * 2.0 * PI;
return vec2(P * cos(theta), P * sin(theta));
}
void main()
{
HASHVALUE = (uvCoords.x * uvCoords.y) * 64.0;
HASHVALUE += fract(time) * 64.0f;
for (int i = 0; i < samples; ++i)
{
vec2 hash = RandomHashValue();
vec2 disk = DiskPoint(sampleRadius, hash.x, hash.y);
//....
}
}
I have come across a shader that I am trying to understand where a point is found within a disk defined by a radius.
How does this function DiskPoint
work?
float HASHVALUE = 0.0f;
vec2 RandomHashValue()
{
return fract(sin(vec2(HASHVALUE += 0.1, HASHVALUE += 0.1)) * vec2(43758.5453123, 22578.1459123));
}
vec2 DiskPoint(in float radius, in float x1, in float x2)
{
float P = radius * sqrt(1.0f - x1);
float theta = x2 * 2.0 * PI;
return vec2(P * cos(theta), P * sin(theta));
}
void main()
{
HASHVALUE = (uvCoords.x * uvCoords.y) * 64.0;
HASHVALUE += fract(time) * 64.0f;
for (int i = 0; i < samples; ++i)
{
vec2 hash = RandomHashValue();
vec2 disk = DiskPoint(sampleRadius, hash.x, hash.y);
//....
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我这样认为:
但是我只是猜测了,没有测试过,所以请记住这一点
I see it like this:
but I just guessed and not tested it so take that in mind
根据 @spektre的建议,我在画布上提取了此功能的结果。
代码看起来像这样:
这是创建的模式:
它看起来都可以找到给定半径的圆圈中的每个(x1,x2)。
希望这会有所帮助!
Based on @Spektre´s suggestion I drew the outcome of this function on a Canvas.
the code looks like this:
This is the created Pattern:
It looks like it finds for every (x1,x2) a point in the circle of given radius.
Hope this will help!