Я работаю уже несколько дней над DirectX 11 версией набора Мандельброта. Что я сделал до сих пор, так это создал четырехугольник с текстурой на нем. Я могу раскрасить точки с помощью пиксельного шейдера, но по какой-то причине набор Мандельброта в пиксельном шейдере не возвращает ожидаемого результата. Я проверил логику в простом коде C++ и получил тот же ошибочный результат. Есть идеи, что не так с кодом? У меня есть правильная версия, работающая на Python, и я просто воспроизвел код, но, похоже, чего-то не хватает.
Ширина набора 2,5 (немного растянет изображение). Предполагается окно 1024*960 и макс. итерация 1000. Я скомпилировал Shader Model 5.0. Он начинается с набора по умолчанию с
RealStart = -2.0;
ImagStart = -1.25;
Проходит через буфер констант
cbuffer cBuffer
{
double RealStart; 'equals -2.5 from the default view of the set
double ImagStart; 'equals -1.25 from the default view of the set
};
// Pixel Shader
float4 main(float4 position : SV_POSITION) : SV_TARGET
{
double real, imag;
double real2, imag2;
int ite = 0;
float4 CalcColor = { 1.0f , 1.0f, 1.0f, 1.0f };
'position is the position of the pixel from 1.0f to 0.0f
real = RealStart + (double) position.x / 1024 * 2.5;
imag = ImagStart + (double) position.y / 960 * 2.5;
for (int i = 0; i < 1000; i++)
{
'breaking down the complex number by its constituents
real2 = real * real;
imag2 = imag * imag;
if (real2 + imag2 > 4.0)
{
break;
}
else {
imag = 2 * real * imag + ImagStart;
real = real2 - imag2 + RealStart;
ite++;
}
}
CalcColor[0] = (float) (ite % 333) / 333 ;
CalcColor[1] = (float) (ite % 666) / 666 ;
CalcColor[2] = (float) (ite % 1000) / 1000;
return CalcColor;
}
Изменить версию Python
def Mandelbrot(creal, cimag, maxNumberOfIterations):
real = creal
imag = cimag
for numberOfIterations in range(maxNumberOfIterations):
real2 = real * real
imag2 = imag * imag
if real2 + imag2 > 4.0:
return numberOfIterations
imag = 2 * real * imag + cimag
real = real2 - imag2 + creal
return maxNumberOfIterations
Creal, cimag и создаются таким образом, а затем просто зацикливаются.
realAxis = np.linspace(realStart, realStart + width, dim)
imagAxis = np.linspace(imagStart, imagStart + width, dim)
Он возвращает maxNumberOfIterations в двумерный массив, который предназначен для рисования множества Мандельброта.