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
2 registered members (TipmyPip, 1 invisible), 18,699 guests, and 8 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 11 of 11 1 2 9 10 11
Re: Dumb terrain question.. Cannot get it to move... [Re: JibbSmart] #387019
11/12/11 20:55
11/12/11 20:55
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
For anyone who is interested (especially Carlos), Ive completed the shader.

It can be found in my shader thread HERE.

Its also got a complete description of how to use it, and
a summary of what it does and where you would want to use it.
And is also packed with a sample script to test it with...

Carlos: Its a bit more complex LOOKING then what we've
discussed here, but thats from added flexability.
It can be made MUCH simpler to look at if we put the
cut-off heights back in as hard-coded numbers.

If you wanna do that, keep it to this thread...
Same goes for any bugs you find in getting it to suit YOUR needs...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #387050
11/13/11 19:41
11/13/11 19:41
Joined: Oct 2008
Posts: 513
Carlos3DGS Offline
User
Carlos3DGS  Offline
User

Joined: Oct 2008
Posts: 513
Wow tahnks alot!!!!

I'm going to go take a look at it right away and try to understand how it works. And it will be a good break from the terrain moving code I'm working on now.


"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1
Re: Dumb terrain question.. Cannot get it to move... [Re: Carlos3DGS] #387057
11/13/11 20:21
11/13/11 20:21
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No problems dude!

If you got any questions on this, or any other subject, just PM me.

Its time for this thread to die...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Dumb terrain question.. Cannot get it to move... [Re: EvilSOB] #387059
11/13/11 21:03
11/13/11 21:03
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline OP
Expert
EvilSOB  Offline OP
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Oh, and to help ease your understanding of the shader,
here is another version that works the same STRUCTURALLY,
but all the configuration settings are hardcoded into the
shader source-code itself, with descriptive variable names.

Example lite-c script
Click to reveal..
Code:
#include <acknex.h>
#include <default.c>

BMAP* sand_tex  = "sand.tga";		// Sand Texture
BMAP* grass_tex = "grass.tga";	// Grass Texture
BMAP* rock_tex  = "rock.tga";		// Rock Texture
BMAP* snow_tex  = "smoke.tga";	// Snow Texture


//
//==========================================================================
//==========================================================================
//CORE CODE
//==========================================================================
MATERIAL *RePaintSkin_mat =
{	effect= "TerrainPainter_hardcoded.fx";		event = skinChangeEvent;
	flags = ENABLE_RENDER | AUTORELOAD;											}
//--------------------------------------------------------------------------
function skinChangeEvent() {	if(me!=render_view.genius)	 return(1);	}
//--------------------------------------------------------------------------
void RePaint_Skin(ENTITY* ME)
{	if(!ME)						return;		//invalid entity to capture.
	if(!ent_getskin(ME,1))	return;		//entity has no skin to capture into.
	//-----------------------------------------------------------------------
	VIEW *view = view_create(1000);		set(view, SHOW);
	view.material = RePaintSkin_mat;		view.genius = ME;
	view.x=ME.x-(ME.max_x+ME.min_x)/2;	view.y=ME.y-(ME.max_y+ME.min_y)/2;
	view.z = ME.z + maxv(ME.max_x-ME.min_x, ME.max_y-ME.min_y)*0.75;
	vec_set(view.pan,vector(0,-90,0));	view.bmap = ent_getskin(ME,1);
	view.size_x = view.bmap.width;		view.size_y = view.bmap.height;
	//-----------------------------------------------------------------------
	wait(1);										ptr_remove(view);			beep();		}
//==========================================================================
//End of CORE CODE
//==========================================================================
//==========================================================================
//



ENTITY* Terr;

void updateView()		{	RePaint_Skin(Terr);	}



function main() 
{
	wait(1);					level_load(NULL);		wait(1);				diag("\n\n\n");
	draw_textmode("Times",0,32,100);				warn_level = 3;	terrain_chunk=256;
	
	//------------------------------------------------------------------------------------
	//
	Terr = ent_create("terr.MDL", nullvector, NULL);
	vec_set(camera.x, vector(-300,150,220));	vec_set(camera.pan, vector(350,-25,0));
	//
	on_space = updateView;
	//
	while(!key_esc) 
	{
		if(key_f1)	DEBUG_BMAP(ent_getskin(Terr,1), 0, 1);

		if(key_f2)	//swap entities
		{	if(!str_cmp(Terr.type, "PLANE01.HMP"))		
			{	ent_morph(Terr, "plane01.hmp");		vec_fill(Terr.scale_x, 0.1);	}
			else
			{	ent_morph(Terr, "Terr.mdl");			vec_fill(Terr.scale_x, 1);		}
			while(key_f2)	wait(1);					}

		wait(1);
	}
}



