这个HLSL 在 DX9.0里没问题 但在 最新DXSDK_Aug09 里出问题

ggg_sss_lll 2009-10-10 04:13:20

matrix ViewMatrix;
matrix ViewProjMatrix;

vector AmbientMtrl;
vector DiffuseMtrl;

vector LightDirection;

//
// Global variables used to hold the ambient light intensity (ambient
// light the light source emits) and the diffuse light intensity (diffuse
// light the light source emits). These variables are initialized here
// in the shader.
//

vector DiffuseLightIntensity = {0.0f, 0.0f, 1.0f, 1.0f};
vector AmbientLightIntensity = {0.0f, 0.0f, 0.2f, 1.0f};

//
// Input and Output structures.
//

struct VS_INPUT
{
vector position : POSITION;
vector normal : NORMAL;
};

struct VS_OUTPUT
{
vector position : POSITION;
vector diffuse : COLOR;
};

//
// Main
//

VS_OUTPUT Main(VS_INPUT input)
{
// zero out all members of the output instance.
VS_OUTPUT output = (VS_OUTPUT)0;

//
// Transform position to homogeneous clip space
// and store in the output.position member.
//
output.position = mul(input.position, ViewProjMatrix);

//
// Transform lights and normals to view space. Set w
// componentes to zero since we're transforming vectors
// here and not points.
//
LightDirection.w = 0.0f;
input.normal.w = 0.0f;
LightDirection = mul(LightDirection, ViewMatrix);
input.normal = mul(input.normal, ViewMatrix);

//
// Compute cosine of the angle between light and normal.
//
float s = dot(LightDirection, input.normal);
if( s < 0.0f )
s = 0.0f;

//
// Ambient light reflected is computed by performing a
// component wise multiplication with the ambient material
// vector and the ambient light intensity vector.
//
// Diffuse light reflected is computed by performing a
// component wise multiplication with the diffuse material
// vector and the diffuse light intensity vector. Further
// we scale each component by the shading scalar s, which
// shades the color based on how much light the vertex received
// from the light source.
//
// The sum of both the ambient and diffuse components gives
// us our final vertex color.
//

output.diffuse = (AmbientMtrl * AmbientLightIntensity) +
(s * (DiffuseLightIntensity * DiffuseMtrl));

return output;
}


错误提示:
error X3025: global variables are implicitly constant, enable compatility mode to allow modification

新版本里都改了些什么呢?
该如何处理,才行呢??
...全文
144 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feilinhe 2009-10-10
  • 打赏
  • 举报
回复
DX9.0的几个版本之间改动确实比较大,全局变量是extern也是常量,在shader里面不能修改,但可以从宿主程序里改。以前的编译器没有强制这一点,现在新的强化了这一要求,改成static试试
lizhigang34 2009-10-10
  • 打赏
  • 举报
回复
HLSL...
好熟悉的四个字母啊,帮顶了!

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