PDA

View Full Version : cg shader and semantic



giuseppe500
07-24-2010, 08:20 AM
Hy.
I'm try to compile this shader with fxcomposer:


this is the function that calculate the spot light


float4 GetSpotLightFactors
(
float3 kModelPosition,
float3 kModelNormal,
float3 kCameraPosition,
float3 kLightPosition,
float fSpecularExponent,
float3 kSpotAxis,
float fSpotCosAngle,
float fSpotExponent
)
{
float3 kVertexDirection = normalize(kModelPosition - kLightPosition);
float fVertexCosAngle = dot(kSpotAxis, kVertexDirection);
if (fVertexCosAngle >= fSpotCosAngle)
{
float fNDotLDir = dot(kModelNormal, -kVertexDirection);

float3 kViewVector = normalize(kCameraPosition - kModelPosition);
float3 kHalfVector = normalize(kViewVector - kVertexDirection);
float fNDotHDir = dot(kModelNormal, kHalfVector);

float4 kLighting = lit(fNDotLDir, fNDotHDir, fSpecularExponent);

// spot contribution
kLighting.w = pow(fVertexCosAngle, fSpotExponent);

return kLighting;
}
else
{
return float4(1.0f, 0.0f, 0.0f, 0.0f);
}
}
void v_L1p
(
in float3 kModelPosition : POSITION,
in float3 kModelNormal : NORMAL,
out float4 kClipPosition : POSITION,
out float4 kVertexColor : COLOR,
uniform float4x4 WVPMatrix,
uniform float4x4 WMatrix,
uniform float3 CameraModelPosition,
uniform float3 MaterialEmissive,
uniform float3 MaterialAmbient,
uniform float4 MaterialDiffuse,
uniform float4 MaterialSpecular,
uniform float3 Light0ModelPosition,
uniform float3 Light0Ambient,
uniform float3 Light0Diffuse,
uniform float3 Light0Specular,
uniform float4 Light0Attenuation)
{
// Transform the position from model space to clip space.
kClipPosition = mul(float4(kModelPosition,1.0f),WVPMatrix);

float4 kLighting = GetPointLightFactors(kModelPosition,kModelNormal,
CameraModelPosition,Light0ModelPosition,MaterialSp ecular.a);

float fAttn = GetAttenuation((float3x3)WMatrix,kModelPosition,
Light0ModelPosition,Light0Attenuation);

float3 kColor = MaterialAmbient*Light0Ambient
+ kLighting.y*MaterialDiffuse.xyz*Light0Diffuse
+ kLighting.z*MaterialSpecular.xyz*Light0Specular;

kVertexColor.rgb = MaterialEmissive + fAttn*kColor;
kVertexColor.a = MaterialDiffuse.a;

}


i dont know why this extra semantic:

in float3 kModelPosition : POSITION,
in float3 kModelNormal : NORMAL,
out float4 kClipPosition : POSITION,
out float4 kVertexColor : COLOR,



but when i call the function v_L1s(the light spot) i get 6 error like this:

Error error C5119 variable/member "HPosition" has semantic "POSITION" which is not visible in this profile


these are the frament and vertex shader:


struct pixel_in {

float4 HPosition : POSITION;
float3 kModelNormal : NORMAL;
float4 kModelColor : COLOR;
};

struct pixel_out {

float4 HPosition:POSITION;
float3 Normal;
float4 Color ;

};

pixel_out mainVS(pixel_in PIN) {

pixel_out OUT;
OUT.HPosition = PIN.HPosition;
OUT.Normal = PIN.kModelNormal;

return OUT;
}
struct pxCol {
float4 color : COLOR;
};
pxCol mainPS(pixel_out IN)
{
float4 kClipPosition = IN.HPosition;
float4 HPosition;
float3 Norm = IN.Normal;
float4 kColorSpot;

v_L1s(
HPosition ,
Norm,
kClipPosition,
kColorSpot,
WVPMatrix,
WMatrix,
CameraModelPosition,
MaterialEmissive,
MaterialAmbient,
MaterialDiffuse,
MaterialSpecular,
Light0ModelPosition,
Light0ModelDirection,
Light0Ambient,
Light0Diffuse,
Light0Specular,
Light0SpotCutoff,
Light0Attenuation);

pxCol Pout;
Pout.color = kColorSpot ;
return Pout;
}
technique technique0 {
pass p0 {
CullFaceEnable = false;
VertexProgram = compile arbvp1 mainVS();
FragmentProgram = compile arbfp1 mainPS();
}
}


I don't understand

Dark Photon
07-31-2010, 06:12 PM
in float3 kModelPosition : POSITION,
in float3 kModelNormal : NORMAL,
out float4 kClipPosition : POSITION,
out float4 kVertexColor : COLOR,


but when i call the function v_L1s(the light spot) i get 6 error like this:

Error error C5119 variable/member "HPosition" has semantic "POSITION" which is not visible in this profile ... I don't understand
Post Cg questions on NVidia's Cg forum:

* http://developer.nvidia.com/forums/index.php?showforum=14