Search the archive:
YaBB - Yet another Bulletin Board
 
   
 
Pages: 1 2 3 ... 13
Send Topic Print
FSWC's back in progress! (Read 40838 times)
Dec 8th, 2007 at 10:43am

Ashton Lawson   Offline
Colonel
FS Water Configurator
Programmer
Phuket, Thailand

Gender: male
Posts: 1211
*****
 
Hey guys,

For those of you following my progress on FSWC, I'm sad to say that it isn't going to be ready for a long time, and I mean quite long.

Basically, my PC's mobo seems to hate me more than anything, and it's been sent to Bangkok to be checked, and I won't get it back for two weeks, which means no developement, therefore no program.

However, the slightly better news is that, since I now know what's needed for the program to work, and I have the basic structure down, I'm going to reprogram it in C# (not a musical note), and recreate it completely so that it works with all FSX-supported operating systems, XP SP2 and Vista, 32-bit and 64-bit, and also support all versions of FSX, including all or no service packs, so that anyone can use the program.

I've also decided on adding extra features, which should allow me, or you, as the case may be, to edit these settings:
General Reflection Amount
Low-Angle Reflections (SP1 and lower)
High-Angle Reflections (SP1 and lower)
Specular Reflections
Wave Intensity
and hopefully a few more, which I have yet to experiment with.

Anyway, if all goes well there will be a single installer, that installs everything you need, system specific stuff and all, so it should be as easy as installing FSX itself (just without the long long waiting time and updates).

So, you won't be hearing from me in a while, not until my PC is back up and running.

See ya guys,

Str!ker
« Last Edit: Jan 29th, 2008 at 4:55pm by Fly2e »  

...&&FS Water Configurator+ has new modifications in the works, plus DirectX 10, Service Pack&&1, and Radeon HD 3+ Series support.
IP Logged
 
Reply #1 - Dec 20th, 2007 at 10:19am

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 

I just saw this

I was wondering what happened to you.


I assumed you may be busy with school. Bummer about your system

Anyway, I have been busy and have not looked that this for some time. I thought perhaps you may still be reworking the code for the SP2 file but I see now you are down.

The original edited code used in SP1


};

#define fresnMin x.x
#define fresnMax x.x

