I have problem with using water shader in 16:9 resolution because view.aspect is being change..

I use this code to change resolution to 16:9:
Code:
function set_resolution(res_,wide_,_depth,_window)
{
	var new_ratio;
	var x_;
	var y_;
	var view_aspect;
	if (res_ == 0) { video_set(0,0,_depth, _window); return; }
	if (wide_ == 0 || _window == 2)
	{
		if (res_ == 1)
		{
			x_ = 640;
			y_ = 480;
		}
		if (res_ == 2)
		{
			x_ = 800;
			y_ = 600;
		}
		if (res_ == 3)
		{
			x_ = 1024;
			y_ = 768;
		}
		if (res_ == 4)
		{
			x_ = 1280;
			y_ = 960;
		}
		if (res_ == 5)
		{
			x_ = 1280;
			y_ = 1024;
		}
		if (res_ == 6)
		{
			x_ = 1400;
			y_ = 1050;
		}
		if (res_ == 7)
		{
			x_ = 1600;
			y_ = 1200;
		}
	}
	else
	{
		if (wide_ == 1)
		{
			if (res_ == 1)
			{
				x_ = 848;
				y_ = 480;
			}
			if (res_ == 2)
			{
				x_ = 960;
				y_ = 600;
			}
			if (res_ == 3)
			{
				x_ = 1088;
				y_ = 612;
			}
			if (res_ == 4)
			{
				x_ = 1280;
				y_ = 720;
			}
			if (res_ == 5)
			{
				x_ = 1360;
				y_ = 768;
			}
			if (res_ == 6)
			{
				x_ = 1600;
				y_ = 900;
			}
			if (res_ == 7)
			{
				x_ = 1920;
				y_ = 1080;
			}
				if (res_ == 8)//moja
			{
				x_ = 1440;
				y_ = 900;
			}
		}
		if (wide_ == 2)
		{
			if (res_ == 1)
			{
				x_ = 640;
				y_ = 400;
			}
			if (res_ == 2)
			{
				x_ = 960;
				y_ = 600;
			}
			if (res_ == 3)
			{
				x_ = 1280;
				y_ = 768;
			}
			if (res_ == 4)
			{
				x_ = 1280;
				y_ = 800;
			}
			if (res_ == 5)
			{
				x_ = 1600;
				y_ = 1024;
			}
			if (res_ == 6)
			{
				x_ = 1680;
				y_ = 1050;
			}
			if (res_ == 7)
			{
				x_ = 1920;
				y_ = 1200;
			}
		}
	}
	video_set(x_, y_, _depth, _window);
	wait(1);
	new_ratio = x_ / y_;
	view_aspect = new_ratio / (4/3);
	camera.aspect = view_aspect;
}


And this water shader from temp_FX.wdl:

Code:
MATERIAL mtl_water_mirror
{
	effect=
	"
//enable: Mirror Fresnel effect
//help: Water transparency depends on view angle
//id: 21
#define MIRROR_FRESNEL

	#include <transform>
	#include <fog>
	#include <pos>
	#include <normal>
	
	float4 vecTime;
	float4 vecSkill41; // Wind_X, Wind_Y, Ripple, Scale
	float4 vecColor;	

	texture entSkin1;
	texture mtlSkin2;

	sampler sBumpTex = sampler_state
	{
		Texture = <entSkin1>;
		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_water_mirror // Output to the pixelshader fragment
	{
		float4 Pos	: POSITION;
		float4 Color: COLOR0;
		float  Fog	: FOG;
		float2 Tex0	: TEXCOORD0;
		float2 Tex1	: TEXCOORD1;
	};

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

// bump and reflection coordinates
		Out.Tex0 = (inTex0 + vecSkill41.xy * vecTime.w ) * vecSkill41.w;
		Out.Tex1 = 0.5 * (1.0 + (Out.Pos/Out.Pos.w));

// color and transparency
		Out.Color = vecColor;
#ifdef MIRROR_FRESNEL
		float4 P = DoPos(inPos); // vector world position
		float3 N = DoNormal(inNormal); // normal world orientation
		float4 vecToView = normalize(vecViewPos-P); // direction towards camera
		Out.Color.a = 0.5 + vecColor.a * (1.0 - dot(vecToView,N));
#endif		
		return Out;
	}
	
#ifdef WONTWORK
	float4 ps_mirror_straight(out_water_mirror In): COLOR
	{
		return tex2D(sMirrorTex,In.Tex1) * In.Color;
	}
	
	float4 ps_water_mirror(out_water_mirror In): COLOR
	{
		float4 Bump = tex2D(sBumpTex,In.Tex0);
		float2 Coord = In.Tex1 + Bump.xy * vecSkill41.z;
		return tex2D(sMirrorTex,Coord) * In.Color;
	}
#endif

//////////////////////////////////////////////////////////////////
	technique water_mirror
	{
		pass one
		{
			AlphaBlendEnable = True;

			sampler[0] = (sBumpTex);
			sampler[1] = (sMirrorTex);

			VertexShader = compile vs_1_1 vs_water_mirror();

// bump matrix - required for texbem
			BumpEnvMat00[1] = (vecSkill41.z);
			BumpEnvMat11[1] = (vecSkill41.z);
			BumpEnvMat01[1] = 0.0;
			BumpEnvMat10[1] = 0.0;

// We need an asm shader here - for some reason,
// ps_1_1 HLSL tex2D won't sample modified coordinates
			PixelShader = asm
			{
				ps_1_1
				tex t0         // sample Stage0 Texture rg 
				texbem t1,t0   // multiply rg with BumpEnvMat to uv, 
							   // and sample Stage1 Texture using uv+t1
				mul r0,v0,t1   // multiply Stage1 Texture by Color + Alpha
			};
		}
	}

	technique fallback { pass one { } }
	";
}


Can anyone make this shader work in 16:9?

Last edited by cro_games; 08/02/08 10:42.

Hello everyone my name is Ivan Mandic from "Frozen pixel studio". wink
-----------------------------------
Homepage: www.fpx-studio.com
e-mail: emu_hunter_1990@hotmail.com
(working on a game engine)