“我的&perd”噪声效果着色器产生全白或全黑
我正在尝试在NVidia FX Composer中编写一个“perlin”噪声着色器。但是,无论我如何调整噪音功能,它都会返回100%白色或100%黑色。我不知道如何解决这个问题,甚至问题是什么。
编辑:如果你看过这个页面,你可能知道我在哪里得到代码。想象一下,我开始使用一种我已经在CPU上工作的方法。
请帮忙。
float Noise1(int x, int y)
{
int n = x + y * 57;
// int n = x + y * 1376312627;
// n = n * n;
// n = (int)pow(n * pow(2, 13), n);
// return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) + 0x7fffffff) / 1073741824.0);
// return abs( ( (n * (n * n * 15731 + 789221) + 1376312589) + 0x7fffffff) / 2147483647.0);
// return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) + 0x7fffffff) / 2147483647.0);
// return ( n / 2147483647.0);
return ( ((float)n) / 500.0 );
// return n = 2147483647.0;
}
float SmoothNoise_1(int x, int y)
{
float corners = ( Noise1(x-1, y-1) + Noise1(x+1, y-1) + Noise1(x-1, y+1) + Noise1(x+1, y+1) ) / 16.0;
float sides = ( Noise1(x-1, y) + Noise1(x+1, y) + Noise1(x, y-1) + Noise1(x, y+1) ) / 8.0;
float center = Noise1(x, y) / 4.0;
return corners + sides + center;
}
float Cosine_Interpolate(float a, float b, float x)
{
float ft = x * 3.1415927;
float f = (1 - cos(ft)) * 0.5;
return a*(1-f) + b*f;
}
float InterpolatedNoise_1(float x, float y)
{
int integer_X = (int)x;
float fractional_X = x - integer_X;
int integer_Y = (int)y;
float fractional_Y = y - integer_Y;
float v1 = SmoothNoise_1(integer_X, integer_Y);
float v2 = SmoothNoise_1(integer_X + 1, integer_Y);
float v3 = SmoothNoise_1(integer_X, integer_Y + 1);
float v4 = SmoothNoise_1(integer_X + 1, integer_Y + 1);
float i1 = Cosine_Interpolate(v1 , v2 , fractional_X);
float i2 = Cosine_Interpolate(v3 , v4 , fractional_X);
return Cosine_Interpolate(i1 , i2 , fractional_Y);
}
int width = 512;
int height = 512;
float4 PerlinNoise_2D(float2 xy : TEXCOORD0) : COLOR0
{
float4 total = 0;
// int p = persistence;
float p = 1.0;
// int n = Number_Of_Octaves - 1;
int n = 2;
for(int i = 0; i < n; ++i)
{
float frequency = pow(2, i);
float amplitude = pow(p, i);
/* total.a = InterpolatedNoise_1(xy.x * width * frequency, xy.y * height * frequency) * amplitude;
total.r = InterpolatedNoise_1(xy.x * width * frequency, xy.y * height * frequency) * amplitude;
total.g = InterpolatedNoise_1(xy.x * width * frequency, xy.y * height * frequency) * amplitude;
total.b = InterpolatedNoise_1(xy.x * width * frequency, xy.y * height * frequency) * amplitude; */
/* total.a = InterpolatedNoise_1(xy.x * frequency, xy.y * frequency) * amplitude;
total.r = InterpolatedNoise_1(xy.x * frequency, xy.y * frequency) * amplitude;
total.g = InterpolatedNoise_1(xy.x * frequency, xy.y * frequency) * amplitude;
total.b = InterpolatedNoise_1(xy.x * frequency, xy.y * frequency) * amplitude; */
total.a = InterpolatedNoise_1(xy.x * width, xy.y * height);
total.r = InterpolatedNoise_1(xy.x * width, xy.y * height);
total.g = InterpolatedNoise_1(xy.x * width, xy.y * height);
total.b = InterpolatedNoise_1(xy.x * width, xy.y * height);
}
return clamp(total, 0.0, 1.0);
// return (float)(int)(2147483647 + 2147483647 + 2147483647 / 2) / 2147483647.0;
}
technique Perlin
{
pass p0
{
VertexShader = null;
PixelShader = compile ps_3_0 PerlinNoise_2D();
}
}
谢谢。
没有找到相关结果
已邀请:
1 个回复
奥李