Jump to content

  • Log In with Google      Sign In   
  • Create Account


What could be the cause of this specular highlight artifact?


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
No replies to this topic

#1 sebjf   Members   -  Reputation: 116

Like
0Likes
Like

Posted 26 March 2012 - 08:47 AM

Hello,

I have a problem with specular highlights in my shader. It manifests itself as a 'rogue highlight' emanating from the point the light vector 'intersects' with the surface, on the opposite side from that which should show the highlight.

Here is an image from it, showing the underside of a box with a directional light pointing down onto the box. (Diffuse set to 0 so only the specular component is showing)

Untitled.png

The excerpts from the shader which are relevant to the specular component are included below; I just cannot see what is going wrong.

This is a possible duplicate [http://www.gamedev.net/topic/459040-hlsl-cleaning-out-specular-artifacts-in-normal-maps/] but as I cannot see the pictures I can't tell!

Has anyone seen this before!?

Thanks

(If the code looks a little.. 'stilted' its because its being psuedo-procedurally generated)


-- Vertex Excerpts --
float4x4 globalTransform; //worldviewprojection
float4x4 worldTransform; //world

struct INPUT
{
float4 positionIn : POSITION0;
float4 normalIn : NORMAL0;
};

struct OUTPUT
{
float4 positionOut0 : POSITION0;
float3 normalOut : WORLD_NORMAL;
float4 positionOut1 : WORLD_POSITION;
};

void dfp_v_DoWVPmTransforms(in INPUT input, inout OUTPUT output)
{
float4 position = float4( input.positionIn.xyz, 1);
output.positionOut0 = mul( position, globalTransform );
}

void dfp_v_DoWorldTransforms(in INPUT input, inout OUTPUT output)
{
output.normalOut = normalize( mul( input.normalIn.xyz, (float3x3)worldTransform  ));
output.positionOut1 = mul( float4(input.positionIn.xyz,1), worldTransform);
output.positionOut1 = output.positionOut1 / output.positionOut1.w;
}

-- Pixel Excerpts --

float4 Ce;
float4 MAc;
float4 diffuseColour;
float4 specularColour;
float specularPower;
float4 eyePosition;

Texture2D lightingInfo;

struct INPUT
{
float4 positionOut0 : POSITION0;
float3 normalOut : WORLD_NORMAL;
float4 positionOut1 : WORLD_POSITION;
};

struct OUTPUT
{
float4 colourOut : COLOR0;
};

struct INTERNAL
{
float4 diffuseSum : DiffuseSum;
float4 specularSum : SpecularSum;
};


[b]float4 CalculateSpecularComponent(float3 surface_normal, float3 lightColour, float3 surface_light_dir, float3 eyeDir)[/b]
[b]{[/b]
[b]float3 H = normalize(-surface_light_dir + eyeDir);[/b]
[b]float intensity = saturate(dot(surface_normal,H));[/b]
[b]float specular = pow(intensity, specularPower);[/b]
[b]return saturate(float4( specularColour * lightColour * specular, 0 ));[/b]
[b]}[/b]

void dfp_p_ComputeDirectionalLights(in INPUT input, inout OUTPUT output, inout INTERNAL internal)
{

float3 worldNormal = input.normalOut;
float3 eyeDir = normalize(eyePosition - input.positionOut1).xyz;

float4 lightInfo = lightingInfo.Load(int3(1,0,0));
for(int i = 0; i < lightInfo.y; i++)
{
float lightoffset = lightInfo.x + (i * 4);

float4 lightcolourpower = lightingInfo.Load(int3(lightoffset,0,0));
float4 lightpositionambienteffect = lightingInfo.Load(int3(lightoffset+1,0,0));
float4 lightdirectcone = lightingInfo.Load(int3(lightoffset+2,0,0)); //the direction of the light will be in xyz

internal.diffuseSum += CalculateDiffuseComponent( worldNormal, lightcolourpower.xyz, lightdirectcone.xyz );
internal.specularSum += CalculateSpecularComponent( worldNormal, lightcolourpower.xyz, lightdirectcone.xyz, eyeDir);
}
}


Sponsor:



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.



PARTNERS