This is very impressive.
Could this code be added to a Parallax Occlusion shader or does it only get applied as a separate shader?
Can you apply this shader with other shaders?
I am currently using a Parallax Occlusion shader on my models.
I am doing a high poly bake with textures using "XNormal".
This is the shader I am using which I altered for High Poly bakes.
My code changes might be wrong, still learning shaders.
//====================================================
// Parallax occlusion mapping
//====================================================
// By EVOLVED
// www.evolved-software.com
//Updated by SITDS
//added normalize to height texture in pixel shader.Needed for High poly bake
//Added cross product to the vertex shader to average the normals to smooth shade the model
//Changed to PS 3.0 and VS 3.0
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------
// tweaks
//--------------
float3 Ambient={0.1f,0.1f,0.1f};
float3 LightPosition={150.0f,150.0f,0.0f};
float3 LightColor={1.0f,1.0f,1.0f};
float LightRange=200.0f;
float SpecularPow=16.0f;
float Heightvec=0.01;
float Biasheight=0.25;
float4 FogColor={0.8f,0.8f,0.8f,1.0f};
float FogRange=2500.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 HeightTX <string Name="";>;
sampler2D Height = sampler_state
{
texture = <HeightTX>;
};
//--------------
// 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;
float Fog:FOG;
};
//--------------
// vertex shader
//--------------
output VS(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV;
//SITDS altered
//Orignal line replaced by 4 lines below
//float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
//recalculate Tangents and binormals for smooth shading of vertex shader
float3 n = normalize(IN.Normal);
float3 b = normalize(cross(n, IN.Tangent));
float3 t = normalize(cross(b, n));
float3x3 TBN={t,b,n};
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.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shader
//--------------
float4 PS(output IN) : COLOR
{
float3 View=normalize(IN.ViewVec);
float2 NewUv=IN.Tex;
//SITDS added Normalize to height for High poly bakes.
for(int i=0;i<8;i++)
{
float HeightTex=normalize(tex2D(Height,NewUv).x+Biasheight);
NewUv +=(Heightvec*HeightTex-Heightvec)*View;
}
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 Parallax
{
pass p1
{
vertexShader = compile vs_3_0 VS();
pixelShader = compile ps_3_0 PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
[img]
[/img]
WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.