Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, Ayumi, 7th_zorro), 877 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 3 of 4 1 2 3 4
Re: Vegetation Template [Re: MadJack] #225848
09/06/08 11:26
09/06/08 11:26
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Wow! very nice MadJack smile
How did you do it? Hit.rgb?

Re: Vegetation Template [Re: Emre] #225851
09/06/08 12:08
09/06/08 12:08
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
In your "terrain" action, instead of a "while" loop to create the trees, I open my BMP file and work on the rgb component of each pixel.
You'll see it soon, I'll give my script here or in the Lite-C contribution forum.

I just want to clean and complete it before grin

BTW, maybe I should say YOUR code with slight changes smile


Commercial A7.25b
RUGod
Re: Vegetation Template [Re: MadJack] #225866
09/06/08 13:28
09/06/08 13:28
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
Tree channels working now:





Commercial A7.25b
RUGod
Re: Vegetation Template [Re: MadJack] #225900
09/06/08 16:17
09/06/08 16:17
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
OK, this is the function I use :
Code:
function set_decor()
{
	var      aFormat; 
	var      aAlpha;
	var      aPixel;
	var      i,j,k;
	var      aChannel;
	COLOR    aColor;
	var      aStep_x, aStep_y;
	var      nb_obj;
	float    aMaxRed = 0;
	float    aMaxGreen = 0;
	float    aMaxBlue = 0;
	float    aDensityRed = 0;
	float    aDensityBlue = 0;
	float    aDensityGreen = 0;
	float    aDensityDec = 0;
	
	var dens_red[256];
	var dens_blue[256];
	var dens_green[256];
	
	var aSide_x, aSide_y;
	
	BMAP* texv = "vegetation.bmp";   // Vegetation - Rocks density map 
                                         // Format = BMP   type RGB 24 bits
                                         // Size is what you want BUT 128x128 is enough
	
	aSide_x = bmap_width (texv);
	aSide_y = bmap_height (texv);
	
	aStep_x = (my.max_x - my.min_x)/aSide_x ;
	aStep_y = (my.max_y - my.min_y)/aSide_y ;
	
	aFormat = bmap_lock(texv,0);
	
	for (i=0; i < 256; i++) 
	{
		dens_red[i] = 0;
		dens_blue[i] = 0;
		dens_green[i] = 0;
	}
	
	for (i=0; i < aSide_x; i++) 
	{
		for (j=0; j < aSide_y; j++)
		{
			aPixel = pixel_for_bmap(texv,i,j);
			pixel_to_vec(aColor, aAlpha, aFormat, aPixel);
			
			dens_red[aColor.red]++;
			dens_blue[aColor.blue]++;
			dens_green[aColor.green]++;
		}
	}

	for (i=0; i < 256; i++) 
	{
		aMaxRed 		+= i * dens_red[i];
		aMaxGreen 	+= i * dens_green[i];
		aMaxBlue		+= i * dens_blue[i];
	}

	if (aMaxRed > 0) aDensityRed = tree_number / aMaxRed;
	if (aMaxGreen > 0) aDensityGreen = bush_number / aMaxGreen;
	if (aMaxBlue > 0) aDensityBlue = rock_number / aMaxBlue;
	
	for (i=0; i < aSide_x; i++) 
	{
		for (j=0; j < aSide_y; j++)
		{
			aPixel = pixel_for_bmap(texv,i,j);
			pixel_to_vec(aColor, aAlpha, aFormat, aPixel);
			
			aChannel = aColor.red;
			if (aChannel > 0)
			{
				aMaxRed = aChannel * aDensityRed;
				nb_obj = integer (aMaxRed);
				
				aDensityDec = aMaxRed - nb_obj;
				
				if (aDensityDec > random(1)) nb_obj++;
				
				for (k=0; k<nb_obj; k++) 
				{
					if (number_tree < tree_number)
					{
						ent_create(tree1, vector(my.min_x + i*aStep_x + random(aStep_x),	my.max_y  - j*aStep_y - random(aStep_y),my.z+8300), tree_func);
						ent_create(tree2, vector(my.min_x + i*aStep_x + random(aStep_x),	my.max_y  - j*aStep_y - random(aStep_y),my.z+8300), tree_func);
						ent_create(tree3, vector(my.min_x + i*aStep_x + random(aStep_x),	my.max_y  - j*aStep_y - random(aStep_y),my.z+8300), tree_func);
						number_tree+=1;
					}
					
				}
				
			}
			
			aChannel = aColor.blue;
			if (aChannel > 0)
			{
				aMaxBlue = aChannel * aDensityBlue;
				nb_obj = integer (aMaxBlue);
				
				aDensityDec = aMaxBlue - nb_obj;
				
				if (aDensityDec > random(1)) nb_obj++;
				
				for (k=0; k<nb_obj; k++) 
				{
					if (number_rock < rock_number)
					{
						ent_create(rock1, vector(my.min_x + i*aStep_x + random(aStep_x),	my.max_y  - j*aStep_y - random(aStep_y),my.z+8300), rock_func);
						number_rock+=1;
					}
					
				}
				
			}
			aChannel = aColor.green;
			if (aChannel > 0)
			{
				aMaxGreen = aChannel * aDensityGreen;
				nb_obj = integer (aMaxGreen);
				
				aDensityDec = aMaxGreen - nb_obj;
				
				if (aDensityDec > random(1)) nb_obj++;
				
				for (k=0; k<nb_obj; k++) 
				{
					if (number_bush < bush_number)
					{
						ent_create(bush1, vector(my.min_x + i*aStep_x + random(aStep_x),	my.max_y  - j*aStep_y - random(aStep_y),my.z+8300), bush_func);
						number_bush+=1;
					}
					
				}
				
			}
		}
	}

	bmap_unlock(texv);

}


