Texture Seams Showing With Evolved's Normal Mapping Shader.
I been having a problem for a long time now with texture seams appearing when I try to use normal mapping. I've had this on the back burner for a while now dealing with other things.
I have attached a zipped project folder containing a small demo of the problem with all necessary files and source. Download to pick at it as you like. Everything is included.
I should also add I completely flattened the normal map to ensure it wasn't creating seams.
Here is a copy of the shader:
//--------------------------------
// NormalMapping
//--------------------------------
// By Evolved
// http://www.vector3r.com/
//--------------------------------
//-----------------
// un-tweaks
//-----------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//-----------------
// tweaks
//-----------------
float4 LightPosition = {150.0f, 150.0f, 0.0f, 1.0f};
float4 LightColor = {1.0f, 1.0f, 1.0f, 1.0f};
float LightRange = 250.0f;
float4 Ambient = {0.1f, 0.1f, 0.1f, 1.0f};
float U = 1.0f;
float V = 1.0f;
//-----------------
// Textures
//-----------------
texture BaseTX
<
string Name="";
>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture NormalTX
<
string Name="";
>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
texture NormalizerTX
<
string Name = "";
>;
samplerCUBE Normalizer = sampler_state
{
Texture = <NormalizerTX>;
ADDRESSU = Clamp;
ADDRESSV = Clamp;
MagFilter = Linear;
MinFilter = Point;
MipFilter = None;
};
//-----------------
// structs
//-----------------
struct input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float3 LightVec:TEXCOORD1;
float3 Attenuation:TEXCOORD2;
float3 ViewVec:TEXCOORD3;
};
//-----------------
// vertex shader
//-----------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV*float2(U,V);
float3 WNor=mul(IN.Normal,World); WNor=normalize(WNor);
float3 Wtan=mul(IN.Tangent,World); Wtan=normalize(Wtan);
float3 Wbin=mul(IN.Binormal,World); Wbin=normalize(Wbin);
float3 WPos=mul(IN.Pos,World);
float3x3 TBN={-Wtan,Wbin,WNor}; TBN=transpose(TBN);
float3 LightPos=LightPosition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-LightPos/LightRange;
OUT.ViewVec=mul(ViewPos,TBN);
return OUT;
}
//-----------------
// pixel shader
//-----------------
float4 PS(output IN) : COLOR
{
float4 Texture=tex2D(Base,IN.Tex);
float3 NormalMap=tex2D(Normal,IN.Tex)*2-1;
float3 LightV=texCUBE(Normalizer,IN.LightVec)*2-1;
float3 View=texCUBE(Normalizer,IN.ViewVec)*2-1;
float Normal=saturate(dot(NormalMap,LightV));
float Specular=saturate(dot(reflect(-View,NormalMap),LightV));
Specular=Specular*Specular; Specular=Specular*Specular;
Specular=Specular*Specular;
float4 DiffuseLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
float4 Light=DiffuseLight*LightColor;
return Texture*(((Normal+Specular)*Light)+Ambient);
}
//-----------------
// techniques
//-----------------
technique NormalMapping
{
pass p1
{
vertexShader = compile vs_1_1 VS();
pixelShader = compile ps_1_4 PS();
}
}
Here is a copy of the demo source:
`Created By Mage Jul 13 2013
`Setup Screen
Set Display Mode 1024, 768, 32
Set Window On
AutoCam Off
Sync On
Sync Rate 30
Backdrop On
`----SETUP DEFAULT LIGHT EXAMPLE
`Load Media
Load Object "Player.x", 10
Position Object 10, -4, 0, 10
Load Image "texture.png", 5
Texture Object 10, 5
Set Object 10, 1, 0, 0, 0, 1, 0
`Create Lights
Make Light 1
Position Light 1, -4,0,0
Color Light 1, RGB(255,255,255)
Set Light Range 1, 100
Set Ambient Light 0
`----SETUP SHADER LIGHT EXAMPLE
`Load Media
Load Object "Player.x", 20
Position Object 20, 4, 0, 10
Set Object 20, 1, 0, 0, 0, 0, 0
`Load Extra Textures used by shader
Load Image "NormalMap.png", 6
Load Image "Normalize.dds", 7, 2
`Load the Shader and apply it
load effect "NormalMapping.fx", 50,0
set object effect 20, 50
`Texture the Object using stages
Texture Object 20, 0, 5
Texture Object 20, 1, 6
Texture Object 20, 2, 7
`Change the shaders light position for the example
vec = Make Vector4(1)
set vector4 1, 0, 0, 0, 1
set effect constant vector 50,"LightPosition", 1
`Display the example
Do
Text 20, 20, "DEFAULT LIGHTING ENGINE"
Text 720, 20, "EVOLVED NORMAL MAPPING SHADER"
XRotate Object 10, Object Angle X(10) + 0.3
XRotate Object 20, Object Angle X(20) + 0.3
Sync
Loop
End
Someone please help me fix this texture seam issue!
Thanks.