我正在尝试使用 DirectX11 计算着色器进行分形渲染的一些实验。提供的示例在 FeatureLevel_10 设备上运行。
我的 RwStructured 输出缓冲区的数据格式为 R32G32B32A32_FLOAT
问题是,当写入缓冲区时,似乎只有 ALPHA ( w ) 值被写入其他内容......这是着色器代码:
struct BufType
{
float4 value;
};
cbuffer ScreenConstants : register(b0)
{
float2 ScreenDimensions;
float2 Padding;
};
RWStructuredBuffer<BufType> BufferOut : register(u0);
[numthreads(1, 1, 1)]
void Main( uint3 DTid : SV_DispatchThreadID )
{
uint index = DTid.y * ScreenDimensions.x + DTid.x;
float minRe = -2.0f;
float maxRe = 1.0f;
float minIm = -1.2;
float maxIm = minIm + ( maxRe - minRe ) * ScreenDimensions.y / ScreenDimensions.x;
float reFactor = (maxRe - minRe ) / (ScreenDimensions.x - 1.0f);
float imFactor = (maxIm - minIm ) / (ScreenDimensions.y - 1.0f);
float cim = maxIm - DTid.y * imFactor;
uint maxIterations = 30;
float cre = minRe + DTid.x * reFactor;
float zre = cre;
float zim = cim;
bool isInside = true;
uint iterationsRun = 0;
for( uint n = 0; n < maxIterations; ++n )
{
float zre2 = zre * zre;
float zim2 = zim * zim;
if ( zre2 + zim2 > 4.0f )
{
isInside = false;
iterationsRun = n;
}
zim = 2 * zre * zim + cim;
zre = zre2 - zim2 + cre;
}
if ( isInside )
{
BufferOut[index].value = float4(1.0f,0.0f,0.0f,1.0f);
}
}
该代码实际上在某种意义上产生了正确的结果(2D Mandelbrot 集),但它似乎以某种方式只触及了 alpha 值而没有写入任何其他内容,尽管集内的像素应该是红色的......(图像是黑色的&白色的 )
有人知道这里发生了什么吗?