half fresnel2( half3 vEyeDir, half3 vSurfaceNorm )
{
  half frdot = min( 1 - dot(vEyeDir, vSurfaceNorm), 1 );
  return lerp( fresnMin, fresnMax, frdot * frdot );



should still work although your other tweaks for specular will have to be refined. I never did fool around with it because I thought you were still working on it.


 
IP Logged
 
Reply #2 - Dec 20th, 2007 at 11:23am

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 


Ok Str!ker I just looked this over and the original code does work to make water more reflective, however, unlike SP1 the frame hit is exactly the same. In SP1 the code allowed raising the water reflection slider to 2xMid with no hit and 2xHigh with a minor hit. With SP2 the frame hit is no different between the default and the code that allows higher reflections.


So there you have it. And to tell you the truth, the water was too reflective and even adjusting the min and max the results were not what I consider accurate for water. It was either a mirror or a pixelated mirror.


There is no performance gain by applying this to the SP2 shader file. All it will do in increase reflection but only if you raise the slider to 2xMed or 2xHigh in order to get cloud and land in the water.


 
IP Logged
 
Reply #3 - Dec 20th, 2007 at 12:40pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 

I have completely confirmed all this now


It will give you high reflections but without the shimmer we got in SP1 so there is no need to fool with specular



But unfortunately it will not provide the high reflections without the same excact hit to performance in DX9 the default shader file produces and you must raise the slider to get the higher reflections.







 
IP Logged
 
Reply #4 - Dec 20th, 2007 at 1:52pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 



If anyone wishes to try this, please note: I see no reason to do this edit other than increasing reflection because there is NO PERFORMACE benefit to making this change like there was in SP1



NOTE: THIS IS FOR SP2 or SP2 with Accleration ONLY. DO NOT USE THE FOLLOWING CODE FOR SP1

Back up your original Microsoft Games/Microsoft Flight Simulator X/ShadersHLSL/Terrain\Water20.fxh <-------- copy this to somewhere safe

Open the original file in notepad and COMPLETELY overwrite it with the following code:


Code:
//---------------------------------------------------------------------------
// Flight Simulator X - Shader Effect Files
// Copyright (c) 2006, Microsoft Corporation
//---------------------------------------------------------------------------
#include <Common.fxh>
#include <MaterialDecl.fxh>
#include <D3D9Texture.fxh>
#include <FuncLibrary.fxh>

#define vLightDir vSunVectorWorld

// Potential textures
texture Water_BaseTexture		   : MATERIAL_BASE_TEXTURE;
texture Water_EnvTexture		    : MATERIAL_ENVIRONMENT_TEXTURE;
texture Water_BumpTexture		   : MATERIAL_BUMP_TEXTURE;

// Global variables
float3 vCamEyePoint : VIEWPOSITION;

float fTimeScale	  : WATER_BUMP_TIME_SCALE;
float fBumpScale	  : WATER_BUMP_SCALE;	    
float fBumpUVScale	: WATER_BUMP_UV_SCALE;
float fBumpU		: WATER_BUMP_DISTANCE_SCALE;
float fBumpV		: WATER_BUMP_LIGHT_SCALE;    
float fFresnelFactorMin : WATER_FRESNEL_FACTOR_MIN;  
float fFresnelFactorMax : WATER_FRESNEL_FACTOR_MAX;  
float fSpecularPower    : SPECULAR_POWER;
float fSpecularBoost    : SPECULAR_BOOST;
float fSpecularBlend    : SPECULAR_BLEND;
float fBumpRotation     : WATER_BUMP_ROTATION;
float fBumpTimeX1	 : WATER_BUMP_TIME_X1;	  
float fBumpTimeY1	 : WATER_BUMP_TIME_Y1;	  
float fBumpTimeX2	 : WATER_BUMP_TIME_X2;	  
float fBumpTimeY2	 : WATER_BUMP_TIME_Y2;	  
float fBumpTimeScale2   : WATER_BUMP_TIME_SCALE_2;  

// Samples used by this shader
sampler Water_BaseSampler = sampler_state
{
    Texture	 = (Water_BaseTexture);
    AddressU	= Clamp;	// terrain textures must be clamped
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_BumpSampler = sampler_state
{
    Texture	 = (Water_BumpTexture);
    AddressU	= Wrap;
    AddressV	= Wrap;
    AddressW	= Wrap;
    MinFilter     = D3DTEXF_LINEAR;
    MagFilter     = D3DTEXF_LINEAR;
    MipFilter     = D3DTEXF_LINEAR;
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_EnvMapSampler = sampler_state
{
    Texture	 = (Water_EnvTexture);
    AddressU	= Clamp;
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

struct VSWATER20_INPUT
{
    float4 vPos	 : POSITION;
    float4 vColor     : COLOR0;
    float3 vNormal    : NORMAL;
    float2 vTex	 : TEXCOORD0;
};

struct VSWATER20_OUTPUT
{
    float4  vPos		    : POSITION;
    float   fFog		    : FOG;
    half4   vColor		  : COLOR0;

    float4 TexBump	  : TEXCOORD0;
    float4 TexEnvMap	: TEXCOORD1;
    float4 TexBase	  : TEXCOORD2;
    float4 MiscData		   : TEXCOORD3;
    float3 vNormalWS	: TEXCOORD4;
    float3 vPosWS		     : TEXCOORD5;
    float3 vEyePosWS	: TEXCOORD6;
    float4 TexScreen	: TEXCOORD7;
};

#define fresnMin 0.1
#define fresnMax 0.7

half fresnel2( half3 vEyeDir, half3 vSurfaceNorm )
{
  half frdot = min( 1 - dot(vEyeDir, vSurfaceNorm), 1 );
  return lerp( fresnMin, fresnMax, frdot * frdot );
}

VSWATER20_OUTPUT Water20VS(const VSWATER20_INPUT v,const bool b30Shader)
{
    VSWATER20_OUTPUT o = (VSWATER20_OUTPUT)0;

    // Transform to clip space
    o.vPos = mul(v.vPos, mFullProj);

    // Compute fog
    o.fFog = ComputeFog(o.vPos.w, FOG_END, FOG_RECIP, FOG_SELECT_VERTEX, FOG_SELECT_TABLE);

	  // Transform to world space
	  float3 vWorldPos = mul(v.vPos, mWorld);

    // Compute eye vector
	  float3 vEye = normalize(vCamEyePoint - vWorldPos);
	  
	  // Scale normal based bump based on dist
	  //float fNormalScale = max(1.0,length(vEye)-fBumpDistScale);

    // Scale bumpmap texture coordinates by detail coordinates
	  //float2 bmp = fmod(v.vPos.xz * (fBumpUVScale * 0.0001f),1024.0f);
	  float2 bmp = fmod((vWorldPos.xz + float2(fBumpU, fBumpV) - mWorld[3].xz) * (fBumpUVScale * 0.0001f),256.0f);    
	  float2 sc = float2(sin(fBumpRotation),cos(fBumpRotation));
	  if (b30Shader)
	  {
		    o.TexBump.xy = bmp + (fSimTime * fBumpTimeScale2)*float2(fBumpTimeX1,fBumpTimeY1);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fBumpTimeScale2)*float2(fBumpTimeX2,fBumpTimeY2))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }
	  else
	  {
		    o.TexBump.xy = bmp + (fSimTime * fTimeScale)*float2(0.4,-0.4);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fTimeScale)*float2(-1.0,1.0))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }    

	  // Send out interpolated normal for lighting
    o.vNormalWS = normalize(TransformVectorToSpace(v.vNormal, mWorld));

	  // Send out eye pos
	  o.vPosWS    = vWorldPos;
	  o.vEyePosWS = vCamEyePoint;

	  // Output vertex color straight to PS
	  // The alpha component is used to represent the relative
	  // depth of the water, used in computing water translucenty
	  // The color component is simply the color scaled by the
	  // diffuse sun lighting component
    o.vColor.a = v.vColor.a;
    o.vColor.rgb = 0.5/*( 1 - fresnel2(vSunVectorWorld_Sun.xyz, o.vNormalWS.xyz) ) * 0.5*/;

    // Environment mapping is determined from the screen-space coordinates
    // of our geometry. This implies that we need to divide them by W, and then
    // offset/scale into a 0-1 range. Because of interpolation issues due to front
    // clipped geometry, the info is pre-processed and passed to the PS where the 1/W
    // is applied. We also apply the normal to the data to emulate reflections caused
    // by the animating geometry
    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www;
//    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www*(1.0+0.25*o.vNormalWS.xzy/fNormalScale);
    o.TexEnvMap.w = 2.0*o.vPos.w;
    o.TexScreen.xyz = float3(1,-1,1)*o.vPos.xyz+o.vPos.www;
    o.TexScreen.w = 2.0*o.vPos.w;

    // Diffuse texture coordinates
    o.TexBase.xy = v.vTex;

    // Compute per-poly fresnel
	  o.MiscData.x = 1.0 - lerp(fFresnelFactorMin, fFresnelFactorMax, pow(smoothstep(0,1,saturate(-normalize(vWorldPos).y)),0.5));
	  o.MiscData.y = 0;
	  o.MiscData.z = 0;
	  o.MiscData.w = 0;

    return o;
}

