Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,038 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 4 1 2 3 4
Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281340
07/26/09 19:44
07/26/09 19:44
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
Here is a lite-c version of the code. changed the way its working a little bit. now you have to pass the pointer to the terrain entity, instead of using 'me'.

Code:
BMAP* canvas;
ENTITY* p_terrain;
VECTOR canvas_size;
var shadow_brightness=112; 

//-----------------------------------------------------------------------------blur
void blur(passes)
{
  var i;
  var px;
  var py;
  var format;
  var pixel;
  VECTOR pixelcolor;
  var pixelalpha;
  VECTOR sample1;
  VECTOR sample2;
  VECTOR sample3;
  VECTOR sample4;
  VECTOR sample5;
  VECTOR sample6;
  VECTOR sample7;
  VECTOR sample8;
  VECTOR sample9; 

  i=0;
  while(i<passes)
  {
    py=0;
    while(py < canvas_size.y)
    {
     px=0;
      while(px<canvas_size.x)
      {
        format=bmap_lock(canvas,0); 

        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px,0,canvas_size.x-1),clamp(py,0,canvas_size.x-1));
        pixel_to_vec(sample1,pixelalpha,format,pixel);

        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px-1,0,canvas_size.x-1),clamp(py,0,canvas_size.x-1));
        pixel_to_vec(sample2,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px-1,0,canvas_size.x-1),clamp(py+1,0,canvas_size.x-1));
        pixel_to_vec(sample3,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px,0,canvas_size.x-1),clamp(py+1,0,canvas_size.x-1));
        pixel_to_vec(sample4,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px+1,0,canvas_size.x-1),clamp(py+1,0,canvas_size.x-1));
        pixel_to_vec(sample5,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px+1,0,canvas_size.x-1),clamp(py,0,canvas_size.x-1));
        pixel_to_vec(sample6,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px+1,0,canvas_size.x-1),clamp(py-1,0,canvas_size.x-1));
        pixel_to_vec(sample7,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px,0,canvas_size.x-1),clamp(py-1,0,canvas_size.x-1));
        pixel_to_vec(sample8,pixelalpha,format,pixel);
        pixel=pixel_for_bmap(canvas,clamp((canvas_size.x-1)-px-1,0,canvas_size.x-1),clamp(py-1,0,canvas_size.x-1));
        pixel_to_vec(sample9,pixelalpha,format,pixel);

        pixelcolor.x=integer((sample1.x*7+sample2.x*2+sample3.x+sample4.x*2+sample5.x+sample6.x*2+sample7.x+sample8.x*2+sample9.x)/19);
        pixelcolor.y=integer((sample1.y*7+sample2.y*2+sample3.y+sample4.y*2+sample5.y+sample6.y*2+sample7.y+sample8.y*2+sample9.y)/19);
        pixelcolor.z=integer((sample1.z*7+sample2.z*2+sample3.z+sample4.z*2+sample5.z+sample6.z*2+sample7.z+sample8.z*2+sample9.z)/19);

        pixel=pixel_for_vec(pixelcolor,100,format);
        pixel_to_bmap(canvas,(canvas_size.x-1)-px,py,pixel);

        bmap_unlock(canvas);

        px+=1;
      }
      py+=1;
      wait(1); // without a wait after each line the loop could get too big if the shadow map is huge
    } 
    i+=1;
  }
}

//-----------------------------------------------------------------------------generate_shadows
void getxyz(px, py, VECTOR* pos)
{
  VECTOR pixel_size;
  pixel_size.x = (p_terrain.max_x-p_terrain.min_x)/canvas_size.x;
  pixel_size.y = (p_terrain.max_y-p_terrain.min_y)/canvas_size.y;
  pos.x = ((p_terrain.x-p_terrain.min_x)-(pixel_size.x*px))-pixel_size.x*0.5;
  pos.y = ((p_terrain.y-p_terrain.min_y)-(pixel_size.y*py))-pixel_size.y*0.5;
  c_trace(vector(pos.x, pos.y, p_terrain.z+50000), vector(pos.x, pos.y, p_terrain.z-50000), IGNORE_MODELS|IGNORE_SPRITES|IGNORE_MAPS);
  pos.z=target.z;
}

void generate_shadows()
{
  var px;
  var py;
  var format;
  var pixel; 

	me = p_terrain;

  py=0;
  while(py<canvas_size.y)
  {
    px=0;
    while(px<canvas_size.x)
    { 
      VECTOR pos;
      
      getxyz(px, py, pos); // get the world coordinates of the pixel
      c_trace(sun_pos.x, pos, IGNORE_ME|IGNORE_SPRITES); // trace from the sun to the pixel
      if(trace_hit) // draw shadow pixel if there is no obstacle
      {
        format=bmap_lock(canvas,0);

        pixel=pixel_for_vec(vector(shadow_brightness,shadow_brightness,shadow_brightness),100,format);
        pixel_to_bmap(canvas,(canvas_size.x-1)-px,py,pixel);

        bmap_unlock(canvas);
      }
      px+=1;
    }
    py+=1;
    wait(1); // without a wait after each line the loop could get too big if the shadow map is huge
  }
  blur(1); // do 1 blur pass
}

//-----------------------------------------------------------------------------terrain
void terrain(ENTITY* ent)
{
  p_terrain = ent;
//  my.material=mtl_terrainshadowmap;

  canvas = bmap_for_entity(ent,2); // the second texture of the terrain is the shadowmap
  canvas_size.x = bmap_width(canvas);
  canvas_size.y = bmap_height(canvas);

  generate_shadows();
}

