Original Post
Hi, It seems all I ever do is have problems... so sorry that I keep asking so many questions - you guys are brilliant at your responses though, I'm learning so much! Anyway, I'm giving shaders a real go atm, and I'm eager to try lots of things. I thought it would be a good idea to try and get cube mapping in. I have sort of got it working. When the camera is at 0, 0, 0 and the mesh is in front of the camera (0, 0, 50 in this case) then it seems to render ok:
However, if I move the camera back 10 units (so it is at 0, 0, -10) then I get this really bizzare result:
Any ideas why this is? I'm pretty unsure with my shader but I thought I had it down correctly. People have said I should use world-invert-transposed matrix, but it gives realllly bad results! Edit: Oh, I thought it might help if you know the colours in the skybox there. Pink is forward, light blue is right, lime yellow is left, yellow is top, dark blue is bottom and red is backwards. [Edited by - acid2 on March 16, 2005 1:41:33 PM]
However, if I move the camera back 10 units (so it is at 0, 0, -10) then I get this really bizzare result:
Any ideas why this is? I'm pretty unsure with my shader but I thought I had it down correctly. People have said I should use world-invert-transposed matrix, but it gives realllly bad results!
float4x4 matWIT : WorldInverseTranspose;
float4x4 matWVP : WorldViewProjection;
float4x4 matVI : ViewInverse;
float4x4 matW : World;
texture CubeTexture;
samplerCUBE cubeSampler = sampler_state
{
texture = <CubeTexture>;
};
struct vsData
{
float4 pos : POSITION;
float3 norm : TEXCOORD0;
float3 viewDir : TEXCOORD1;
};
vsData vs_CubeMap( float4 pos : POSITION,
float4 norm : NORMAL )
{
vsData Out;
Out.pos = mul(pos, matWVP);
Out.norm = mul(norm, matWIT);
Out.viewDir = matVI[3].xyz - pos.xyz;
return Out;
}
float4 fs_CubeMap( vsData In ) : COLOR0
{
float3 normalNormalized = normalize(In.norm);
float3 viewDirNormalized = normalize(In.viewDir);
return texCUBE(cubeSampler, reflect(viewDirNormalized, normalNormalized));
}
technique Cubemap
{
pass p0
{
VertexShader = compile vs_1_1 vs_CubeMap();
PixelShader = compile ps_2_0 fs_CubeMap();
}
}