Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (7th_zorro, Quad, VoroneTZ, 1 invisible), 623 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Water reflections - possible memory leak? #444745
08/17/14 20:40
08/17/14 20:40
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Every time I reach the level in my game using the game studio water reflection shader, my frame rate gets chopped in half - and stays low until I restart my game. My first level i get anywhere from 30 to 60 fps, the next level there are water reflections and I'm down to 15fps. I return to the menu and restart the game and my first level is at 15fps. I exit the engine and reload and my first level is back to 30-60fps.

Is there something in the water shader script I should add or edit? It seems like it's sucking resources even when it is not in use.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Water reflections - possible memory leak? [Re: Stansmedia] #444754
08/18/14 08:02
08/18/14 08:02
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
in MapBuilder you can find a rewritten version of it in MBmwater.c/.h files (maybe I modified it since last release, but the last one should also work fine).


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Water reflections - possible memory leak? [Re: sivan] #445304
09/02/14 23:38
09/02/14 23:38
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
I am using your version of the water shader. It is still happening. As soon as I reach a level with the water shader the games performance completely dies - even after loading levels without the shader.

Level 3 - i get 60fps when I load the game on that level.
Level 2 - i get 20fps because of the water shader.
When I load level 2 and pass to level 3, level 3 runs at 20fps.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Water reflections - possible memory leak? [Re: Stansmedia] #445310
09/03/14 08:57
09/03/14 08:57
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I had no problems with it but since the last release I rewrote it, here is the updated unpublished version (for safety you can ptr_remove the water entity before another level load, but in theory it should work without it, I never remove it):

include MBmwater.h and MBmwater.c in your project,

put it in water entity action (tested and probably works only with one water entity!):
Code:
Mwater_Init(my);



MBmwater.h
Code:
#ifndef MBmwater_h
#define MBmwater_h

//////////////////////////////////////////////////////////////////////
// defines

//#define MIRROR_DEBUG

//////////////////////////////////////////////////////////////////////
// variables

var mwater_speedx				= 10;
var mwater_speedy				= 25;
var mwater_ripple				= 50;
var mwater_scale				= 100;

var mwater_mirrorvisible 	= 0;

//////////////////////////////////////////////////////////////////////
// views

#ifdef MIRROR_DEBUG
	VIEW* mw_view_mirror = { layer = 1; }
#else
	VIEW* mw_view_mirror = { layer = -1; }  // render mirror view before camera view
#endif

//////////////////////////////////////////////////////////////////////
// bmaps

BMAP* 	mw_bmap_mirrortarget 	= NULL;
BMAP*		mw_bmap_water_uv 			= NULL;

//////////////////////////////////////////////////////////////////////
// materials

MATERIAL* mtl_mirrorWaterMB =
{
	ambient_blue  = 50;  	ambient_green  = 50;  	ambient_red  = 50;
	diffuse_blue  = 200;  	diffuse_green  = 200;  	diffuse_red  = 200;
	specular_blue = 0;  		specular_green = 0;  	specular_red = 0;
	emissive_blue = 0;  		emissive_green = 0;  	emissive_red = 0;
	power = 5;
	albedo = 100;
	effect = "mirrorWaterMB.fx";
}

//////////////////////////////////////////////////////////////////////
// functions

void		Mwater_Init(ENTITY* ent);

//////////////////////////////////////////////////////////////////////



#endif



MBmwater.c
Code:
#ifndef MBmwater_c
#define MBmwater_c


//////////////////////////////////////////////////////////////////////
// code


