Okay here's the shader so far, in theory it should work, but I haven't
tested it yet and so there may be some mistake that I overlooked, it's
setup as if for Ogre, so it will likely need some slight changes for
use with Torque. If the formatting got messed up too much by the
forums wordwrapping, then I can post the hlsl file itself.
//Begin File
/////////////////////////////////////////////////////////////////////////
/== Parallax + SpecMap + LightMap Shader ==/
////////////////////////////////////////////////////////////////////////
void vertex_main
(
float4 position : POSITION,
float3 normal : NORMAL,
float2 uv : TEXCOORD0,
float2 uv2 : TEXCOORD1,
float3 tangent : TEXCOORD2,// judging by the example I assume
tangent and binormal are supplied here..?
float3 binormal : TEXCOORD3,
// Outputs
out float4 oPosition : POSITION,
out float2 oUv : TEXCOORD0,
out float2 oUv2 : TEXCOORD1,
out float3 oTSLightDir : TEXCOORD2, // (tangent space)
out float3 oTSHalfAngle : TEXCOORD3, // (tangent space)
out float3 oEyeDir : TEXCOORD4, // (tangent space)
//Apparently Torque requires registers for uniforms?
//I don't know how Torque wants that sort of thing setup so I've
left it blank
// uniform params, and the like
uniform float4x4 worldViewProj,
// object space:
uniform float4 lightPosition,
uniform float3 eyePosition
)
{
oPosition = mul(worldViewProj, position);
oUv = uv;
oUv2 = uv2;
float3 lightDir = normalize(lightPosition.xyz - (position *
lightPosition.w));
float3x3 rotation = float3x3(tangent, binormal, normal);
oTSLightDir = mul(rotation, lightDir);
float3 eyeDir = normalize(eyePosition -
position.xyz);
float3 halfAngle = normalize(eyeDir + lightDir);
oTSHalfAngle = mul(rotation, halfAngle);
float3 eyeDir = eyePosition -
position.xyz;
oEyeDir = normalize(mul(rotation, eyeDir));
}
float3 expand(float3 vect)
{
return (vect - 0.5) * 2;
}
void fragment_main
(
// inputs
float2 uv :TEXCOORD0,
float2 uv2 :TEXCOORD1,//lightmap coord
float3 TSLightDir :TEXCOORD2,
float3 TSHalfAngle :TEXCOORD3,
float3 eyeDir :TEXCOORD4,
// samplers, uniforms etc
//light stuff
uniform float3 diffuseColor, //Do the light maps include color?
uniform float3 specularColor,
uniform float3 ambientColor,
uniform float shininess, //Larger values result in brighter,
smaller highlights
uniform float2 scaleBias,//x component = scale, y = bias
// samplers
uniform sampler2D diffuseMap : register(S0),
uniform sampler2D normalMap : register(S1),
uniform sampler2D heightMap : register(S2),
uniform sampler2D lightMap : register(S3),
uniform sampler2D specMap : register(S4),
//output
out float4 oColor : COLOR)
)
{
// Using the alpha component of the normal or diffuse map would
also work here
float height = tex2D(heightMap, uv).r;
float scale = scaleBias.x;
float bias = scaleBias.y;
float displacement = (height * scale) + bias;
float3 uv3 = float3(uv, 1);
float2 offsetUV = ((eyeDir * displacement) + uv3).xy;
float3 normal = expand(tex2D(normalMap, offsetUV).xyz);
float3 diffuse = tex2D(diffuseMap, offsetUV).xyz;
float3 specular = pow(saturate(dot(normal, halfAngle)), shininess) *
specularColor;
// Spec map; allows for modifying color/intensity of the highlights
float3 specMap = tex2D(specMap,offsetUV);
float3 col = diffuse * saturate(dot(normal, TSLightDir)) *
diffuseColor + (specular*specMap);
//multiply in light map at the very end and add in ambient light
oColor = float4((col*tex2D(lightMap,uv2))+ambient, 1);
}
//End File
> > - Show quoted text -- Hide quoted text -