//here is a simple example material. the first texture of the terrain has to be the color map (the tiling can be specified with the texture transformation matrix). the second texture of the terrain has to be the shadow map.


//-----------------------------------------------------------------------------materials
//MATERIAL* mtl_terrainshadowmap = 
//{
//  effect=
//  "
//  texture entSkin1;
//  texture entSkin2;
//
//  technique one_pass_shadow
//  {
//    pass p0
//    {
//      Texture[0]=<entSkin1>;
//      Texture[1]=<entSkin2>;
// 
//      ColorArg1[0]=Texture;
//      ColorOp[0]=Modulate2x;
//      ColorArg2[0]=Diffuse;
//      TexCoordIndex[0]=0;
//      TextureTransformFlags[0]=Count2;
//      TextureTransform[0]={1.0,0.0,0.0,0.0, // color map u scale
//                           0.0,1.0,0.0,0.0, // color map v scale
//                           0.0,0.0,0.0,0.0,
//                           0.0,0.0,0.0,0.0};
//
//      ColorArg1[1]=Texture;
//      ColorOp[1]=Modulate;
//      ColorArg2[1]=Current;
//      TexCoordIndex[1]=0;
//      TextureTransformFlags[1]=Count2;
//      TextureTransform[1]={1.0,0.0,0.0,0.0,
//                           0.0,1.0,0.0,0.0,
//                           0.0,0.0,0.0,0.0,
//                           0.0,0.0,0.0,0.0};
//    }
//  }
//  ";
//}
//



Re: Will do free coding - if contented donations are welcome [Re: Scorpion] #281354
07/26/09 20:40
07/26/09 20:40
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
THanks a lot! Got it working, although the shadow doesn't fit.
I load up an example to test with.

EDIT:

Here is the testing environement:

http://www.puppenheim.org/Shadow_Mapping_Testing.zip

with the test_terrain.hmp I got at the last time 4 little shadows in 4 directions. With the terrain_relief.mdl I got one a bit too big shadow.

Last edited by Pappenheimer; 07/26/09 20:48.
Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281356
07/26/09 20:52
07/26/09 20:52
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
I didn't changed the way it's working (afaik^^) and I also wondered a bit, why the shadows are that big, but i will look into it.

EDIT: okay I looked into it and you just didn't applied a correct shader. normally the 2nd skin is used as a tiled detailmap. If you use the example shader given with the code, it works fine. I just uploaded it again to proof that its working:

http://rapidshare.com/files/260375668/smtest.zip

Last edited by Scorpion; 07/26/09 21:31. Reason: got it! =)
Re: Will do free coding - if contented donations are welcome [Re: Scorpion] #281366
07/26/09 21:36
07/26/09 21:36
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Hm, wanted to get it working with the second skin map, though! blush

Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281369
07/26/09 21:46
07/26/09 21:46
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
it does work with the second skin, what do you mean?

Re: Will do free coding - if contented donations are welcome [Re: Scorpion] #281371
07/26/09 21:53
07/26/09 21:53
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
I mean, without shader/material.
My hope was to use it for mdls as well, with any shape and atlas mapping.

Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281372
07/26/09 21:55
07/26/09 21:55
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
BTW, it doesn't actually save the shadowmap, right?

EDIT:
It is easy:
bmap_save(canvas,"result.png");


Last edited by Pappenheimer; 07/26/09 22:01.
Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281380
07/26/09 22:43
07/26/09 22:43
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
i just converted the script i didn't add extras.

For using the script with any model you like you have to find a way to get the xyz position of uv coordinates. everything else is easy. I will look into this in a few hours ('tomorrow')

and why don't you like the idea of materials? it's a ffp effect, so it'S aviable with every version and isn't more complicated than the normal engine materials (which are in fact also ffp shaders afaik)

Re: Will do free coding - if contented donations are welcome [Re: Scorpion] #281384
07/26/09 22:57
07/26/09 22:57
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Originally Posted By: Scorpion
i just converted the script i didn't add extras.

I know, I don't want to sound as if I complain! smile
Originally Posted By: Scorpion
For using the script with any model you like you have to find a way to get the xyz position of uv coordinates. everything else is easy. I will look into this in a few hours ('tomorrow')


That's great. If you find a way to do it, that's fantastic. If it costs too much time, you already got the terrain part running. Thank you for that very much.

Originally Posted By: Scorpion
and why don't you like the idea of materials? it's a ffp effect, so it'S aviable with every version and isn't more complicated than the normal engine materials (which are in fact also ffp shaders afaik)

I thought it restricts to a certain uv-mapping which wouldn't work with the individual uv-layout of the most models.

Re: Will do free coding - if contented donations are welcome [Re: Pappenheimer] #281515
07/27/09 15:43
07/27/09 15:43
Joined: Jan 2007
Posts: 1,619
Germany
Scorpion Offline OP
Serious User
Scorpion  Offline OP
Serious User

Joined: Jan 2007
Posts: 1,619
Germany
I tried to look in it, but the only possible way to find the xyz position of a uv coordinate (if there's any or there are more than one) is to access the triangles of the modell afaics. thats only possible with functions of the dx-sdk and i am not that deep in it to do that.

Page 2 of 4 1 2 3 4

Moderated by  checkbutton, Inestical, Perro 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1