void	 Mwater_Init(ENTITY* ent)
{
	//------------------------------------------------------------------	
	
	my = ent;
	
	//------------------------------------------------------------------	
	
	my.material = mtl_mirrorWaterMB;											
	
	//------------------------------------------------------------------	
	
	if (mw_bmap_water_uv)
		{
			ptr_remove(mw_bmap_water_uv);												// *** correct mirror shift on multiple level loads
			mw_bmap_water_uv = NULL;
		}
	
//	mw_bmap_water_uv = bmap_to_uv(bmap_create("water.dds"));					// orig - results in mirror offset
//	mw_bmap_water_uv = bmap_to_normals(bmap_create("water.dds"), 50);		// *** - no mirror offset error !
   mw_bmap_water_uv = bmap_to_normals(bmap_for_entity(my,1), 50);			// *** use 1st skin, okay

   my.material.skin1 = mw_bmap_water_uv;
   my.material.flags |= TRANSLUCENT;
	
	//------------------------------------------------------------------	
	
	if (mw_bmap_mirrortarget) 
		{ 
	//		my.material.skin2 = mw_bmap_mirrortarget;
	//		return; 	
			ptr_remove(mw_bmap_mirrortarget);										// *** correct mirror shift on multiple level loads
			mw_bmap_mirrortarget = NULL;
		}
	
	//------------------------------------------------------------------	
	
	mw_bmap_mirrortarget = bmap_createblack(256,256,888);
	my.material.skin2 = mw_bmap_mirrortarget;
	mw_view_mirror.bmap = mw_bmap_mirrortarget;
	mw_view_mirror.size_x = bmap_width(mw_view_mirror.bmap);
	mw_view_mirror.size_y = bmap_height(mw_view_mirror.bmap);

	vec_set(mw_view_mirror.pnormal_x,vector(0,0,1.0));							// reflect upwards
	
	set(mw_view_mirror,NOCULL|PORTALCLIP);											// *** NOSHADOW|  - to get proper decal shadows - engine bug to be fixed
	
#ifdef ENGINE_BUG_DECAL_A840	
	if ((shadow_stencil < (var)0 ) || (shadow_stencil > (var)2))			// *** because of an engine bug below A8.45.1
#endif	
 		{
 			set(mw_view_mirror, NOSHADOW);											// ***			needed by pssm, not needed by decal/stencil shadows 
 		}
	
	set(mw_view_mirror,NOFLAG1);														// suppress all entities with flag1 set

	set(mw_view_mirror,NOPARTICLE);													// requird by PORTALCLIP
	set(mw_view_mirror,NOSHADER);														// requird by PORTALCLIP
	
	//------------------------------------------------------------------	
		
	while ((mw_bmap_mirrortarget) && (me))											// ¤¤¤
	{
		proc_mode = PROC_LATE;															// camera must be moved before
		
		if (!is(my,CLIPPED)) 
			{
				// place the mirror plane at the topmost entity polygon
				vec_for_max(mw_view_mirror.portal_x,my);							// without taking into account scale
//				vec_mul(view_mirror.portal_x, my.scale_x);						// *** multiply with scale
				vec_add(mw_view_mirror.portal_x,my.x);								// offset by position
//				view_mirror.portal_z = my.z;											// ***to avoid errors because of vertex movements
				mwater_mirrorvisible = 1;
			}
		
		if (mwater_mirrorvisible) 
			{ 
				set(mw_view_mirror,SHOW);
				mw_view_mirror.genius 		= camera.genius;
				mw_view_mirror.aspect 		= (screen_size.x / screen_size.y) * camera.aspect;		// screen aspect, independent of render target
				mw_view_mirror.arc    		= camera.arc;
				mw_view_mirror.fog_start 	= camera.fog_start;
				mw_view_mirror.fog_end   	= camera.fog_end;	
				mw_view_mirror.clip_far		= camera.clip_far * 0.5;
				mw_view_mirror.clip_near 	= camera.clip_near * 2;
				mw_view_mirror.x 	 		 	= camera.x;
				mw_view_mirror.y 	   		= camera.y;
				mw_view_mirror.z 	   		= 2 * mw_view_mirror.portal_z - camera.z;					// move the camera at its mirror position
				mw_view_mirror.pan    		= camera.pan;
				mw_view_mirror.tilt   		= -camera.tilt;													// flip the vertical camera angle	
				mw_view_mirror.roll   		= -camera.roll;
			}
		else 
			{ 
				// switch rendering off when all mirror objects are outside the frustum
				reset(mw_view_mirror, SHOW); 
			}
		
		// reset
		mwater_mirrorvisible = 0;

#ifdef MIRROR_DEBUG
		if (key_f11) 
			{	
				// debugging - make mirror visible onscreen
				mw_view_mirror.bmap = NULL;
			} 
		else 
			{
				mw_view_mirror.bmap = mw_bmap_mirrortarget;
			}	
#endif
		wait(1);
	}
	
	//------------------------------------------------------------------	
	
	// ¤¤¤
	ptr_remove(mw_bmap_mirrortarget);							// *** correct mirror shift on multiple level loads
	mw_bmap_mirrortarget = NULL;
	
	//------------------------------------------------------------------	
}




