PDA

View Full Version : Problems with ARBVP1



maximian
09-15-2004, 07:26 AM
Okay, I resolved some prior issues. But I am still having problems with this program. I compiled for arbvp1 profile, but when I traced the assembly code it DOES NOT match the program in cg. Any ideas, please help. Thanks.



//BEGIN FRAGMENT PROGRAM IN CG
//C:\Documents and Settings\Owner\Desktop\CG Test>
//COMPILE WITH THE FOLLOWING:
//cgc -nofastmath -nofastprecision -longprogs //-strict -profile arbfp1 -o refLines.fp //reflectionLinesFP.cg
struct IN
{
float3 texcoord0 : TEXCOORD0; //interpolated vertex position
float3 texcoord1 : TEXCOORD1; //interpolated vertex normal
};

struct OUT
{
float4 color : COLOR;
};

float4 RayPlaneIntersection( float4 planeN, float planeD, float4 rayP, float4 rayT)
{
float dotP = dot( rayT, planeN);
float4 intersectP;
float ret1,ret2;

ret1 = (dotP == 0 ) ? 0 : 1;

float u = (-( dot(planeN, rayP) + planeD)) / (dotP);

ret2 = (u < 0 ) ? 0 : 1;

intersectP = (u*rayT + rayP)*ret1*ret2;
intersectP.w = ret1*ret2;

return intersectP;
}

float4 Proj3(float4 p, float4 q)
{
float4 result;

float pDotQ = dot( p, q );

float magQ = dot( q, q );

pDotQ /= magQ;

result = q*pDotQ;

return result;
}

float GetColor(float distance)
{
float lDistance=.001;
float sDistance=.002;
float sum = lDistance+sDistance;

int div = distance / sum;
distance -= div*sum;

distance -= lDistance;

float color = (distance<=0) ? 0.0 : 1.0;
return color;
}


OUT main(IN i)
{
OUT o;

float4 planeN=float4(0,0,1,0);
float4 rayT=float4(0,0,-1,0);
float4 centroid=float4(0,0,.6,1);
float4 v3,v1=float4(1,0,0,0),temp;
float4 intersectPoint = float4(1,1,1,1);
float planeD;
float color;
float distance;

temp = float4( i.texcoord0, 1);
intersectPoint = RayPlaneIntersection( planeN, planeD, temp, rayT);
v3 = intersectPoint - centroid;
temp = Proj3( v3, v1);

distance = sqrt( dot( temp, temp ) );

color = GetColor(distance);

o.color = float4( color, color, color, 1);

return o;
}