Here is that what i have already done, but somewhere inthe deep of this script is a mistake i made and do not find...if someone of u do i would be really happy
script:
Code:
//definitions
bmap tertex1 = <veg065.pcx>;
bmap tertex2 = <ground018.pcx>;
bmap TerMap = <terrain_map.tga>;
define belongTo,skill5;
define friend,1;
define enemy,2;
define visibleRange,skill6;
entity* fowTer;
bmap* tempMap;
var fowMapArray[16384];//128x128
var oldFowMapArray[16384];
var fowMapSize = 128;
var terrainPxSize;
////////////////////////////////
material matFowTer
{
skin1 = tertex1;
skin2 = tertex2;
skin3 = TerMap;
effect="fowt.fx";
}
panel just_a_test
{
flags=visible;
}
function painMap
{
var tempPos[2];
var pixel;
var format;
tempMap=bmap_for_entity(fowTer,4);
format = bmap_lock(tempMap,0);
while(tempPos.y<fowMapSize)
{
if(fowMapArray[(fowMapSize-1)*tempPos.y+tempPos.x]!=oldFowMapArray[(fowMapSize-1)*tempPos.y+tempPos.x])
{
temp=255*((fowMapSize-1)*tempPos.y+tempPos.x);
pixel = pixel_for_vec(vector(temp,temp,temp),100,format);
pixel_to_bmap(tempMap,tempPos.x,tempPos.y,pixel);
}
tempPos.x+=1;
if(tempPos.x>fowMapSize)
{
tempPos.x=0;
tempPos.y+=1;
}
}
bmap_unlock(tempMap);
just_a_test.bmap = tempMap;
}
function check_fow
{
var tempPos[2];
var targetPos[2];
var tempRange;
while(1)
{
you=ent_next(null);
while(you!=null)
{
if(your.belongTo == friend)
{
if(your.visibleRange==0)
{
vec_Set(camera.x,your.x);
camera.z+=200;
camera.tilt=-90;
your.light = on;
your.red=255;
your.green=0;
your.blue=0;
your.scale_x = 2;
your.scale_y = 2;
your.scale_z = 2;
error("unit don't have a visibleRange");
freeze_mode=2;
}
tempRange = int(your.visibleRange/terrainPxSize+0.5);
targetPos.x = (your.x-fowTer.min_x)/terrainPxSize-tempRange;//xpos
targetPos.y = (your.y-fowTer.min_y)/terrainPxSize-tempRange;//y
while(tempPos.y<=tempRange*2)
{
temp.x=targetPos.x+tempPos.x;
temp.y=targetPos.y+tempPos.y;
breakpoint;
if(vec_dist(vector(tempRange.x,tempRange.y,0),vector(temp.x,temp.y,0))<=tempRange)
{
fowMapArray[fowMapSize*temp.y+temp.x]=1;
}
tempPos.x+=1;
if(tempPos.x>tempRange*2)
{
tempPos.x=0;
tempPos.y+=1;
}
}
}
you = ent_next(you);
}
painMap();
wait(1);
}
}
action fow_terrain
{
fowTer=me;
terrainPxSize = (my.max_x-my.min_x)/fowMapSize;//now u have the size of a pixel in quants
my.material = matFowTer;
check_fow();
}
shader:
Code:
float4x4 matWorldViewProj;
texture entSkin1;
texture entSkin2;
texture entSkin3;
texture entSkin4;
texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
sampler2D textur1 = sampler_state {Texture=<entSkin1>;};
sampler2D textur2 = sampler_state {Texture=<entSkin2>;};
sampler2D textur3 = sampler_state {Texture=<entSkin3>;};
sampler2D textur4 = sampler_state {Texture=<mtlSkin1>;};
sampler2D textur5 = sampler_state {Texture=<mtlSkin2>;};
sampler2D terrainMap = sampler_state {Texture=<mtlSkin3>;};
sampler2D fowMap = sampler_state {Texture=<entSkin4>;};
void terrainVS( in float4 pos :POSITION,
in float2 Tex :TEXCOORD0,
out float4 opos :POSITION,
out float2 texcrd :TEXCOORD0)
{
opos=mul(pos,matWorldViewProj);
texcrd=Tex;
}
float4 terrainPS(in float2 texcrd:TEXCOORD0):COLOR
{
float4 tex1 = tex2D(textur1,texcrd*20);
float4 tex2 = tex2D(textur2,texcrd*20);
float4 tex3 = tex2D(textur3,texcrd*20);
float4 tex4 = tex2D(textur4,texcrd*20);
float4 tex5 = tex2D(textur5,texcrd*20);
float4 visible = tex2D(terrainMap,texcrd);
float4 fow = tex2D(fowMap,texcrd);
tex1 = lerp(tex1,tex2,visible.r);
tex1 = lerp(tex1,tex3,visible.g);
tex1 = lerp(tex1,tex4,visible.b);
tex1 = lerp(tex1,tex5,1-visible.w);
return tex1*fow;
}
technique
{
pass p0
{
vertexShader = compile vs_2_0 terrainVS();
pixelShader = compile ps_2_0 terrainPS();
}
}