This code is supposed to work with the code given here by Emre
You just need to modify terrain action :
Code:
action Terrain()
{
	my.material=multirgb;
	set(my,UNLIT);
	//section:Terrain Coordinate
	//entry:Minimum x
	my.min_x=-3000;//5295//4081
	//entry:Maximum x
	my.max_x=3000;//4566//3041
	//entry:Minimum y
	my.min_y=-3000;//5200//4053
	//entry:Maximum y
	my.max_y=3000;//4500//3300
	//image:help.bmp
	
	bush2_load();
	
	set_decor();
	
}


It replace, bush_load, rock_load and the tree load part.
Bush2_load could also be done using the alpha channel of the bitmap.

Last edited by MadJack; 09/06/08 19:44.

Commercial A7.25b
RUGod
Re: Vegetation Template [Re: MadJack] #225935
09/06/08 19:29
09/06/08 19:29
Joined: Jul 2007
Posts: 619
Turkey, Izmir
Emre Offline OP
User
Emre  Offline OP
User

Joined: Jul 2007
Posts: 619
Turkey, Izmir
Thank you very much MadJack!
It's really, really very nice.
Thanks for your effort, and sharing. smile

Re: Vegetation Template [Re: Emre] #225939
09/06/08 19:49
09/06/08 19:49
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
Thanks to you too wink

There was a mistake in my code, all the entities functions were "tree_func", I have edited now, even if it was funny to see rocks like floating on lava grin


Commercial A7.25b
RUGod
Re: Vegetation Template [Re: MadJack] #225970
09/06/08 23:27
09/06/08 23:27
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
Blink Offline

Expert
Blink  Offline

Expert

Joined: Jan 2006
Posts: 2,157
Connecticut, USA
is the c-script version for shader model 3.0 only? i am getting a strange error. i only have shader model 2.0. the error says something about a d3d buffer. and points to line 435 in the wdl.


My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
Re: Vegetation Template [Re: Blink] #226007
09/07/08 09:25
09/07/08 09:25
Joined: Jun 2005
Posts: 87
France
MadJack Offline
Junior Member
MadJack  Offline
Junior Member

Joined: Jun 2005
Posts: 87
France
  • This function is in Lite-C.
  • It is developped to work within Emre contribution, but as I needed to clearly see the vegetation distribution, I use a specific main file ("test.c") very simplified (whithout D3D functions)
  • I have no problem by testing from SED -> test.c -> run test with current file
  • The only error message I get is when I try it from WED -> run
  • No problem when using it in my own project (Loopix based)
  • There is no shader used in the function itself, only lite-c script

From there, I can't help you more, sorry, but I can give you my full test project sources here (6.6 Mo):
Test vegetation + density


Commercial A7.25b
RUGod
Re: Vegetation Template [Re: MadJack] #226269
09/08/08 19:21
09/08/08 19:21
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
Blink Offline

Expert
Blink  Offline

Expert

Joined: Jan 2006
Posts: 2,157
Connecticut, USA
thanks, i will give it a shot. i just want some vegetation for a couple of levels in my project, something basic.


My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
Re: Vegetation Template [Re: Blink] #226318
09/09/08 05:34
09/09/08 05:34
Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Frederick_Lim Offline
User
Frederick_Lim  Offline
User

Joined: Oct 2003
Posts: 827
22�21'24"N 114�07'30"E
Wow that's really amazing, but how to cast the object's shadow on terrain?

Page 3 of 4 1 2 3 4

Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | 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