ok thank you omaremad.
I changed it back to a vec4, but still getting the same results
I have written a test outside of my framework, so it can be easily copied and pasted, if you or anyone else has the time to try to help me out with it.
It is a sphere and a plane, with an arrow showing the location and direction of the light and shadow camera. Here is a screen shot.
And here is the simplified code.
Code: Select all
# include <Irrlicht.h>
#pragma comment (lib,"Irrlicht.lib")
int main()
{
///// make all the Irrlicht pointers ///////
irr::IrrlichtDevice *device = irr::createDevice( irr::video::EDT_OPENGL,
irr::core::dimension2d<irr::s32>(800,600),
32,
true,
false,
true
);
irr::video::IVideoDriver *driver = device->getVideoDriver();
irr::scene::ISceneManager *scenemanager = device->getSceneManager();
irr::video::IGPUProgrammingServices *gpu = driver->getGPUProgrammingServices();
///////////////////////////////////////////
///// add the lights and cameras /////////
irr::scene::ILightSceneNode *light = scenemanager->addLightSceneNode ();
light->setPosition(irr::core::vector3df(20,20,0));
irr::scene::ICameraSceneNode *shadowCam = scenemanager->addCameraSceneNode();
shadowCam->setPosition(irr::core::vector3df(20,20,0));
shadowCam->setTarget (irr::core::vector3df(0,0,0));
irr::scene::IAnimatedMeshSceneNode *arrowNode = scenemanager->addAnimatedMeshSceneNode(scenemanager->addArrowMesh("arrow",irr::video::SColor(255,50,75,250),irr::video::SColor(255,150,175,250),4,8,2,.6f,.05f,.3f));
arrowNode->setMaterialFlag(irr::video::EMF_LIGHTING,false);
arrowNode->setPosition(light->getPosition());
arrowNode->setRotation(irr::core::vector3df(0,0,135));
arrowNode->setScale(irr::core::vector3df(3,3,3));
irr::scene::ICameraSceneNode *renderCam = scenemanager->addCameraSceneNodeFPS();
renderCam->setPosition(irr::core::vector3df(0,25,-50));
renderCam->setTarget (irr::core::vector3df(0,0,0));
/////////////////////////////////////////
//// add a sphere //////////////////////
irr::scene::IAnimatedMesh *sphereMesh = scenemanager->addSphereMesh("sphere",5.0f,32,32);
irr::scene::IAnimatedMeshSceneNode *sphereNode = scenemanager->addAnimatedMeshSceneNode(sphereMesh);
sphereNode->getMaterial(0).DiffuseColor.set(255,250,75,50);
sphereNode->setPosition(irr::core::vector3df(0,5,0));
///////////////////////////////////////
///// create the render target////////
irr::video::ITexture *renderTarget = driver->createRenderTargetTexture(irr::core::dimension2di(512,512));
//// build the matrix to hopefully project the shadow /////////////
irr::core::matrix4 tMatrix;
tMatrix=shadowCam->getProjectionMatrix();// the light's projection
tMatrix *= shadowCam->getViewMatrix(); // the lights view
tMatrix *= sphereNode->getAbsoluteTransformation();// the sceneNode's position
tMatrix.setTranslation(irr::core::vector3df(0.5f,0.5f,0.0f));// translation and scale
tMatrix.setScale(irr::core::vector3df(0.5f,0.5f,1.0f)); // to make it 0-1
////////////////////////////////////
/////add the plane/////////////////
irr::s32 shader;
shader = gpu->addHighLevelShaderMaterialFromFiles( "VERT.vert",
"main",
irr::video::EVST_VS_2_0,
"FRAG.frag",
"main",
irr::video::EPST_PS_2_0,
NULL,
irr::video::EMT_SOLID,
0
);
irr::video::SMaterial planeMaterial;
planeMaterial.MaterialType = (irr::video::E_MATERIAL_TYPE)shader;
planeMaterial.DiffuseColor.set(255,50,250,75);
planeMaterial.setTexture(0,renderTarget); // set the renderTarget texture
planeMaterial.setTextureMatrix(0,tMatrix);// set the lights view projection matrix
irr::scene::IAnimatedMesh *planeMesh = scenemanager->addHillPlaneMesh("plane",irr::core::dimension2df(100.0f,100.0f),irr::core::dimension2d<irr::u32>(1,1),&planeMaterial);
irr::scene::IAnimatedMeshSceneNode *planeNode = scenemanager->addAnimatedMeshSceneNode (planeMesh);
/////////////////////////////////////
while (device->run())
{
driver->beginScene(true,true,0);
//////// shadow pass ////////////
scenemanager->setActiveCamera(shadowCam);
driver->setRenderTarget(renderTarget, true, true, irr::video::SColor(255,255,255,255));
shadowCam->render();
sphereNode->render();
/////// render pass ///////////
scenemanager->setActiveCamera(renderCam);
driver->setRenderTarget(0,true,true,0);
scenemanager->drawAll();
driver->endScene();
}
device->drop();
}
These are the only 2 external files, the shader for projecting the texture. SUper simple.
Code: Select all
// vertex shader
varying vec4 TexCoord;
void main()
{
gl_Position = ftransform();
TexCoord = gl_TextureMatrix[0] * gl_Vertex;
}
Code: Select all
// pixel shader
uniform sampler2D renderTarget;
varying vec4 TexCoord;
varying vec4 Color;
void main()
{
vec4 Light = texture2DProj(renderTarget,TexCoord);
gl_FragColor = Light;
}
Please take just a few moments with this example? I made it as short as I could. What more am I missing?