float4 Water20PS(VSWATER20_OUTPUT Input, const bool b30Shader) : COLOR
{
    float4 Bump;
    float2 BumpEnv;
    float4 Color;
	  float2 specularFactor;

    // Renomalize the input vectors and determine the
    // eye vector for lighting and reflection
    float3 vEyeDirWS;
    vEyeDirWS = normalize(Input.vEyePosWS - Input.vPosWS);
	  
    
    // Sample the base color and bumpmaps
    // Since this is essentially a texbem style operation, we
    // manually apply the matrix to the bumpmap values, we then
    // scale our envmap texcoords by 1/W before factoring in the
    // bumpmap
	  float3 vSurfaceNorm;
    if (b30Shader)
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }
    else
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }

	  // Compute the diffuse lighting component of the water.
	  float3 vHN;
	  float3 vHN2;

    vHN = normalize(vEyeDirWS.xyz + vSunVectorWorld_Sun.xyz);
    vHN2 = normalize(vEyeDirWS.xyz + vSunVectorWorld_Moon.xyz);

    specularFactor = fSpecularBlend*(pow(fSpecularBoost*saturate(float2(dot(vSurfaceNorm, vHN),fSunMoonInterpolant * dot(vSurfaceNorm, vHN2))), fSpecularPower));
    
	  // Sample the water textures and determine the final color
	  float4 baseColor = tex2D(Water_BaseSampler, Input.TexBase);
	  float4 envColor = tex2Dbias(Water_EnvMapSampler, float4(BumpEnv.xy,0,1 * (Input.TexScreen.z/Input.TexScreen.w)));
	  
	  
	  float4 terrainColor = baseColor;
    float fAlpha = baseColor.a;
	  float4 fLand = { baseColor.a, baseColor.a, baseColor.a, baseColor.a };
	  
    half fr = fresnel2( vEyeDirWS.xyz, vSurfaceNorm.xyz);

    Color = half4( lerp( baseColor.rgb * Input.vColor.rgb, envColor.rgb, fr ), 1);
//    return Color;

    return float4(lerp(Color.xyz + (vSunDirectional * specularFactor.x) + (0.3 * (specularFactor.y + saturate(dot(vSunVectorWorld_Moon,vSurfaceNorm)))).xxx, terrainColor.xyz, fLand),fAlpha);
}

// ------- 3.0 ----------
float4 Water30PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,true);
}

// ------- 2.0 ----------


float4 Water20PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,false);
}

// ------ VS ------
VSWATER20_OUTPUT Water20VS(VSWATER20_INPUT Input)
{
	  return Water20VS(Input,false);
}

 




Save the file. You now have a newly edited Water20.fxh file with the original backed up for restore


Browse to the following folder:


FOR XP users,
Go to C:/Documents and Settings/YOUR NAME/Local Settings/Application Data/Microsoft/FSX/Shaders/Terrain <----- this folder

FOR VISTA users,
Go to C:/Users/YOUR NAME/AppData/Local/Microsoft/FSX/Shaders/Terrain <------- this folder


BACK UP that entire folder somewhere safe. Then, open the original and DELETE ALL THE CONTENTS OF THE TERRAIN FOLDER




Boot the sim and set water to either 2xMed or 2xHigh


RESTORE DEFAULT

To uninstall, overwrite the edited Water20.fxh with the one you backed up

Browse to the TERRAIN folder as listed above and DELETE the entire folder

Replace the deleted folder with your original you backed up



NOTE: You can experiment with the following lines in the file:


#define fresnMin 0.X   <------- this is sensitive! A value of 0.01 to 0.5 and the default of 0.1 seems to do fine
#define fresnMax 0.X<------- value between 0.1 and 0.9 (or higher such as 1.2, etc)  a value of 0.4 to 0.7 does quite well. Try reducing it to 0.5 or 0.6 to get a balance of high and low reflections


NOTE: WHEN EVER YOU EDIT THE FILE WITH NEW VALUES YOU MUST DELETE THE ENTIRE -CONTENTS- OF THE SHADERS\TERRAIN FOLDER AS YOU DID ABOVE, and BEFORE FSX IS BOOTED IN ORDER FOR THE CHANGES TO TAKE EFFECT
 
IP Logged
 
Reply #5 - Dec 20th, 2007 at 8:37pm

Barnes   Offline
Colonel
14209
Canada

Posts: 17
*****
 
Nick,

Thanks for reworking the shader file!

Looks great.

Dave
 
IP Logged
 
Reply #6 - Dec 20th, 2007 at 9:25pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 

I did not rework anything. Originally I was sent a file by str!ker to test and I was out of the country so I asked someone to test it for me. It would not work in SP2 which is what I suspected because ithe one he edited was from SP1. When I got back I did not have time to look further into it and I assumed str!ker was still working on it. When I checked to see if he had posted anything on the subject I found this post so I did a quick edit into the SP2 shader file and checked it myself.


it works but not like it does in SP1. The amount of control is not there and the water appears too reflective. Mountain lakes have that type of reflection but not large bodies of water.

