0
与.cpp文件和.h文件一样,我希望使用Shader代码中的一些函数来创建文件。如何在.hlsl文件中包含文件?
下面假设这个代码是在light.hlsl文件
struct DirectionalLight
{
float4 Ambient;
float4 Diffuse;
float4 Specular;
float3 Direction;
float pad;
};
// some structures...
................
.............
void ComputePointLight(Material mat, PointLight L, float3 pos, float3 normal, float3 toEye,
out float4 ambient, out float4 diffuse, out float4 spec)
{
//define fucntion that i need....
}
define other functions..
void ComputeSpotLight(Material mat, SpotLight L, float3 pos, float3 normal, float3 toEye,
out float4 ambient, out float4 diffuse, out float4 spec)
{
}
,然后我创建PixelShader.hlsl文件,该文件是这样的
#include"light.hlsl"
float4 main(Pin pin):SV_TARGET
{
do something with functions in light.hlsl file.....
}
我只是不想复制并粘贴此代码到我所有的hlsl代码..如果我必须更改我的光功能代码,那么我应该更改每个hlsl代码,这不是我想要的。
我在网上搜索了这个。 实现ID3D10Include类,然后没有人告诉如何使用它... 我不知道使用什么文件扩展名...是不是.hlsli ?? 像#include“lightfuncs.hlsli”??
对此有什么好的建议?
如果我不写入口点,当我编译项目(按CTR +希夫+ B)发生错误。我怎么让编译器知道一些hlsl文件只是为了包括? –
如果您在Visual Studio中默认使用''hlsli'' –
@ChuckWalbourn,那么“排除自构建”将不会尝试将该文件编译为HLSL着色器? – Matthias