1 registered members (AndrewAMD),
527
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: FoW Shader (deutsch/engl.)
[Re: Scorpion]
#126954
05/01/07 23:31
05/01/07 23:31
|
Joined: Oct 2003
Posts: 4,131
Matt_Aufderheide
Expert
|
Expert
Joined: Oct 2003
Posts: 4,131
|
there are a number of ways to do fog of war, the most "correct" way is to make a projection matrix that covers the whole playing area, then project your fog map on top of everything, including terrain, models, etc.
if you dont know what that means, then you may want to do something different, like just blend your fog map over the terrain texture, and fade out your models seperately, though this can be hard.
or, if you deciede to have a very narrow field of view setting, like almost orthographic, you can simply overlay a large rectanlge above everything else, like a sqaure sprite, this would be mapped with the fog texture.
As far as making the fog texture, you can use pixel to bitmap to draw white pixels to a black texture, just use a proportion formula to find the pixel regions..
|
|
|
Re: FoW Shader (deutsch/engl.)
[Re: akabane]
#126957
05/03/07 20:56
05/03/07 20:56
|
Joined: Jan 2007
Posts: 1,619 Germany
Scorpion
Serious User
|
Serious User
Joined: Jan 2007
Posts: 1,619
Germany
|
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(); } }
|
|
|
|