Jump to content
  • Advertisement
Sign in to follow this  
BMacZero

Debugging HLSL Shader

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

I'm having a lot of trouble debugging this specular shader in HLSL, I was hoping some extra eyes might be able to find the problem. Can anyone help me out here? I'm just banging my head against the wall at this point.

This is the shader code:


sampler TextureSampler : register(s0);

Texture2D<float4> xSpecularMap;
Texture2D<float4> xNormalMap;
float3 xLightPosition;
float4 xLightColor;
uint xWidth;
uint xHeight;

sampler Sampler =
sampler_state
{
Texture = xNormalMap;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};

float4 main(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0
{
float4 tex = tex2D(TextureSampler, texCoord);

float3 texC3;
texC3.x = texCoord.x * xWidth;
texC3.y = texCoord.y * xHeight;
texC3.z = 0;

float4 shadingResult = float4(0,0,0,0);

float4 normal = xNormalMap.Sample(Sampler, texCoord) - float4(.5,.5,.5,.5);
float specular = xSpecularMap.Sample(Sampler, texCoord).r;
float3 displacement = normalize(xLightPosition.xyz - texC3);

float intensity = dot(normal.xyz, displacement);
//shadingResult += intensity * xLightColor;

float3 halfvector = normalize((displacement + float3(0,0,-1)) / 2);
float specintensity = max(0, dot(normal.xyz, halfvector));
shadingResult = specintensity * xLightColor;

return specintensity; //tex * shadingResult * color;
}

technique Light
{
pass Pass1
{
PixelShader = compile ps_2_0 main();
}
}


The key area starts around line 40. specular is the R value of a passed-in specular map, which is correct and has stuff in it (this is what I see if I pass it straight through):
spec.png

And if I pass through only the calculated intensity of the specular light, this is what I see:
shade2.png

But if I return the simple product of these two floats, all I see is black with an extremely faint circle at the location of the light, even if I augment the shading intensity hundredfold.

Thanks in advance for any advice.

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!