#endif



the shader mirrorWaterMB.fx:
Code:
bool AUTORELOAD;

/////////////////////////////////////////////////////////////////////////////

#define FRESNEL_TRANSPARENCY

/////////////////////////////////////////////////////////////////////////////

#include <transform>
#include <fog>
#include <pos>
#include <normal>
//#include <vecskill>		// use global variables instead of skills

/////////////////////////////////////////////////////////////////////////////

float4 vecTime;
float4 vecSunColor;	
float4 vecColor;	
float fAlbedo;
float fAlpha;

/////////////////////////////////////////////////////////////////////////////

texture entSkin1;
texture mtlSkin1;
texture mtlSkin2;

//	my.skill41 = floatv(10);		// 10 speed x
//	my.skill42 = floatv(25);		// 25 speed	y
//	my.skill43 = floatv(25);		//	25 ripple - waves
//	my.skill44 = floatv(75);		// 100 scale

float mwater_speedx_var						= 10.0;
float mwater_speedy_var						= 25.0;
float mwater_ripple_var						= 50.0;
float mwater_scale_var						= 100.0;

/////////////////////////////////////////////////////////////////////////////

sampler sBumpTex = sampler_state
	{
		Texture = <mtlSkin1>;
		MipFilter = Linear;
		MinFilter = Linear;
		MagFilter = Linear;
		AddressU = Wrap;
		Addressv = Wrap;
	};

sampler sMirrorTex = sampler_state
	{
		Texture = <mtlSkin2>;
		MipFilter = Linear;
		MinFilter = Linear;
		MagFilter = Linear;
		AddressU = Clamp;
		Addressv = Clamp;
	};

/////////////////////////////////////////////////////////////////////////////

struct out_mirror // Output to the pixelshader fragment
	{
		float4 Pos	: POSITION;
		float  Fog	: FOG;
		float4 Color: COLOR0;
		float2 Tex0	: TEXCOORD0;
		float3 Tex1	: TEXCOORD1;
		float3 Albedo: TEXCOORD2;
	};

/////////////////////////////////////////////////////////////////////////////

out_mirror vs_water_mirror
									(
										in float4 inPos		: POSITION,
										in float3 inNormal	: NORMAL,
										in float4 inTex0		: TEXCOORD0
									)
{
	out_mirror Out;
	
	Out.Pos = DoTransform(inPos); 										// transform to screen coordinates
	Out.Fog = DoFog(inPos);

	// bump and reflection coordinates
   float2 Speed;
   Speed.x  = (mwater_speedx_var * 0.000002);
   Speed.y  = (mwater_speedy_var * 0.000002);
   
	Out.Tex0 = (inTex0 + Speed*vecTime.w) * (mwater_scale_var*0.05);
	Out.Tex1 = Out.Pos.xyw;

	// color and transparency
	Out.Albedo.x = 0;
	Out.Albedo.y = 0;
	Out.Albedo.z = (mwater_ripple_var * 0.001);						// ripple
	
	Out.Color    = float4(vecColor.xyz + vecSunColor.xyz, fAlpha);
{}
#ifdef FRESNEL_TRANSPARENCY
	float4 P = DoPos(inPos); 												// vector world position
	float3 vecToView = normalize(vecViewPos-P); 						// direction towards camera
	float3 N = DoNormal(inNormal); 										// normal world orientation
	Out.Color.a = 0.67 + fAlpha * (1.0 - dot(vecToView,N));
#endif
		
	return Out;
}
	
