Original Post
I recently started to play around with HLSL shaders. I'm currently trying to make real simple water, with bump mapping and cubempa reflection. Now my problem is with that actual cubemap reflection. The code is pretty simple, and for once I undertsand it all. However, it seems to procude strange results. I find it quite annoying because nobody seems to have problems and I do, and I just can't point the source. So I wondered if any of you pros could help me ;). I've put two screenshots to show the results. I apply the shader on a simple square made from 4 vertices with their normal upward (0, 1, 0). This screen shot shows how the cubemap projection on the plane just mess up when the camera is positionned according to particular angles. http://img21.imageshack.us/img21/6876/screen1tso.th.jpg The second one shows the main problem, it seems that something's wrong with the coords interpolation between the opposite corners. There is clearly (easier to see when its moving) a seem between the two triangles. http://img21.imageshack.us/img21/238/screen2uhk.th.jpg I've put the HLSL code here, you'll see that it's quite simple. Basically, I compute the view direction by substracting the eye position (camera position) from the vertex position, both in world space. I use this view direction along with the normal (which i'll recall is always (0,1,0)) to get a reflection vector which is actually used as my 3d coords for the cubemap. So, any idead why that wouldn't work ? P.S. : The cubemap has nothing to do with the skybox, it's normal :P [Edited by - GLForce on April 17, 2009 4:54:05 PM]
float4x4 WorldViewProj : WORLDVIEWPROJ;
float4x4 World : WORLD;
float ElapsedTime;
float3 Eye;
texture ReflectionTexture;
samplerCUBE ReflectionSampler : TEXUNIT3 = sampler_state
{
Texture = (ReflectionTexture);
MIPFILTER = LINEAR;
MINFILTER = LINEAR;
MAGFILTER = LINEAR;
};
struct VS_IN
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 Texture : TEXCOORD0;
};
struct VS_OUT
{
float4 Position : POSITION;
float3 Texture0 : TEXCOORD0;
};
struct PS_OUT
{
float4 Color : COLOR0;
};
VS_OUT vs_func(in VS_IN In)
{
VS_OUT Out;
Out.Position = mul(In.Position, WorldViewProj);
float3 WorldPos = mul(In.Position, World).xyz;
float3 WEye = mul(World, Eye);
float3 V = normalize(WorldPos - Eye);
float3 Normal = normalize(mul(World, In.Normal));
Out.Texture0 = reflect(V, Normal);
return Out;
}
PS_OUT ps_func(in VS_OUT In)
{
PS_OUT Out;
float4 color = texCUBE(ReflectionSampler, In.Texture0);
Out.Color = color;
return Out;
}
technique Technique0
{
pass p0
{
FogEnable = FALSE;
Lighting = FALSE;
Sampler[0]= (ReflectionSampler);
VertexShader = compile vs_1_1 vs_func();
PixelShader = compile ps_2_0 ps_func();
}
}