On top of that, the benefit we had with this in SP1 was 2 fold because the slider could be raised without a performance hit. In SP2 that is not the case.

Further, in looking at it I see that specular seems to have been broken down differently and there are other shader files which control that now.

In any case, its something to timker with but other than shallow reef and mountain lake water, it does not look right to me.

The ENV files need to be reworked which will also allow greater reflective quality, and, allow better dynamic color and brightness change to water as cloud cover increases.


 
IP Logged
 
Reply #7 - Dec 20th, 2007 at 9:53pm

alrot   Offline
Colonel
Freeware Designers Above
All..

Posts: 10231
*****
 
You will say ,Alex is exagerating once again so I will just say.. Thanks Nick

trust me ,I did have to compress to much to reduce to 100k ,if you would see what I see Shocked

...
 

...

Venezuela
IP Logged
 
Reply #8 - Dec 20th, 2007 at 10:35pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 


You guys running slower cards, this may help make it look better. I can not say for sure.  And, since you do not have full support like the 8000 series increasing the water slider may not apply the same hit as it would on a better video adapter.


 
IP Logged
 
Reply #9 - Dec 20th, 2007 at 10:52pm

alrot   Offline
Colonel
Freeware Designers Above
All..

Posts: 10231
*****
 
Nick I can asure you this water moves and reflect much better, the last time I remember seing this water like this was before Sp1 , I took some shots too ..

It may be a slowest card , but 15 frps with a medium high sliders , man I feel very confortable ,or maybe I'm the lukiest man on earth Cool
 

...

Venezuela
IP Logged
 
Reply #10 - Dec 20th, 2007 at 11:04pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 
alrot wrote on Dec 20th, 2007 at 10:52pm:
Nick I can asure you this water moves and reflect much better, the last time I remember seing this water like this was before Sp1 , I took some shots too ..

It may be a slowest card , but 15 frps with a medium high sliders , man I feel very confortable ,or maybe I'm the lukiest man on earth Cool



Glad it is working for you my friend

enjoy   Wink
 
IP Logged
 
Reply #11 - Dec 23rd, 2007 at 1:51pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 





UPDATE   2nd GENERATION TWEAK

Apparently Pwheeler over at AVSIM has taken this a step further and added code to address specular sun reflections, and, remove the moon glow from water which was annoying. It also reduces the reflective surface at higher altitudes but still allows them at lower, as water should display. Its not perfect but you can try the new code here:


NOTE: MAKE SURE TO FOLLOW THE DIRECTIONS ABOVE WHEN CHANGING THE CODE IN THE FILE


This updates the specular but removes the moon water glow:

Code:
//---------------------------------------------------------------------------
// Flight Simulator X - Shader Effect Files
// Copyright (c) 2006, Microsoft Corporation
//---------------------------------------------------------------------------
#include <Common.fxh>
#include <MaterialDecl.fxh>
#include <D3D9Texture.fxh>
#include <FuncLibrary.fxh>

#define vLightDir vSunVectorWorld

// Potential textures
texture Water_BaseTexture		   : MATERIAL_BASE_TEXTURE;
texture Water_EnvTexture		    : MATERIAL_ENVIRONMENT_TEXTURE;
texture Water_BumpTexture		   : MATERIAL_BUMP_TEXTURE;

// Global variables
float3 vCamEyePoint : VIEWPOSITION;

float fTimeScale	  : WATER_BUMP_TIME_SCALE;
float fBumpScale	  : WATER_BUMP_SCALE;	    
float fBumpUVScale	: WATER_BUMP_UV_SCALE;
float fBumpU		: WATER_BUMP_DISTANCE_SCALE;
float fBumpV		: WATER_BUMP_LIGHT_SCALE;    
float fFresnelFactorMin : WATER_FRESNEL_FACTOR_MIN;  
float fFresnelFactorMax : WATER_FRESNEL_FACTOR_MAX;  
float fSpecularPower    : SPECULAR_POWER;
float fSpecularBoost    : SPECULAR_BOOST;
float fSpecularBlend    : SPECULAR_BLEND;
float fBumpRotation     : WATER_BUMP_ROTATION;
float fBumpTimeX1	 : WATER_BUMP_TIME_X1;	  
float fBumpTimeY1	 : WATER_BUMP_TIME_Y1;	  
float fBumpTimeX2	 : WATER_BUMP_TIME_X2;	  
float fBumpTimeY2	 : WATER_BUMP_TIME_Y2;	  
float fBumpTimeScale2   : WATER_BUMP_TIME_SCALE_2;  

