EDIT:

OK. ok. She lives. AT THE MOMENT - GOD KNOWS ITS GOING TO EXPLODE AT ANY MOMENT. Superku, I tried the NOFLAG1 again and I realised for some stupid reason the waterplane model I was using had two sides (SHOOT ME). The only problem I'm dealing with right now is at certain heights, the mirror camera is catching the opposite side of the floor. Going to mess around with none flags on texture, figure something out.

Edit 2: Slipped the NOCULL back in and yeh. Good to go.

Here is what I have, in case anybody has been following this..

Keep in mind, it's tailored for the water plane to be at a Z of 0.

Water mirror
Code:
VIEW* view_mirror = { layer = -1; }  // render mirror view before camera view
BMAP* bmap_mirrortarget = NULL;
var mtlfx_mirrorvisible = 0;

function fx_mirror()
{
	if (bmap_mirrortarget)
	{
		ptr_remove(bmap_mirrortarget);	
		bmap_mirrortarget = NULL;
	}

	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|NOPARTICLE|NOCULL);
	set(view_mirror,NOFLAG1);

	while (bmap_mirrortarget)
	{
		
		proc_mode = PROC_LATE;	// camera must be moved and mtlfx_mirrorvisible set before
		if (mtlfx_mirrorvisible) 
		{ 
			set(view_mirror,SHOW);
				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;
				view_mirror.clip_near = camera.clip_near;
				view_mirror.x 	   = camera.x;
				view_mirror.y 	   = camera.y;
				view_mirror.z 	= -camera.z; // view_mirror.z = 2*view_mirror.portal_z-camera.z;
				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,SHOW); 
		}
		mtlfx_mirrorvisible = 0;
		wait(1);
	}
}

BMAP* bmap_water_uv = NULL;

function mirror_init()
{
   fx_mirror();   // create a mirror view, set mirror target to mtl.skin2
	while (1)
	{
		if (!is(my,CLIPPED))
		{
			vec_for_max(view_mirror.portal_x,my);
			vec_add(view_mirror.portal_x,my.x);
			mtlfx_mirrorvisible = 1;
		}
		wait(1);
	}
}

function mirror_water_init()
{
	if (!bmap_water_uv)
	{
	   bmap_water_uv = bmap_to_uv(bmap_create("water.dds"));
   }
   mtl.skin1 = bmap_water_uv;
   mtl.flags |= TRANSLUCENT;
	mirror_init();	// activate mirror view
}

MATERIAL* mtl_mirrorWater =
{
	effect = "mirrorWater.fx";
	event = mirror_water_init;
}

action fx_mirrorWater()
{
	my.skill20 = 1;
	set(my,PASSABLE);
	set(my,FLAG1);
	my.material = mtl_mirrorWater;
   mtl_setup(80,80,80,80);//80
}



Material for objects to be reflected.
>> I couldn't get a variable to float into the shader, so I just have the clip at a Z of 0.

Code:
MATERIAL* mtl_specBumpymr22 =
{
	diffuse_red = 255;
	diffuse_blue = 255;
	diffuse_green = 255;	
	specular_blue = 255;	// bright specular component
	specular_green = 255;
	specular_red = 255;
	ambient_red = 0;
	ambient_blue = 0;
	ambient_green = 0;
	effect = "mirrorbump.fx";
	flags = PASS_SOLID;
}
 function mtl_event_render2()
{
 	if (render_view != camera)
 	{
 		mtl = mtl_specBumpymr22;
 		return(0);
 	}
 }

MATERIAL* bump_mirror =
{
	diffuse_red = 255;
	diffuse_blue = 255;
	diffuse_green = 255;	
	specular_blue = 255;	// bright specular component
	specular_green = 255;
	specular_red = 255;
	ambient_red = 0;
	ambient_blue = 0;
	ambient_green = 0;
	event = mtl_event_render2;
	flags = ENABLE_RENDER | PASS_SOLID;
	effect = "specBump.fx";
}



