Is there a normalmap, bump, or parallax shader with support for darklights lightmaps? I tried to modify the ReliefMapping.fx from evolved with no luck.
How to add the stage 1 with darklights lightmaps to a shader?
Original:
//====================================================
// Relief Mapping
//====================================================
// By EVOLVED
// www.evolved-software.com
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------
// tweaks
//--------------
float3 Ambient={0.5f,0.5f,0.5f};
float3 LightPosition={150.0f,150.0f,0.0f};
float3 LightColor={1.0f,1.0f,1.0f};
float LightRange=200.0f;
float SpecularPow=32.0f;
float depth=0.03;
float4 FogColor={0.8f,0.8f,0.8f,1.0f};
float FogRange=250000.0f;
float Alpha=1.0f;
//--------------
// Textures
//--------------
texture BaseTX <string Name="";>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture NormalTX <string Name="";>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
texture HeightMTX <string Name="";>;
sampler2D HeightM = sampler_state
{
texture = <HeightMTX>;
};
//--------------
// 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;
float3 ViewPos:TEXCOORD4;
float3 VNormal:TEXCOORD5;
float Fog:FOG;
};
//--------------
// vertex shader
//--------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV;
float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
TBN=transpose(mul(TBN,World));
float3 WPos=mul(IN.Pos,World);
float3 LightPos=LightPosition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-LightPos/LightRange;
OUT.ViewVec=mul(ViewPos,TBN);
OUT.ViewPos=-ViewPos;
OUT.VNormal=mul(IN.Normal,World);
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shader
//--------------
float GetDepth(in float2 Uv,in float2 Displace)
{
float Height=0.0;
float depth=1.0;
float Inc=0.125f;
for( int i=0;i<8;i++ )
{
Height+=Inc;
float HeightTex=1-tex2D(HeightM,Uv+Displace*Height);
if (depth>0.995)
if (Height>=HeightTex) depth=Height;
}
Height=depth;
for( int i=0;i<4;i++ )
{
Inc*=0.5;
float HeightTex=1-tex2D(HeightM,Uv+Displace*Height);
if (Height>=HeightTex)
{
depth=Height;
Height-=2*Inc;
}
Height=Height+Inc;
}
return depth;
}
float4 PS(output IN) : COLOR
{
float2 Uv=IN.Tex;
float3 View=normalize(IN.ViewVec);
float ViewN=dot(IN.VNormal,normalize(IN.ViewPos));
float2 Displace=((View*depth)/ViewN).xy;
float Ray=GetDepth(Uv,Displace);
float2 NewUv=(Uv+Displace*Ray);
float4 Texture=tex2D(Base,NewUv);
float3 NormalMap=tex2D(Normal,NewUv)*2-1;
NormalMap=normalize(NormalMap);
float3 LightV=normalize(IN.LightVec);
float Normal=saturate(dot(reflect(-View,NormalMap),LightV));
Normal=pow(Normal,SpecularPow)+saturate(dot(NormalMap,LightV));
float PixelLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
float3 Light=PixelLight*LightColor;
return float4(Texture*((Normal*Light)+Ambient),Texture.w*Alpha);
}
//--------------
// techniques
//--------------
technique Relief
{
pass p1
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_a PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
and my modification
//====================================================
// Relief Mapping
//====================================================
// By EVOLVED
// www.evolved-software.com
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------
// tweaks
//--------------
float3 Ambient={0.5f,0.5f,0.5f};
float3 LightPosition={150.0f,150.0f,0.0f};
float3 LightColor={1.0f,1.0f,1.0f};
float LightRange=200.0f;
float SpecularPow=32.0f;
float depth=0.03;
float4 FogColor={0.8f,0.8f,0.8f,1.0f};
float FogRange=250000.0f;
float Alpha=1.0f;
//--------------
// Textures
//--------------
texture BaseTX <string Name="";>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture LightMap <string Name="";>;
sampler2D LightMapSample = sampler_state
{
texture = <LightMap>;
};
texture NormalTX <string Name="";>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
texture HeightMTX <string Name="";>;
sampler2D HeightM = sampler_state
{
texture = <HeightMTX>;
};
//--------------
// structs
//--------------
struct input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD0;
float2 LMUV:TEXCOORD1;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float2 LMuv:TEXCOORD1;
float3 LightVec:TEXCOORD2;
float3 Attenuation:TEXCOORD3;
float3 ViewVec:TEXCOORD4;
float3 ViewPos:TEXCOORD5;
float3 VNormal:TEXCOORD6;
float Fog:FOG;
};
//--------------
// vertex shader
//--------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV;
OUT.LMuv=IN.LMUV;
float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
TBN=transpose(mul(TBN,World));
float3 WPos=mul(IN.Pos,World);
float3 LightPos=LightPosition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-LightPos/LightRange;
OUT.ViewVec=mul(ViewPos,TBN);
OUT.ViewPos=-ViewPos;
OUT.VNormal=mul(IN.Normal,World);
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shader
//--------------
float GetDepth(in float2 Uv,in float2 Displace)
{
float Height=0.0;
float depth=1.0;
float Inc=0.125f;
for( int i=0;i<8;i++ )
{
Height+=Inc;
float HeightTex=1-tex2D(HeightM,Uv+Displace*Height);
if (depth>0.995)
if (Height>=HeightTex) depth=Height;
}
Height=depth;
for( int i=0;i<4;i++ )
{
Inc*=0.5;
float HeightTex=1-tex2D(HeightM,Uv+Displace*Height);
if (Height>=HeightTex)
{
depth=Height;
Height-=2*Inc;
}
Height=Height+Inc;
}
return depth;
}
float4 PS(output IN) : COLOR
{
float2 Uv=IN.Tex;
float3 View=normalize(IN.ViewVec);
float ViewN=dot(IN.VNormal,normalize(IN.ViewPos));
float2 Displace=((View*depth)/ViewN).xy;
float Ray=GetDepth(Uv,Displace);
float2 NewUv=(Uv+Displace*Ray);
float4 Texture=tex2D(Base,NewUv);
float3 NormalMap=tex2D(Normal,NewUv)*2-1;
NormalMap=normalize(NormalMap);
float3 LightV=normalize(IN.LightVec);
float Normal=saturate(dot(reflect(-View,NormalMap),LightV));
Normal=pow(Normal,SpecularPow)+saturate(dot(NormalMap,LightV));
float PixelLight=1-saturate(dot(IN.Attenuation,IN.Attenuation));
float3 Light=PixelLight*LightColor;
return float4(Texture*((Normal*Light)+Ambient),Texture.w*Alpha);
}
//--------------
// techniques
//--------------
technique Relief
{
pass p1
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_a PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
Thanks and sorry for my english