// Samples used by this shader
sampler Water_BaseSampler = sampler_state
{
    Texture	 = (Water_BaseTexture);
    AddressU	= Clamp;	// terrain textures must be clamped
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_BumpSampler = sampler_state
{
    Texture	 = (Water_BumpTexture);
    AddressU	= Wrap;
    AddressV	= Wrap;
    AddressW	= Wrap;
    MinFilter     = D3DTEXF_LINEAR;
    MagFilter     = D3DTEXF_LINEAR;
    MipFilter     = D3DTEXF_LINEAR;
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_EnvMapSampler = sampler_state
{
    Texture	 = (Water_EnvTexture);
    AddressU	= Clamp;
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

struct VSWATER20_INPUT
{
    float4 vPos	 : POSITION;
    float4 vColor     : COLOR0;
    float3 vNormal    : NORMAL;
    float2 vTex	 : TEXCOORD0;
};

struct VSWATER20_OUTPUT
{
    float4  vPos		    : POSITION;
    float   fFog		    : FOG;
    half4   vColor		  : COLOR0;

    float4 TexBump	  : TEXCOORD0;
    float4 TexEnvMap	: TEXCOORD1;
    float4 TexBase	  : TEXCOORD2;
    float4 MiscData		   : TEXCOORD3;
    float3 vNormalWS	: TEXCOORD4;
    float3 vPosWS		     : TEXCOORD5;
    float3 vEyePosWS	: TEXCOORD6;
    float4 TexScreen	: TEXCOORD7;
};

#define fresnMin 0.05
#define fresnMax 0.5

half fresnel2( half3 vEyeDir, half3 vSurfaceNorm )
{
  half frdot = min( 1 - dot(vEyeDir, vSurfaceNorm), 1 );
  return lerp( fresnMin, fresnMax, frdot * frdot );
}

VSWATER20_OUTPUT Water20VS(const VSWATER20_INPUT v,const bool b30Shader)
{
    VSWATER20_OUTPUT o = (VSWATER20_OUTPUT)0;

    // Transform to clip space
    o.vPos = mul(v.vPos, mFullProj);

    // Compute fog
    o.fFog = ComputeFog(o.vPos.w, FOG_END, FOG_RECIP, FOG_SELECT_VERTEX, FOG_SELECT_TABLE);

	  // Transform to world space
	  float3 vWorldPos = mul(v.vPos, mWorld);

    // Compute eye vector
	  float3 vEye = normalize(vCamEyePoint - vWorldPos);
	  
	  // Scale normal based bump based on dist
	  //float fNormalScale = max(1.0,length(vEye)-fBumpDistScale);

    // Scale bumpmap texture coordinates by detail coordinates
	  //float2 bmp = fmod(v.vPos.xz * (fBumpUVScale * 0.0001f),1024.0f);
	  float2 bmp = fmod((vWorldPos.xz + float2(fBumpU, fBumpV) - mWorld[3].xz) * (fBumpUVScale * 0.0001f),256.0f);    
	  float2 sc = float2(sin(fBumpRotation),cos(fBumpRotation));
	  if (b30Shader)
	  {
		    o.TexBump.xy = bmp + (fSimTime * fBumpTimeScale2)*float2(fBumpTimeX1,fBumpTimeY1);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fBumpTimeScale2)*float2(fBumpTimeX2,fBumpTimeY2))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }
	  else
	  {
		    o.TexBump.xy = bmp + (fSimTime * fTimeScale)*float2(0.4,-0.4);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fTimeScale)*float2(-1.0,1.0))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }    

	  // Send out interpolated normal for lighting
    o.vNormalWS = normalize(TransformVectorToSpace(v.vNormal, mWorld));

	  // Send out eye pos
	  o.vPosWS    = vWorldPos;
	  o.vEyePosWS = vCamEyePoint;

	  // Output vertex color straight to PS
	  // The alpha component is used to represent the relative
	  // depth of the water, used in computing water translucenty
	  // The color component is simply the color scaled by the
	  // diffuse sun lighting component
    o.vColor.a = v.vColor.a;
    o.vColor.rgb = 0.5/*( 1 - fresnel2(vSunVectorWorld_Sun.xyz, o.vNormalWS.xyz) ) * 0.5*/;

    // Environment mapping is determined from the screen-space coordinates
    // of our geometry. This implies that we need to divide them by W, and then
    // offset/scale into a 0-1 range. Because of interpolation issues due to front
    // clipped geometry, the info is pre-processed and passed to the PS where the 1/W
    // is applied. We also apply the normal to the data to emulate reflections caused
    // by the animating geometry
    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www;
//    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www*(1.0+0.25*o.vNormalWS.xzy/fNormalScale);
    o.TexEnvMap.w = 2.0*o.vPos.w;
    o.TexScreen.xyz = float3(1,-1,1)*o.vPos.xyz+o.vPos.www;
    o.TexScreen.w = 2.0*o.vPos.w;

    // Diffuse texture coordinates
    o.TexBase.xy = v.vTex;

    // Compute per-poly fresnel
	  o.MiscData.x = 1.0 - lerp(fFresnelFactorMin, fFresnelFactorMax, pow(smoothstep(0,1,saturate(-normalize(vWorldPos).y)),0.5));
	  o.MiscData.y = 0;
	  o.MiscData.z = 0;
	  o.MiscData.w = 0;

    return o;
}

float4 Water20PS(VSWATER20_OUTPUT Input, const bool b30Shader) : COLOR
{
    float4 Bump;
    float2 BumpEnv;
    float4 Color;
	  float2 specularFactor;

    // Renomalize the input vectors and determine the
    // eye vector for lighting and reflection
    float3 vEyeDirWS;
    vEyeDirWS = normalize(Input.vEyePosWS - Input.vPosWS);
	  
    
    // Sample the base color and bumpmaps
    // Since this is essentially a texbem style operation, we
    // manually apply the matrix to the bumpmap values, we then
    // scale our envmap texcoords by 1/W before factoring in the
    // bumpmap
	  float3 vSurfaceNorm;
    if (b30Shader)
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }
    else
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }

	  // Compute the diffuse lighting component of the water.
	  float3 vHN;
	  float3 vHN2;

    vHN = normalize(vEyeDirWS.xyz + vSunVectorWorld_Sun.xyz);
    vHN2 = normalize(vEyeDirWS.xyz + vSunVectorWorld_Moon.xyz);

    specularFactor = fSpecularBlend*(pow(fSpecularBoost*saturate(float2(dot(vSurfaceNorm, vHN),fSunMoonInterpolant * dot(vSurfaceNorm, vHN2))), fSpecularPower));
    
	  // Sample the water textures and determine the final color
	  float4 baseColor = tex2D(Water_BaseSampler, Input.TexBase);
	  float4 envColor = tex2Dbias(Water_EnvMapSampler, float4(BumpEnv.xy,0,1 * (Input.TexScreen.z/Input.TexScreen.w)));
	  
	  
	  float4 terrainColor = baseColor;
    float fAlpha = baseColor.a;
	  float4 fLand = { baseColor.a, baseColor.a, baseColor.a, baseColor.a };
	  
    half fr = fresnel2( vEyeDirWS.xyz, vSurfaceNorm.xyz);

    Color = half4( lerp( baseColor.rgb * 2 * Input.vColor.rgb, envColor.rgb, fr ), 1);
