Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Combining lightsources

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 cozzie   Members   

4964
Like
0Likes
Like

Posted 15 July 2013 - 04:21 PM

Hi,

I'm trying to combine a point light and directional light, with in the end both diffuse and specular components.

But I can't figure out why the combination of my diffuse directional light and diffuse point light are not working together. In the attenuation range the light gets 'purple', in the center of the point light it looks OK (same as when disabling the directional light).

 

I've stripped the pixel shader to find the case, but no success yet.

Any help is really appreciated.

 

When I use the light sources individual from each other (directional/ point) I get expected results.

// Complete version

float4 PS_function(VS_OUTPUT input): COLOR0
{
	float4 textureColor = tex2D(textureSampler, input.TexCoord);
	float3 normal = normalize(input.Normal);

// 	SPECULAR

	float3 viewdir = normalize(CameraPos - input.wPos);
	float specPower = exp2(MatSpecPower * 13.0f);


/** 	DIRECTIONAL LIGHT - PER PIXEL (diffuse and specular) **/
	float3 diffuseDir = 0.0f;
	float3 specularDir = 0.0f;

	for(int i=0;i<MaxDirectionalLights;i++)
	{	
		diffuseDir	+= saturate(DirLightColInt[i] * dot(normal,  DirLightDir[i]));

		float3 lightdir = normalize(DirLightDir[i] - input.wPos);
		float3 h = normalize(lightdir + viewdir);
		specularDir += pow(saturate(dot(h, normal)), specPower);
	}

/** 	POINT LIGHTS - PER PIXEL (diffuse and specular) **/

	float3 lightDir = normalize(PointLightPos[0] - input.wPos);

	// per pixel attenuation
	float dist = length(PointLightPos[0] - input.wPos);

	float att = saturate(1 - (dist - PointLightFPRange[0]) / (PointLightRange[0] - PointLightFPRange[0]));
	att *= att;

	// per pixel diffuse

	float diffIntPoint = dot(normal, lightDir) * att;
	float3 diffusePoint = diffIntPoint * PointLightColInt[0];

	// specular; using blinn half angle

	float3 h = normalize(lightDir + viewdir);

	float specularPoint = pow(saturate(dot(h, normal)), specPower) * att;

/**	FINAL PIXEL COLOR (specular only for point lights **/

	return float4((saturate(AmbientColInt + (MatDiff * (diffusePoint + diffuseDir)) + (MatSpec * (specularDir + specularPoint)) + MatEmi) * textureColor.rgb), textureColor.a);
}


// Stripped version just to test diffuse, not OK

float4 PS_function(VS_OUTPUT input): COLOR0
{
	float4 textureColor = tex2D(textureSampler, input.TexCoord);
	float3 normal = normalize(input.Normal);

/** 	DIRECTIONAL LIGHT - PER PIXEL (diffuse and specular) **/
	float3 diffuseDir = 0.0f;
	for(int i=0;i<MaxDirectionalLights;i++)
	{	
		diffuseDir	+= saturate(DirLightColInt[i] * dot(normal,  DirLightDir[i]));
	}

/** 	POINT LIGHTS - PER PIXEL (diffuse and specular) **/

	float3 lightDir = normalize(PointLightPos[0] - input.wPos);

	// per pixel attenuation
	float dist = length(PointLightPos[0] - input.wPos);

	float att = saturate(1 - (dist - PointLightFPRange[0]) / (PointLightRange[0] - PointLightFPRange[0]));
	att *= att;

	// per pixel diffuse

	float diffIntPoint = dot(normal, lightDir) * att;
	float3 diffusePoint = diffIntPoint * PointLightColInt[0];
	

/**	FINAL PIXEL COLOR (specular only for point lights **/

	return float4((saturate((diffusePoint + diffuseDir)) * textureColor.rgb), textureColor.a);
}

Edited by cozzie, 15 July 2013 - 04:23 PM.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me


#2 cozzie   Members   

4964
Like
1Likes
Like

Posted 16 July 2013 - 01:00 PM

Solved it, after looking at it for quite a while ... angry.png

 

I wasn't clamping (saturate) the diffuse lighting of the point light.

Looks all good now


Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.