我最近切换到Visual2015,.fx文件已经贬值。我的项目包含了用于着色器的.fx文件,所以我一直在切换。
只有在切换期间,我才更改为使用延迟渲染照明。
到目前为止,我做过的唯一一个着色器是第二遍使用的像素着色器,用于计算每个像素x的着色器,对它们进行求和,并输出最终颜色。
然而,每当我编译(我实际上不是在运行时使用着色器,我只是得到它的所有设置,窗口仍然只是被清除成一个颜色每帧,没有实际渲染),我得到一个失败,说…
错误X4502:阴影模型ps_4_0_level_9_3不允许读取位置语义。
这是我在这个项目中唯一造成这个错误的着色器。
我省略了getGBufferAttributes和calculateLighting方法,因为我知道它们不是问题所在。
Texture2D NormalTexture : register(t0);
Texture2D DiffuseAlbedoTexture : register(t1);
Texture2D SpecularAlbedoTexture : register(t2);
Texture2D PositionTexture : register(t3);
cbuffer LightParams
{
float3 LightPos;
float3 LightColor;
float3 LightDirection;
float2 SpotlightAngles;
float4 LightRange;
};
cbuffer CameraParams
{
float3 CameraPos;
};
float4 main(in float4 screenPos : SV_Position) : SV_Target0
{
float3 normal;
float3 position;
float3 diffuseAlbedo;
float3 specularAlbedo;
float specularPower;
getGBufferAttributes(screenPos.xy, normal, position, diffuseAlbedo, specularAlbedo, specularPower);
float3 lighting = calculateLighting(normal, position, diffuseAlbedo, specularAlbedo, specularPower);
return float4(lighting, 1.0f);
}此着色器使用的代码是基于本书中用作延迟呈现示例的代码,由Jason、Matt和Jack使用Direct3D 11进行实际渲染。
我不明白为什么他们会给出不起作用的源代码。它与Visual 2015中的新编译器和运行时有关吗?
另外,由于我将从以前只使用效果到现在的原始HLSL着色器,有什么我应该知道的东西可能会绊倒像我这样的人吗?
发布于 2016-02-20 20:40:35
一个非常新手的错误,我是用旧的HLSL编译器编译的。但是为什么这是默认的呢?很奇怪。
对于任何想知道的人,只需右键单击解决方案资源管理器中的HLSL文件,转到属性-> HLSL编译器-> General,并将Shader模型切换到您想要的模型,这是我的最新版本(5.0)。
https://computergraphics.stackexchange.com/questions/2077
复制相似问题