Shader code "TerrainPainter_hardcoded.fx"
Click to reveal..
Code:
//===================================================================================
//ColorMapping Samplers Texture-Sources
texture sand_tex_bmap, grass_tex_bmap, rock_tex_bmap, snow_tex_bmap;
sampler SandSampler  = sampler_state  { Texture = <sand_tex_bmap>;  };
sampler GrassSampler = sampler_state  { Texture = <grass_tex_bmap>; };
sampler RockSampler  = sampler_state  { Texture = <rock_tex_bmap>;  };
sampler SnowSampler  = sampler_state  { Texture = <snow_tex_bmap>;  };
//
//===================================================================================
//Configuration Settings
float Lap = 20;			// Border Overlap Range 	 		(in quants)
//
float GrassStart =  37;	// Start height of GRASS texture	(in quants)
float RockStart  =  80;	// Start height of ROCK texture	(in quants)
float SnowStart  = 125;	// Start height of SNOW texture	(in quants)
//
float SandScale  = 6;	// SAND texture scale multiplier
float GrassScale = 6;	// GRASS texture scale multiplier
float RockScale  = 2;	// ROCK texture scale multiplier
float SnowScale  = 3;	// SNOW texture scale multiplier
//
//===================================================================================
//Random Number Generator
#define cMult 0.0001002707309736288
#define aSubtract 0.2727272727272727
//
float random(float4 t)
{ 
	float a, b, c, d;
	a=t.x+t.z*cMult+aSubtract-floor(t.x); 
	a*=a; 	b=t.y+a; 	b-=floor(b); 
	c=t.z+b; 	c-=floor(c); 	d=c; 
	a+=c*cMult+aSubtract-floor(a); 
	a*=a; b+=a;		b-=floor(b); 
	c+=b; c-=floor(c); 
	return ((a+b+c+d)/4); 
}
//
//===================================================================================
//
void Painter_VS(	in  float4	inPos:  POSITION,	in	 float2 inTex:  TEXCOORD0,
						out float4	outPos: POSITION,	out float  outHgt: TEXCOORD0,
						out float2 outTexD:TEXCOORD1, out float2 outTexG:TEXCOORD2,
						out float2 outTexR:TEXCOORD3, out float2 outTexS:TEXCOORD4	)
{
	outPos	= float4(inTex.x*2-1, -inTex.y*2+1, 0,1);		//output normalized XYpos
	outHgt	= inPos.y + (random(inPos)*20)-10;	//output slightly-randomized height
	outTexD	= inTex * SandScale;		//	re-scale coords for SAND/DIRT texture lookup
	outTexG	= inTex * GrassScale;	//	re-scale coords for GRASS texture lookup
	outTexR	= inTex * RockScale;		//	re-scale coords for ROCK texture lookup
	outTexS	= inTex * SnowScale;		//	re-scale coords for SNOW texture lookup
}
//
//===================================================================================
//
float4 Painter_PS(	in float  inHgt: TEXCOORD0,
							in float2 inTexD:TEXCOORD1, in float2 inTexG:TEXCOORD2,
							in float2 inTexR:TEXCOORD3, in float2 inTexS:TEXCOORD4 ):COLOR0 
{	
	float4 color = 0;
		  if(inHgt<(GrassStart-Lap))	color = tex2D(SandSampler, inTexD);
	else if(inHgt<(GrassStart+Lap))	color = lerp(tex2D(SandSampler, inTexD), tex2D(GrassSampler,inTexG),saturate((inHgt-GrassStart)/Lap));
	else if(inHgt<(RockStart-Lap))	color = tex2D(GrassSampler, inTexG);
	else if(inHgt<(RockStart+Lap))	color = lerp(tex2D(GrassSampler,inTexG), tex2D(RockSampler, inTexR),saturate((inHgt-RockStart)/Lap));
	else if(inHgt<(SnowStart-Lap))	color = tex2D(RockSampler, inTexR); 
	else if(inHgt<(SnowStart+Lap))	color = lerp(tex2D(RockSampler, inTexR), tex2D(SnowSampler, inTexS),saturate((inHgt-SnowStart)/Lap));
	else										color = tex2D(SnowSampler, inTexS);
	return color;
}
//
//===================================================================================
//
technique terrain_paint 
{
	pass p0 
	{
		CullMode = None;
		VertexShader = compile vs_2_0 Painter_VS();
		PixelShader  = compile ps_2_0 Painter_PS();
	}
}
//
//===================================================================================
//




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Page 11 of 11 1 2 9 10 11

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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