PDA

View Full Version : Cg shader for env-Map



Cgor_Cyrosly
08-27-2007, 12:29 AM
Hi,my GL Program with cg vertex shader and fragment shader,but the result is black color ,it`s also not changed after i changed the uniform parameter through the Cg api "cgSetParameter*",why?
these`re my shaders,is there problem? Thanks

VS


struct v2fConnector{
float4 oPos:HPOS;
float3 oReflRay:TEX0;
float3 oRefrRayR:TEX1;
float3 oRefrRayG:TEX2;
float3 oRefrRayB:TEX3;
float oDis:COL0;
};

v2fConnector vertexEntry(uniform matrix mvp:state.matrix.mvp,
uniform matrix mv:state.matrix.modelview,
uniform float3x3 mvit:state.matrix.modelview.invtrans,
uniform float3 lightPos,
uniform float3 eta,
float4 vPos:POSITION,
float4 vTexCoord:TEXCOORD0,
float3 vNormal:NORMAL)
{
v2fConnector OUT;
float4 eHPos=mul(mv,vPos);
float3 mRay=-normalize(lightPos-eHPos.xyz/eHPos.w);//In light ray of 3D eye-space
float3 mNormal=normalize(mul(mvit,vNormal));
OUT.oPos=mul(mvp,vPos);
OUT.oReflRay=reflect(mRay,mNormal);
OUT.oRefrRayR=refract(mRay,mNormal,eta.x);
OUT.oRefrRayG=refract(mRay,mNormal,eta.y);
OUT.oRefrRayB=refract(mRay,mNormal,eta.z);
OUT.oDis=length(mRay);//distance form vertex object to light
return OUT;
}
FS


struct v2fConnector{
float3 texCoord0:TEXCOORD0;
float3 texCoord1:TEXCOORD1;
float3 texCoord2:TEXCOORD2;
float3 texCoord3:TEXCOORD3;
float dis:COLOR0;
};

float4 fragmentEntry(v2fConnector IN,
uniform float3 reflectivity,
uniform float3 reflDelayR,
uniform float3 reflDelayG,
uniform float3 reflDelayB,
uniform float3 refrDelayR,
uniform float3 refrDelayG,
uniform float3 refrDelayB,
uniform samplerCUBE reflMap:TEXUNIT0,
uniform samplerCUBE refrMap:TEXUNIT1):COLOR
{
float4 reflColor=texCUBE(reflMap,IN.texCoord0);
reflColor.r*=1.0/(IN.dis*(IN.dis*reflDelayR.x+reflDelayR.y)+reflDel ayR.z);
reflColor.g*=1.0/(IN.dis*(IN.dis*reflDelayG.x+reflDelayG.y)+reflDel ayG.z);
reflColor.b*=1.0/(IN.dis*(IN.dis*reflDelayB.x+reflDelayB.y)+reflDel ayB.z);
float4 refrColor;
refrColor.r=texCUBE(refrMap,IN.texCoord1).r;
refrColor.r*=1.0/(IN.dis*(IN.dis*refrDelayR.x+refrDelayR.y)+refrDel ayR.z);
refrColor.g=texCUBE(refrMap,IN.texCoord2).g;
refrColor.r*=1.0/(IN.dis*(IN.dis*refrDelayG.x+refrDelayG.y)+refrDel ayG.z);
refrColor.b=texCUBE(refrMap,IN.texCoord3).b;
refrColor.r*=1.0/(IN.dis*(IN.dis*refrDelayB.x+refrDelayB.y)+refrDel ayB.z);
refrColor.a=1.0;
float4 oCol;
oCol.rgb=lerp(refrColor.rgb,reflColor.rgb,reflecti vity);
oCol.a=refrColor.a;
return oCol;
}