I was trying to play around with custom lighting models, and immediately encountered the following problem, which should be a really basic one, but I'm really not sure why it works as it is.
code:
Code: Select all
#define pi 3.14159265358979324
float4x4 mMVP : WORLDVIEWPROJECTION;
float4x4 mMV : WORLDVIEW;
float4x4 mIMV : WORLDVIEWINVERSE;
struct VDL{
float3 D;
float3 S;
float3 A;
float3 vDir;};
struct VPL{
float3 D;
float3 S;
float3 A;
float3 vPos;
float3 vAtt;
float Range;};
struct VSL{
int Type;
float3 D;
float3 S;
float3 A;
float3 vPos;
float3 vDir;
float3 Att;
float4 FalloffO2I;};
struct VL{
int Type;
float3 D;
float3 S;
float3 A;
float3 vPos;
float3 vDir;
float3 vAtt;
float4 FalloffO2I;};
VDL DL[8]< string SasBindAddress = "Ventuz.DirectionalLight[*]";>;
VPL PL[8]< string SasBindAddress = "Ventuz.PointLight[*]" ;>;
VSL SL[8]< string SasBindAddress = "Ventuz.SpotLight[*]" ;>;
VL L[8] < string SasBindAddress = "Ventuz.Light[*]" ;>;
int DLCount< string SasBindAddress = "Ventuz.NumDirectionalLights" ;>;
int PLCount< string SasBindAddress = "Ventuz.NumPointLights" ;>;
int SLCount< string SasBindAddress = "Ventuz.NumSpotLights" ;>;
int LCount< string SasBindAddress = "Ventuz.NumLights" ;>;
struct a2v{
float4 vPos : POSITION0;
float4 vNormal : NORMAL0;
};
struct v2f{
float4 vPos : POSITION0;
float4 vPosVS : TEXCOORD0;
float4 vNormalVS : NORMAL0;
};
float sp<string SasUiLabel="Specular Power";float SasUiMin=0;> = 50;
float3 c<string SasUiControl="ColorPicker";>;
v2f vert(a2v Input){
float4x4 mITMV = transpose(mIMV);
v2f Output;
Output.vPos = mul(Input.vPos, mMVP);
Output.vNormalVS = mul(Input.vNormal, mITMV);
Output.vPosVS = mul(Input.vPos, mMV);
return Output;
}
float4 frag(v2f Input) : COLOR{
// Directional Light:
float3 n = normalize(Input.vNormalVS.xyz);
float3 l = -normalize(DL[0].vDir);
float3 v = normalize(Input.vPos.xyz);
float3 h = (l+v)/2;
float4 LCoef = lit(dot(n,l),dot(n,h),sp);
// return LCoef*float4(c,1);
return float4(c,1);
}
technique tech0{
pass pass0{
vertexshader = compile vs_3_0 vert();
pixelshader = compile ps_3_0 frag();
ZEnable = TRUE;
}
}
Problem: In the last two lines in my pixelshader (the frag function), I have one return commented out. The fx shader works fine as it is, but if I swap both lines, I get compile errors:
- (58,16)Legal indices are in [1,15]
- (58,16)invalid ps_3_0 input semantic 'POSITION0'
- (90,17)There was an error compiling expression
Code: Select all
struct v2f{
float4 vPos : POSITION0;
Code: Select all
pixelshader = compile ps_3_0 frag();
Thanks in advance
-C