HLSL错误:x3206 implicit trucation of vector type


今天在两处出现了这个问题:

float3 ambient = gMtrl.ambient*gSpotLight.ambient;//环境光

oPosLight = mul( oPosW, gViewToLightProj );

检查了一下发现是维度问题..ambient是float3类型,gMtrl.ambient是float4类型;oPosLight是float4类型,oPosW是float3类型,只需要把gMtrl.ambient*gSpotLight.ambient的结果取前三维(.rgb或.xyz),oPosW换成思维的(float4(三位向量,1.0f))。
正确代码如下:

float3 ambient = (gMtrl.ambient*gSpotLight.ambient).rgb;//环境光

oPosLight = mul( float4(oPosW,1.0f), gViewToLightProj );



你可能感兴趣的:(vector,float)