Jump to content
  • Advertisement
Sign in to follow this  
sebjf

What could be the cause of this specular highlight artifact?

This topic is 2450 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

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)

[attachment=7903: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;
};


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

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);
}
}

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!