//    return Color;

    return float4(lerp(Color.xyz + (vSunDirectional * specularFactor.x * 0.5) + (0.3 * (specularFactor.y)).xxx, terrainColor.xyz, fLand),fAlpha);
}

// ------- 3.0 ----------
float4 Water30PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,true);
}

// ------- 2.0 ----------


float4 Water20PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,false);
}

// ------ VS ------
VSWATER20_OUTPUT Water20VS(VSWATER20_INPUT Input)
{
	  return Water20VS(Input,false);
}


 




Too make water more reflective, change the following in the line close to the bottom of the list:

Color = half4( lerp( baseColor.rgb * 2 * <-------------- Change this to * 1 *

That setting tends to boost color so changing it and how it may look will depend on the water you are using (default or other)



NOTE: THIS IS ONLY FOR DX9! All these edits are for DX9. Pwheeler is working on a possible DX10 mod as well.



« Last Edit: Dec 23rd, 2007 at 4:26pm by NickN »  
IP Logged
 
Reply #12 - Dec 23rd, 2007 at 2:16pm

alrot   Offline
Colonel
Freeware Designers Above
All..

Posts: 10231
*****
 
NickN wrote on Dec 23rd, 2007 at 1:51pm:
UPDATE

Apparently Pwheeler over at AVSIM has taken this a step further and added code to address specular sun reflections, and, remove the moon glow from water which was annoying. It also reduces the reflective surface at higher altitudes but still allows them at lower, as water should display. Its not perfect but you can try the new code here:



aww Nick Undecided , what's pwheeler? well , Is this would change the nice moves and shining day of the watter like in the shot above? will be affected,  ..but I didn't check(saw) how was the reflex of the sun and the moon... Undecided Im confuse
 

...

Venezuela
IP Logged
 
Reply #13 - Dec 23rd, 2007 at 2:41pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 
alrot wrote on Dec 23rd, 2007 at 2:16pm:
NickN wrote on Dec 23rd, 2007 at 1:51pm:
UPDATE

Apparently Pwheeler over at AVSIM has taken this a step further and added code to address specular sun reflections, and, remove the moon glow from water which was annoying. It also reduces the reflective surface at higher altitudes but still allows them at lower, as water should display. Its not perfect but you can try the new code here:



aww Nick Undecided , what's pwheeler? well , Is this would change the nice moves and shining day of the watter like in the shot above? will be affected,  ..but I didn't check(saw) how was the reflex of the sun and the moon... Undecided Im confuse



All I can say is try it Alrot. Follow the same directions I posted for the first edit.. You can always go back to the one you like..  Smiley

I like the second one for several reasons. It is the one I am using for the recent water shots I posted. There are some things about it I do not like but I do not have time right now to go through the code and play with it.


When ever str!ker gets back on the ball he may be able to work with it and his interface
 
IP Logged
 
Reply #14 - Dec 23rd, 2007 at 2:52pm

NickN   Offline
Colonel
FSX runs fine... the problem
is you or your system

Posts: 6317
*****
 


Also, what it removes is the "glow' the moon makes on the entire water surface. I did not check it for the reflection on the moon itself





If you want the code which keeps all the moon glow but updates the rest, you can use this which I just edited special for you:



Code:
//---------------------------------------------------------------------------
// Flight Simulator X - Shader Effect Files
// Copyright (c) 2006, Microsoft Corporation
//---------------------------------------------------------------------------
#include <Common.fxh>
#include <MaterialDecl.fxh>
#include <D3D9Texture.fxh>
#include <FuncLibrary.fxh>

#define vLightDir vSunVectorWorld

// Potential textures
texture Water_BaseTexture		   : MATERIAL_BASE_TEXTURE;
texture Water_EnvTexture		    : MATERIAL_ENVIRONMENT_TEXTURE;
texture Water_BumpTexture		   : MATERIAL_BUMP_TEXTURE;

// Global variables
float3 vCamEyePoint : VIEWPOSITION;

float fTimeScale	  : WATER_BUMP_TIME_SCALE;
float fBumpScale	  : WATER_BUMP_SCALE;	    
float fBumpUVScale	: WATER_BUMP_UV_SCALE;
float fBumpU		: WATER_BUMP_DISTANCE_SCALE;
float fBumpV		: WATER_BUMP_LIGHT_SCALE;    
float fFresnelFactorMin : WATER_FRESNEL_FACTOR_MIN;  
float fFresnelFactorMax : WATER_FRESNEL_FACTOR_MAX;  
float fSpecularPower    : SPECULAR_POWER;
float fSpecularBoost    : SPECULAR_BOOST;
float fSpecularBlend    : SPECULAR_BLEND;
float fBumpRotation     : WATER_BUMP_ROTATION;
float fBumpTimeX1	 : WATER_BUMP_TIME_X1;	  
float fBumpTimeY1	 : WATER_BUMP_TIME_Y1;	  
float fBumpTimeX2	 : WATER_BUMP_TIME_X2;	  
float fBumpTimeY2	 : WATER_BUMP_TIME_Y2;	  
float fBumpTimeScale2   : WATER_BUMP_TIME_SCALE_2;  

// Samples used by this shader
sampler Water_BaseSampler = sampler_state
{
    Texture	 = (Water_BaseTexture);
    AddressU	= Clamp;	// terrain textures must be clamped
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_BumpSampler = sampler_state
{
    Texture	 = (Water_BumpTexture);
    AddressU	= Wrap;
    AddressV	= Wrap;
    AddressW	= Wrap;
    MinFilter     = D3DTEXF_LINEAR;
    MagFilter     = D3DTEXF_LINEAR;
    MipFilter     = D3DTEXF_LINEAR;
    MipMapLodBias = (State_MipMapLodBias);
};

sampler Water_EnvMapSampler = sampler_state
{
    Texture	 = (Water_EnvTexture);
    AddressU	= Clamp;
    AddressV	= Clamp;
    MinFilter     = (State_MinFilter);
    MagFilter     = (State_MagFilter);
    MipFilter     = (State_MipFilter);
    MipMapLodBias = (State_MipMapLodBias);
};

struct VSWATER20_INPUT
{
    float4 vPos	 : POSITION;
    float4 vColor     : COLOR0;
    float3 vNormal    : NORMAL;
    float2 vTex	 : TEXCOORD0;
};

struct VSWATER20_OUTPUT
{
    float4  vPos		    : POSITION;
    float   fFog		    : FOG;
    half4   vColor		  : COLOR0;

    float4 TexBump	  : TEXCOORD0;
    float4 TexEnvMap	: TEXCOORD1;
    float4 TexBase	  : TEXCOORD2;
    float4 MiscData		   : TEXCOORD3;
    float3 vNormalWS	: TEXCOORD4;
    float3 vPosWS		     : TEXCOORD5;
    float3 vEyePosWS	: TEXCOORD6;
    float4 TexScreen	: TEXCOORD7;
};

#define fresnMin 0.05
#define fresnMax 0.5

half fresnel2( half3 vEyeDir, half3 vSurfaceNorm )
{
  half frdot = min( 1 - dot(vEyeDir, vSurfaceNorm), 1 );
  return lerp( fresnMin, fresnMax, frdot * frdot );
}

VSWATER20_OUTPUT Water20VS(const VSWATER20_INPUT v,const bool b30Shader)
{
    VSWATER20_OUTPUT o = (VSWATER20_OUTPUT)0;

    // Transform to clip space
    o.vPos = mul(v.vPos, mFullProj);

    // Compute fog
    o.fFog = ComputeFog(o.vPos.w, FOG_END, FOG_RECIP, FOG_SELECT_VERTEX, FOG_SELECT_TABLE);

	  // Transform to world space
	  float3 vWorldPos = mul(v.vPos, mWorld);

    // Compute eye vector
	  float3 vEye = normalize(vCamEyePoint - vWorldPos);
	  
	  // Scale normal based bump based on dist
	  //float fNormalScale = max(1.0,length(vEye)-fBumpDistScale);

    // Scale bumpmap texture coordinates by detail coordinates
	  //float2 bmp = fmod(v.vPos.xz * (fBumpUVScale * 0.0001f),1024.0f);
	  float2 bmp = fmod((vWorldPos.xz + float2(fBumpU, fBumpV) - mWorld[3].xz) * (fBumpUVScale * 0.0001f),256.0f);    
	  float2 sc = float2(sin(fBumpRotation),cos(fBumpRotation));
	  if (b30Shader)
	  {
		    o.TexBump.xy = bmp + (fSimTime * fBumpTimeScale2)*float2(fBumpTimeX1,fBumpTimeY1);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fBumpTimeScale2)*float2(fBumpTimeX2,fBumpTimeY2))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }
	  else
	  {
		    o.TexBump.xy = bmp + (fSimTime * fTimeScale)*float2(0.4,-0.4);
		    o.TexBump.zw = (bmp*fBumpScale) + ((fSimTime * fTimeScale)*float2(-1.0,1.0))/2.0f;
		    o.TexBump.zw = float2(o.TexBump.z * sc.y - o.TexBump.w * sc.x, o.TexBump.z * sc.x + o.TexBump.w * sc.y);
	  }    

	  // Send out interpolated normal for lighting
    o.vNormalWS = normalize(TransformVectorToSpace(v.vNormal, mWorld));

	  // Send out eye pos
	  o.vPosWS    = vWorldPos;
	  o.vEyePosWS = vCamEyePoint;

	  // Output vertex color straight to PS
	  // The alpha component is used to represent the relative
	  // depth of the water, used in computing water translucenty
	  // The color component is simply the color scaled by the
	  // diffuse sun lighting component
    o.vColor.a = v.vColor.a;
    o.vColor.rgb = 0.5/*( 1 - fresnel2(vSunVectorWorld_Sun.xyz, o.vNormalWS.xyz) ) * 0.5*/;

    // Environment mapping is determined from the screen-space coordinates
    // of our geometry. This implies that we need to divide them by W, and then
    // offset/scale into a 0-1 range. Because of interpolation issues due to front
    // clipped geometry, the info is pre-processed and passed to the PS where the 1/W
    // is applied. We also apply the normal to the data to emulate reflections caused
    // by the animating geometry
    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www;
//    o.TexEnvMap.xyz = o.vPos.xyz+o.vPos.www*(1.0+0.25*o.vNormalWS.xzy/fNormalScale);
    o.TexEnvMap.w = 2.0*o.vPos.w;
    o.TexScreen.xyz = float3(1,-1,1)*o.vPos.xyz+o.vPos.www;
    o.TexScreen.w = 2.0*o.vPos.w;

    // Diffuse texture coordinates
    o.TexBase.xy = v.vTex;

    // Compute per-poly fresnel
	  o.MiscData.x = 1.0 - lerp(fFresnelFactorMin, fFresnelFactorMax, pow(smoothstep(0,1,saturate(-normalize(vWorldPos).y)),0.5));
	  o.MiscData.y = 0;
	  o.MiscData.z = 0;
	  o.MiscData.w = 0;

    return o;
}

float4 Water20PS(VSWATER20_OUTPUT Input, const bool b30Shader) : COLOR
{
    float4 Bump;
    float2 BumpEnv;
    float4 Color;
	  float2 specularFactor;

    // Renomalize the input vectors and determine the
    // eye vector for lighting and reflection
    float3 vEyeDirWS;
    vEyeDirWS = normalize(Input.vEyePosWS - Input.vPosWS);
	  
    
    // Sample the base color and bumpmaps
    // Since this is essentially a texbem style operation, we
    // manually apply the matrix to the bumpmap values, we then
    // scale our envmap texcoords by 1/W before factoring in the
    // bumpmap
	  float3 vSurfaceNorm;
    if (b30Shader)
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }
    else
    {
		Bump = tex2Dbias(Water_BumpSampler, float4(Input.TexBump.xy,0,-2.0f))
			   + tex2Dbias(Water_BumpSampler, float4(Input.TexBump.zw,0,-3.0f));
		Bump = normalize(Bump-1.0f);
		vSurfaceNorm = Bump.xzy;
		BumpEnv = (Input.TexEnvMap.xy/Input.TexEnvMap.w)+ (0.2f*Bump.xy);
    }

	  // Compute the diffuse lighting component of the water.
	  float3 vHN;
	  float3 vHN2;

    vHN = normalize(vEyeDirWS.xyz + vSunVectorWorld_Sun.xyz);
    vHN2 = normalize(vEyeDirWS.xyz + vSunVectorWorld_Moon.xyz);

    specularFactor = fSpecularBlend*(pow(fSpecularBoost*saturate(float2(dot(vSurfaceNorm, vHN),fSunMoonInterpolant * dot(vSurfaceNorm, vHN2))), fSpecularPower));
    
	  // Sample the water textures and determine the final color
	  float4 baseColor = tex2D(Water_BaseSampler, Input.TexBase);
	  float4 envColor = tex2Dbias(Water_EnvMapSampler, float4(BumpEnv.xy,0,1 * (Input.TexScreen.z/Input.TexScreen.w)));
	  
	  
	  float4 terrainColor = baseColor;
    float fAlpha = baseColor.a;
	  float4 fLand = { baseColor.a, baseColor.a, baseColor.a, baseColor.a };
	  
    half fr = fresnel2( vEyeDirWS.xyz, vSurfaceNorm.xyz);

    Color = half4( lerp( baseColor.rgb * 2 * Input.vColor.rgb, envColor.rgb, fr ), 1);
//    return Color;

    return float4(lerp(Color.xyz + (vSunDirectional * specularFactor.x * 0.5) + (0.3 * (specularFactor.y + saturate(dot(vSunVectorWorld_Moon,vSurfaceNorm)))).xxx, terrainColor.xyz, fLand),fAlpha);
}


