Here's a little something to play around with. Apply it to sphere's, plane's, etc..
//
// Steempipe's Basic Cubemap HLSL Shader
//
// Needs: Dx 9.00c, 3dgs v6.31+
// vertex/pixelshader v.1.1
//
//
bmap cubemap = <desertsm+6.tga>; // 6-sided cubemap
function mat_cubemap_init
{
bmap_to_cubemap(bmap_to_mipmap(mtl.skin1));
}
Material mat_cubemap
{
skin1 = cubemap;
event = mat_cubemap_init;
effect = "
float4x4 matWorldViewProj;
float4x4 matWorld;
float3 vecViewPos;
float4 vecFog;
texture mtlSkin1;
sampler sCubemap = sampler_state
{
Texture = (mtlSkin1);
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
struct VSOUT
{
float4 Position : POSITION;
float3 Reflection : TEXCOORD2;
float Fog : FOG;
};
VSOUT Cubemap_VS(float4 Position : POSITION, float3 Normal : NORMAL)
{
VSOUT Out;// = (VSOUT)0;
// Do some maths according to the entities position
float3 Position_World = mul(Position, matWorld).xyz;
float3 Normal_World = normalize(mul(Normal, (float3x3)matWorld));
// Get the View Direction
float3 Refl_Proj = Position_World - vecViewPos;
// Output the reflection vector
Out.Reflection = reflect(Refl_Proj, Normal_World);
// Output postition in clipping space
Out.Position = mul(Position, matWorldViewProj);
// Output fog to the fogtable
float ofog = 1 - (distance(Position_World, vecViewPos) - vecFog.x) * vecFog.z;
Out.Fog = ofog;
// Output all
return Out;
}
float4 Cubemap_PS(float3 Reflection : TEXCOORD2) : COLOR
{
// Perform 3D cube-texture lookup
float4 tex0 = texCUBE(sCubemap, Reflection);
// Output Texture
return tex0;
}
technique Cubemap
{
pass P0
{
vertexShader = compile vs_1_1 Cubemap_VS();
PixelShader = compile ps_1_1 Cubemap_PS();
}
}
";
}
action hlsl_cubemap
{
my.material = mat_Cubemap;
}