/////////////////////////////////////////////////////////////////////////////

float4 ps_water_mirror(out_mirror In): COLOR
	{

		float4 Bump  = tex2D(sBumpTex,In.Tex0)*2-1;
		
		float2 Coord = 0.5 * (1.0 + In.Tex1.xy/In.Tex1.z) + Bump.xy * In.Albedo.z;
		
		float4 ColorMod 	= In.Color;
		ColorMod.a 			= 1;
		
		return tex2D(sMirrorTex,Coord) * In.Color * ColorMod; // ***
	}

//////////////////////////////////////////////////////////////////

technique water_mirror
	{
		pass one
		{
			AlphaBlendEnable 	= True;
		   
			VertexShader	= compile vs_2_0 vs_water_mirror();
			PixelShader		= compile ps_2_0 ps_water_mirror();			
		}		
	}

technique fallback { pass one { } }



to be honest I don't really use it. it has better performance than my other water shaders based on shade-c, but they are also rewritten since last release, providing several options for quality/performance considerations (no foam, no refraction, no dynamic depth).


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: Water reflections - possible memory leak? [Re: sivan] #445314
09/03/14 12:19
09/03/14 12:19
Joined: Jul 2004
Posts: 785
Serbia
Iglarion Offline
User
Iglarion  Offline
User

Joined: Jul 2004
Posts: 785
Serbia
What debug window say? I don't think that watter shader is a problem. It sounds as there is a problem with memory consumption, and you walk along the edge, and watter sader's is just a little thing that jump this border. Probably a bigger problem with memory leak is somewhere else. I once had the same symptoms with fps drops like you. What about your textures - format/size?


IGRAVISION Page - www.igravision.com
RPG project - The Battle For Forgol 92.75%
Re: Water reflections - possible memory leak? [Re: Iglarion] #445322
09/03/14 16:31
09/03/14 16:31
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
The REF in the debug panel is spiking. I did the one thing I should have done first and test the map with the reflection off... Sure enough. Your right, Iglarion. But the map contains the same models/setup as the maps that run at high frame rates. An MDL terrain with a 1024x texture tiling over it. Tree, grass, and border (cluster of trees in one file), as well as some WED blocks for entrance and exits. Very weird.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Water reflections - possible memory leak? [Re: Stansmedia] #445323
09/03/14 16:52
09/03/14 16:52
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Could it be my nexus settings in the map properties? I've got it at 128


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Water reflections - possible memory leak? [Re: Stansmedia] #445324
09/03/14 18:36
09/03/14 18:36
Joined: Jul 2004
Posts: 785
Serbia
Iglarion Offline
User
Iglarion  Offline
User

Joined: Jul 2004
Posts: 785
Serbia
Keep nexus under 300 is quite ok, so you can feel free to increase. Can you make one screenshot with Statistics panel [F11] before and after fps drop start, maybe this can help to find out the problem.


IGRAVISION Page - www.igravision.com
RPG project - The Battle For Forgol 92.75%
Re: Water reflections - possible memory leak? [Re: Iglarion] #445326
09/03/14 19:25
09/03/14 19:25
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
... it doesn't seem to be doing it now. I... uh... need to go have a smoke before I explode.

This is getting brutal. I'm very close to having this game done, and ironing out bugs is literally the most tedious process.

Last edited by Stansmedia; 09/03/14 19:27.

Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Water reflections - possible memory leak? [Re: Stansmedia] #445327
09/03/14 19:40
09/03/14 19:40
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
set FLAG1 for grass and other detail object to hide them in the mirror view.


Free world editor for 3D Gamestudio: MapBuilder Editor

Moderated by  Blink, Hummel, Superku 

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