We're having a problem with shaders, which doesn't look the same under DX and OGL. It's basicly normal mapping shader.
OpenGL:
DX:
Now comes the shader code:
Code: Select all
void main(
float2 TexCoord0 : TEXCOORD0,
float3 L : TEXCOORD1,
float3 H : TEXCOORD2,
//my outputs
out float4 oColor : COLOR,
//textures
uniform sampler2D diffuseMap,
uniform sampler2D normalMap,
uniform sampler2D specularMap,
//uniform state
uniform float3 Ambient,
uniform float3 Diffuse,
uniform float3 OceanSpecular,
uniform float3 ContinentSpecular,
uniform float OceanShininess,
uniform float ContinentShininess)
{
//fetch normal diffuse color
float3 diffuseTexture = tex2D(diffuseMap, TexCoord0).xyz;
float3 specularCoefficient = tex2D(specularMap, TexCoord0).xyz;
float3 N = tex2D(normalMap, TexCoord0).xyz;
//prepare parameters for lighting calculations
N = (N - 0.5) * 2.0;
N = normalize(N);
L = normalize(L);
H = normalize(H);
float D = max(dot(N, L), 0.0);
//specular including selfshadowing
float spec = max(dot(N, H), 0.0);
spec = (D > 0.5)?spec:0.0;
float3 oceanSpec = pow(spec, OceanShininess) * OceanSpecular;
float3 continentSpec = pow(spec, ContinentShininess) * ContinentSpecular;
float3 specularColor = lerp(continentSpec, oceanSpec, specularCoefficient);
float3 outputColor = min(Ambient + Diffuse * D, 1.0) * diffuseTexture;
outputColor += specularColor;
//oColor = float4(outputColor, 1.0);
oColor = float4(L, 1.0);
}
EDIT:
Here comes vertex shader:
Code: Select all
void main(
//my inputs
float4 Position : POSITION,
float3 normal : NORMAL,
float2 TexCoord0 : TEXCOORD0,
float3 tangent : TEXCOORD1,
//my outputs
out float4 oPosition : POSITION,
out float4 oColor : COLOR,
out float2 oTexCoord0 : TEXCOORD0,
out float3 oTexCoord1 : TEXCOORD1,
out float3 oTexCoord2 : TEXCOORD2,
//uniform state
uniform float4x4 ModelViewProj,
uniform float4 LightPos,
uniform float3 EyePos)
{
oPosition = mul(ModelViewProj, Position);
oTexCoord0 = TexCoord0;
oColor = float4(1.0, 1.0, 1.0, 1.0);
float3 lightDir = LightPos.xyz;
normal = normalize(normal);
tangent = normalize(tangent);
float3 binormal = cross(tangent, normal);
float3x3 rotation = float3x3(tangent, binormal, normal);
// Transform the light vector according to this matrix
float3 L = normalize(mul(rotation, lightDir));
oTexCoord1 = L;
//oTexCoord1 = normalize(lightDir);
//calculate half-angle for specular
float3 V = EyePos - Position.xyz;
V = normalize(mul(rotation, V));
oTexCoord2 = normalize(V + L);
}
Guyver