Jump to content
  • Advertisement
Sign in to follow this  
Asheh

CG Attenuation Problem?

This topic is 3255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive been playing around with my attenuation and it seems its totally off, if I adjust the values so that it should only appear within a small distance it doesnt seem to affect things at all, here is my CG code:
void Ambient_vp
		(
		  float4 position : POSITION, 

		  out float4 oPosition : POSITION,
		  out float4 colour    : COLOR,

		  uniform float4x4 worldViewProj,
		  uniform float4 ambient
		)
{
	oPosition = mul(worldViewProj, position);
	colour = ambient;
} 

void PerPixel_Vert 
		(	
			float4 position : POSITION,
			float3 normal   : NORMAL, 

			uniform float4 lightPosition,
			uniform float3 eyePosition,
			uniform float4x4 worldviewproj, 

			out float4 oPos : POSITION,
			out float3 oNorm: TEXCOORD0,
			out float3 oLightDir: TEXCOORD1,
			out float3 oHalfAngle: TEXCOORD2,
			out float3 oWorldPos: TEXCOORD3
		) 
{
	oPos = mul(worldviewproj, position);
	oWorldPos = float3(oPos);
	
    //oDist = length(position - lightPosition); //interpolated fragment distance
   
	float3 EyeDir = normalize(eyePosition - position.xyz);

	oLightDir = normalize(lightPosition.xyz -  (position.xyz * lightPosition.w)); 

	oHalfAngle   = normalize(oLightDir + EyeDir); 

	oNorm = normal;
}
 

void PerPixel_Frag (	float3 normal: TEXCOORD0,
			float3 LightDir  : TEXCOORD1,
			float3 HalfAngle : TEXCOORD2, 
			float  WorldPos : TEXCOORD3, 

			uniform float4 lightPosition,
			uniform float4 lightDiffuse,
			uniform float4 lightSpecular,
			uniform float exponent,

		    out float4 oColor : COLOR
		   )
{  
	float3 N = normalize(normal);

	float NdotL = dot(normalize(LightDir), N);
	float NdotH = dot(normalize(HalfAngle), N);
	
	if(NdotL > 0.0)
	{
		float4 Lit = lit(NdotL,NdotH,exponent);
		
		//linear attenuation
		float d = distance(WorldPos, lightPosition);
		float l = 0.022;
		float q = 0.0019;
		float atten = 1 / (1 + (l*d) + (q*d*d));
			
		oColor = (lightDiffuse * Lit.y + lightSpecular * Lit.z) * atten;
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!