mirrorbump.fx
Code:
// Tweakables: 
static const float AmbientIntensity  = 1.0f; // The intensity of the ambient light. 
static const float DiffuseIntensity = 1.0f;  // The intensity of the diffuse light. 
static const float SpecularIntensity = 1.0f; // The intensity of the specular light. 
static const float SpecularPower = 8.0f;     // The specular power. Used as 'glossyness' factor. 
static const float4 SunColor = {0.0f, 0.0f, 0.0f, 0.0f}; // Color vector of the sunlight. 

float water_height;
  
// Application fed data: 
const float4x4 matWorldViewProj; // World*view*projection matrix. 
const float4x4 matWorld; // World matrix. 
const float4 vecAmbient; // Ambient color. 
const float4 vecSunDir;  // Sun light direction vector. 
const float4 vecViewPos; // View position. 
    
float3x3 matTangent; // hint for the engine to create tangents in TEXCOORD2

texture mtlSkin1; 
sampler ColorMapSampler = sampler_state  // Color map sampler. 
{ 
   Texture = <mtlSkin1>; 
   MipFilter = Linear;   // required for mipmapping
}; 
    
texture mtlSkin2;  // Normal map. 
sampler NormalMapSampler = sampler_state  // Normal map sampler. 
{ 
   Texture = <mtlSkin2>; 
   MipFilter = None;   // a normal map usually has no mipmaps
}; 

// Vertex Shader: 
void NormalMapVS( in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float3 InTex: TEXCOORD0, 
   in float4 InTangent: TEXCOORD2, 
   out float4 OutPos: POSITION, 
   out float3 OutTex: TEXCOORD0, 
   out float3 OutViewDir: TEXCOORD1, 
   out float3 OutSunDir: TEXCOORD2) 
{ 

// Transform the vertex from object space to clip space: 
   OutPos = mul(InPos, matWorldViewProj); 
// Pass the texture coordinate to the pixel shader: 
   OutTex = InTex;
   OutTex.z = mul(InPos,matWorld).y;
// Compute 3x3 matrix to transform from world space to tangent space: 
   matTangent[0] = mul(InTangent.xyz, matWorld); 
   matTangent[1] = mul(cross(InTangent.xyz, InNormal)*InTangent.w, matWorld); 
   matTangent[2] = mul(InNormal, matWorld); 
// Calculate the view direction vector in tangent space: 
   OutViewDir = normalize(mul(matTangent, (vecViewPos - mul(InPos,matWorld)))); 
// Calculate the light direction vector in tangent space: 
   OutSunDir = normalize(mul(matTangent, -vecSunDir)); 
} 
 
// Pixel Shader: 
float4 NormalMapPS(
   in float3 InTex: TEXCOORD0, 
   in float3 InViewDir: TEXCOORD1, 
   in float3 InSunDir: TEXCOORD2): COLOR 
{ 
	clip(InTex.z);//water_height_var
// Read the normal from the normal map and convert from [0..1] to [-1..1] range 
   float3 BumpNormal = tex2D(NormalMapSampler, InTex)*2 - 1; 
// Calculate the ambient term: 
   float4 Ambient = AmbientIntensity * vecAmbient; 
// Calculate the diffuse term: 
   float4 Diffuse = DiffuseIntensity * SunColor * saturate(dot(InSunDir, BumpNormal)); 
// Calculate the reflection vector: 
   float3 R = normalize(2 * dot(BumpNormal, InSunDir) * BumpNormal - InSunDir); 
// Calculate the specular term: 
   InViewDir = normalize(InViewDir); 
   float Specular = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity; 
// Fetch the pixel color from the color map: 
   float4 Color = tex2D(ColorMapSampler, InTex); 
// Calculate final color: 
   return (Ambient + Diffuse + Specular) * Color; 
} 
 
// Technique: 
technique NormalMapTechnique 
{ 
   pass P0 
   { 
     VertexShader = compile vs_2_0 NormalMapVS(); 
     PixelShader  = compile ps_2_0 NormalMapPS(); 
   } 
}


Last edited by Stansmedia; 06/17/14 04:28.

Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en