After long stupid testings, I managed to get shader working. But, I have first-person camera, and I need to see my player mirrored in
vertical mirror. So far, this shader works only for horizontal surface. I'm currently trying to adapt it for vertical, but with no
luck for few hours. If someone has made it already, please, share. Or I'll post working sample here if I ever finish it myself.
MATERIAL* mtl_floor_mirror =
{
effect="floorMirror.fx";
}
//enable: Mirror debugging
//help: Make mirror view visible by pressing F11
//id: 22
//#define MIRROR_DEBUG
#ifdef MIRROR_DEBUG
VIEW* view_mirror = { layer = 1; }
#else
VIEW* view_mirror = { layer = -1; } // render mirror view before camera view
#endif
BMAP* bmap_mirrortarget = NULL;
var mtlfx_mirrorvisible = 0;
//Simulate a horizontal mirror by generating
//a camera view from below through the floor
function fx_mirror()
{
// do nothing if mirror is already running
if (bmap_mirrortarget) {
my.material.skin2 = bmap_mirrortarget;
return;
}
bmap_mirrortarget = bmap_createblack(256,256,888);
my.material.skin2 = bmap_mirrortarget;
view_mirror.bmap = bmap_mirrortarget;
view_mirror.size_x = bmap_width(view_mirror.bmap);
view_mirror.size_y = bmap_height(view_mirror.bmap);
vec_set(view_mirror.pnormal_x,vector(0,0,1.0)); // reflect upwards
set(view_mirror,NOSHADOW|NOCULL|PORTALCLIP);
// suppress shadows in the mirror, look through walls, and clip at portal plane
//enable: Suppress FLAG1 in mirror
//help: Don't display FLAG1 objects in the mirror views
//id: 23
set(view_mirror,NOFLAG1); // suppress all entities with flag1 set
//enable: Suppress particles in mirror
//help: Don't display particles in the mirror views
//id: 24
set(view_mirror,NOPARTICLE);
//enable: Suppress shaders in mirror
//help: Don't render material effects in the mirror views
//id: 25
set(view_mirror,NOSHADER);
while (bmap_mirrortarget)
{
proc_mode = PROC_LATE; // camera must be moved and mtlfx_mirrorvisible set before
if (mtlfx_mirrorvisible)
{
set(view_mirror,VISIBLE);
view_mirror.genius = camera.genius;
view_mirror.aspect = (screen_size.x/screen_size.y)*camera.aspect; // screen aspect, independent of render target
view_mirror.arc = camera.arc;
view_mirror.fog_start = camera.fog_start;
view_mirror.fog_end = camera.fog_end;
view_mirror.clip_far = camera.clip_far * 0.5;
view_mirror.clip_near = camera.clip_near * 2;
view_mirror.x = camera.x;
view_mirror.y = camera.y;
view_mirror.z = 2*view_mirror.portal_z-camera.z; // move the camera at its mirror position
view_mirror.pan = camera.pan;
view_mirror.tilt = -camera.tilt; // flip the vertical camera angle
view_mirror.roll = -camera.roll;
}
else {
// switch rendering off when all mirror objects are outside the frustum
reset(view_mirror,VISIBLE);
}
mtlfx_mirrorvisible = 0;
#ifdef MIRROR_DEBUG
if (key_f11) { // debugging - make mirror visible onscreen
view_mirror.bmap = NULL;
} else {
view_mirror.bmap = bmap_mirrortarget;
}
#endif
wait(1);
}
}