我正在使用VS 2019社区,并将DirectX SDK作为标准VS安装的一部分提供。
着色器源:
cbuffer Params : register(b1)
{
float4 param1;
float4 param2;
float4 frameNum; // Not used in this shader
float4 depthBias; // Not used in this shader
};
cbuffer Gradients : register(b2)
{
float2 gradients[160];
};
Texture2D srcTexture : register(t0); // Not used in this shader
SamplerState linearSampler : register(s0); // Not used in this shader
struct PS_INPUT
{
float4 position : SV_POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1; // Not used in this shader
};
float dotGridGradient(int i, float x, float y)
{
return gradients[i].x * x + gradients[i].y * y;
}
float4 PLASmain(PS_INPUT IN) : SV_Target
{
// Perlin noise plasma generator from https://en.wikipedia.org/wiki/Perlin_noise#Implementation
float x = saturate(IN.texcoord0.x) * 15.999;
float y = saturate(IN.texcoord0.y) * 8.999;
int xi = floor(x);
int yi = floor(y);
x -= xi;
y -= yi;
int i = yi * 16 + xi;
float g0 = dotGridGradient(i, x, y);
float g1 = dotGridGradient(i + 1, x, y);
float g2 = dotGridGradient(i + 16, x, y);
float g3 = dotGridGradient(i + 17, x, y);
float l0 = lerp(g0, g1, x);
float l1 = lerp(g2, g3, x);
float l2 = lerp(l0, l1, y) / 2 + 0.5;
float4 result = lerp(param1, param2, l2);
return result;
}
使用着色器模型设置为4_0
进行编译时,命令行选项如下:
/E"PLASmain" /Vn"plasmaShader" /ps"_4_0" /Fh"...\plasmaShaderRelease.hxx" /nologo
这样编译就可以了,并生成了一个可工作的着色器。但是,如果我将着色器模型更改为4_0 level 9_3
,则命令行选项将切换为:
/E"PLASmain" /Vn"plasmaShader" /ps"_4_0_level_9_3" /Fh"...\plasmaShaderRelease.hxx" /nologo
并且输出生成以下错误:
1>...\Shaders\plasmaShader.psh(34,15): error X5589: Invalid const register num: 162. Max allowed is 31.
1>...\Shaders\plasmaShader.psh(27,12-23): error X4505: maximum temp register index exceeded
1>...\Shaders\plasmaShader.psh(27,12-23): error X4505: maximum temp register index exceeded
1>...\Shaders\plasmaShader.psh(27,33-44): error X4505: maximum temp register index exceeded
1>...\Shaders\plasmaShader.psh(27,33-44): error X4505: maximum temp register index exceeded
X4505
错误重复了300多次。