// ------- 3.0 ----------
float4 Water30PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,true);
}

// ------- 2.0 ----------


float4 Water20PS(VSWATER20_OUTPUT Input) : COLOR
{
	  return Water20PS(Input,false);
}

// ------ VS ------
VSWATER20_OUTPUT Water20VS(VSWATER20_INPUT Input)
{
	  return Water20VS(Input,false);
}


 







=========================================================





NOTE TO Str!ker:

The code that pwhweeler added to the original is as follows:



Color = half4( lerp( baseColor.rgb
* 2 *
Input.vColor.rgb, envColor.rgb, fr ), 1);
//    return Color;

   return float4(lerp(Color.xyz + (vSunDirectional * specularFactor.x
* .5
)+ (0.3 * (specularFactor.y)).xxx, terrainColor.xyz, fLand),fAlpha);
}


which also removes the moon glow but leaves the moon reflection at lower altitude

and he edited the main values as such:

#define fresnMin 0.05
#define fresnMax 0.5


It does require the original code edit be in the file as well:


#define fresnMin x.x
#define fresnMax x.x

half fresnel2( half3 vEyeDir, half3 vSurfaceNorm )
{
 half frdot = min( 1 - dot(vEyeDir, vSurfaceNorm), 1 );
 return lerp( fresnMin, fresnMax, frdot * frdot );
}


and toward the bottom the original code edit,


   half fr = fresnel2( vEyeDirWS.xyz, vSurfaceNorm.xyz);





« Last Edit: Dec 23rd, 2007 at 5:02pm by NickN »  
IP Logged
 
Pages: 1 2 3 ... 13
Send Topic Print