hmmm I'm still having problems, not sure if anyone can help but I have just reached a complete dead end, it seems (to me) that the cubemap isn't being rendered properly, I assume it is the camera/matrices that is the problem but I can't figure out whta I need to do..?
Here is a screen, as you can see the 'reflection' is HUGE and it seems to be offset
http://img90.imageshack.us/img90/787/cubeza1.png
Here is my code that renders to the 6 faces of the cubemap
Code: Select all
if((framecount%5)==0)
{
framecount=0;
plane->setVisible(false);
for( u32 i=0; i<6; i++ )
{
// Standard view that will be overridden below.
core::vector3df vEnvEyePt = plane->getAbsolutePosition();
fixedCam->setPosition(vEnvEyePt);
core::vector3df vLookatPt, vUpVec;
switch( i )
{
case 0:
vLookatPt = vEnvEyePt + core::vector3df( 1.0f, 0.0f, 0.0f );
vUpVec = core::vector3df( 0.0f, 1.0f, 0.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
case 1:
vLookatPt = vEnvEyePt + core::vector3df(-1.0f, 0.0f, 0.0f );
vUpVec = core::vector3df( 0.0f, 1.0f, 0.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
case 2:
vLookatPt = vEnvEyePt + core::vector3df( 0.0f, 1.0f, 0.0f );
vUpVec = core::vector3df( 0.0f, 0.0f,-1.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
case 3:
vLookatPt = vEnvEyePt + core::vector3df( 0.0f,-1.0f, 0.0f );
vUpVec = core::vector3df( 0.0f, 0.0f, 1.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
case 4:
vLookatPt = vEnvEyePt + core::vector3df( 0.0f, 0.0f, 1.0f );
vUpVec = core::vector3df( 0.0f, 1.0f, 0.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
case 5:
vLookatPt = vEnvEyePt + core::vector3df( 0.0f, 0.0f,-1.0f );
vUpVec = core::vector3df( 0.0f, 1.0f, 0.0f );
fixedCam->setTarget(vLookatPt);
fixedCam->setUpVector(vUpVec);
break;
}
core::matrix4 proj;
proj.buildProjectionMatrixPerspectiveFovLH(core::PI/2, 1.0, 1.0, 2000.0);
fixedCam->setProjectionMatrix(proj);
smgr->setActiveCamera(fixedCam);
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTargetCubeFace(texCubeMap, i, true, true, video::SColor(255,255,255,255));
//Draw scene manager
smgr->drawAll();
driver->setRenderTarget(0, true, true, video::SColor(255,113,113,133));
}
smgr->setActiveCamera(fpsCam);
}
plane->setVisible(true);
Tho I don't actaully believe there are any problems with the shader that applies the cubemap (it works fine in rendermonkey) here is all the relevant shader stuff
Code: Select all
#line 2 "cubemap.hlsl"
float4x4 view_proj_matrix;
float4 view_position;
struct VS_OUTPUT
{
float4 Pos: POSITION;
float3 Reflect: TEXCOORD0;
};
VS_OUTPUT vs_main(float4 inPos: POSITION, float3 inNormal: NORMAL)
{
VS_OUTPUT Out;
// Compute the projected position and send out the texture coordinates
Out.Pos = mul(inPos,view_proj_matrix);
//Out.TexCoord = inTxr;
float4 look = inPos-view_position;
// Compute the reflection vector
Out.Reflect = reflect(normalize(look),inNormal);
return Out;
}
sampler EnvMap;
float4 ps_main(float3 inReflect: TEXCOORD0) : COLOR
{
// Output texture color with reflection map
return texCUBE(EnvMap,inReflect);
}
Code: Select all
virtual void OnSetConstants(video::IMaterialRendererServices* services, s32 userData)
{
video::IVideoDriver* driver = services->getVideoDriver();
core::matrix4 worldViewProj;
worldViewProj = driver->getTransform(video::ETS_PROJECTION);
worldViewProj *= driver->getTransform(video::ETS_VIEW);
worldViewProj *= driver->getTransform(video::ETS_WORLD);
services->setVertexShaderConstant("view_proj_matrix", &worldViewProj.M[0], 16);
core::vector3df pos = device->getSceneManager()->
getActiveCamera()->getPosition();
video::SColorf campos(pos.X, pos.Y, pos.Z, 1.0f);
services->setVertexShaderConstant("view_position", reinterpret_cast<f32*>(&campos), 4);
}
Code: Select all
MyShaderCallBack* mc = new MyShaderCallBack();
newMaterialType1 = gpu->addHighLevelShaderMaterialFromFiles(
"../../media/cubemap.hlsl", "vs_main", video::EVST_VS_2_0,
"../../media/cubemap.hlsl", "ps_main", video::EPST_PS_2_0,
mc, video::EMT_SOLID);
I'd really appreciate any suggestions because this has started driving me mad! Thanks