This shader mod was posted by Xystus in the shader thread. I've already used it and it's pretty much what I've been looking for, evolved's relief mapping with darklights lightmaps. But I can't figure out how to texture different objects. If I export a lightmap from darklights with a dbo how can this be done?
Maybe limbs?
I'm modeling a large castle for my WIP game season of dis and I really need both normal mapping and lightmaps. Any help appreciated.
//====================================================
// Relief Mapping
//====================================================
// By EVOLVED
// www.evolved-software.com
//====================================================
// Modified by Xystus to acept Darklights lightmaps
//--------------
// 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 LightTX <string Name="";>;
sampler2D Lighting = sampler_state
{
texture = <LightTX>;
};
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 UV1:TEXCOORD1;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float2 LM: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.LM=IN.UV1*float2(1.0,1.0);
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);
float4 LightMap=(tex2D(Lighting,IN.LM)*2);
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*LightMap)),Texture.w*Alpha);
}
//--------------
// techniques
//--------------
technique Relief
{
pass p1
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_a PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
http://mattsmith.carbonmade.com/