Jump to content

  • Log In with Google      Sign In   
  • Create Account


Water Style Direction


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 riuthamus   Crossbones+   -  Reputation: 4328

Like
0Likes
Like

Posted 23 June 2012 - 03:00 AM

I wanted to get some feedback on our water. I think our effect is really good but there is something about the reflections that seem off. Is there any special techniques we should be using to make the water look a bit.... better? I am already very pleased with the look but just wanted to see what else we could do, or if people thought we needed to do anything.

Our current "suspected issue" is that we have mip mapping working, this makes the water look smooth really far. If we remove the mip mapping the water looks like dancing ants in the background... is there any tech that would give us a nice inbetween look?

Posted Image

Posted Image

Posted Image

Edited by riuthamus, 23 June 2012 - 03:04 AM.


Sponsor:

#2 tanzanite7   Members   -  Reputation: 1147

Like
1Likes
Like

Posted 29 June 2012 - 12:54 AM

A few thoughts:
* Use anisotropic filtering.
* Reflected sky is much brighter than the actual sky at/near horizon.
* Add a shimmer effect (in water plane direction at distance sample reflection with noise offset) - it is too clean reflection.

Use 3D texture for noise using z as time - for stable and pleasant shimmer.
Use more samples with noise offsets than one (diverging from one point outward in response to anisotropy and distance [ignore anisotropy at small distance - looks silly]).

Edited by tanzanite7, 29 June 2012 - 12:54 AM.


#3 Ashaman73   Crossbones+   -  Reputation: 6748

Like
3Likes
Like

Posted 29 June 2012 - 02:17 AM

The shading seems to be wrong. The reflected cubes in the first screenshots recieve more light than the original one, this is wrong. A similar issue in the last screenshot, where the mountain in the center is less fogged in the reflected version.

#4 riuthamus   Crossbones+   -  Reputation: 4328

Like
0Likes
Like

Posted 30 June 2012 - 12:58 AM

we are playing with the idea of tessellation, but that will not come until we figure out how we are going to make dynamic water. Right now, the obvious issue is the mipmapping fucking with our normal maps for the water. We are trying to resolve that.

#5 Telanor   Members   -  Reputation: 1284

Like
0Likes
Like

Posted 30 June 2012 - 01:15 AM

I'm the one that coded the water. I think one of the problems is that the normal map is in tangent space but we dont have code for tangent space normals. Also, our game uses Y = up. I'm not sure how that affects the water shader. I had to change the sampled value order to .rbg just to get it to not look completely messed up. The specular reflections also seem wrong to me, they only occur near the middle of the water.

What were you suggesting to enable anisotropic filtering on? The reflections/refractions or the normal map?

The code is mostly the same as from this tutorial

float4x4 World;
float4x4 View;
float4x4 ReflectionView;
float4x4 Projection;
float3 CamPos;
float FarPlane;
float4 WaterColor;
float WaveLength;
float WaveHeight;
float Time;
float WindForce;
float3 WindDirection;
float3 LightDirection;
Texture2D ReflectionMap;
Texture2D RefractionMap;
Texture2D DepthMap;
Texture2D BumpMap1;
Texture2D BumpMap2;

 //specular input variables
 float SpecPerturb = 1;
 float SpecPower = 354;

SamplerState RTSampler
{
	Filter = Min_Mag_Mip_Linear;
	AddressU = mirror;
	AddressV = mirror;
};

SamplerState MapSampler
{
	Filter = Min_Mag_Mip_Linear;
	AddressU = Wrap;
	AddressV = Wrap;
};

struct VertexShaderInput
{
	float4 Position : POSITION0;
	float3 Normal : NORMAL;
	float2 TexCoords : TEXCOORD0;
};

struct VertexShaderOutput
{
	float4 Position : SV_POSITION;
	float4 ReflectionMapSamplingPos : TEXCOORD0;
	float2 BumpMapSamplingPos : TEXCOORD1;
	float2 BumpMapSamplingPos2 : TEXCOORD2;
	float4 RefractionMapSamplingPos : TEXCOORD3;
	float4 Position3D : TEXCOORD4;
};

struct PixelShaderOutput
{
	float4 Color : SV_TARGET0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
	VertexShaderOutput output = (VertexShaderOutput)0;

	float4x4 worldViewProjection = mul(World, mul(View, Projection));
	float4x4 reflectionWorldViewProjection = mul(World, mul(ReflectionView, Projection));

	float3 windDir = normalize(WindDirection);
	float3 windDir2 = normalize(mul(WindDirection, float3x3(0.707, 0, -.707, 0, 1, 0, .707, 0, .707))); //45 degree rotation matrix
	float3 perpDir = cross(windDir, float3(0, 1, 0));

	float ydot = dot(input.TexCoords, windDir.xz);
	float xdot = dot(input.TexCoords, perpDir.xz);
	float2 moveVector = float2(xdot, ydot);
	float2 moveVector2 = float2(dot(input.TexCoords, cross(windDir2, float3(0, 1, 0)).xz), dot(input.TexCoords, windDir2.xz));

	moveVector.y += Time * WindForce;
	moveVector2.y += Time * 2 * WindForce; 

	output.Position = mul(input.Position, worldViewProjection);
	output.Position.z = log(0.001 * output.Position.z + 1) / log(0.001 * FarPlane + 1) * output.Position.w;
	output.ReflectionMapSamplingPos = mul(input.Position, reflectionWorldViewProjection);
	output.RefractionMapSamplingPos = output.Position;
	output.Position3D = mul(input.Position, World);
	output.BumpMapSamplingPos = moveVector / WaveLength;
	output.BumpMapSamplingPos2 = moveVector2 / (WaveLength / 2);
	
	//output.Depth.x = output.Position.z;
	//output.Depth.y = output.Position.w;

	return output;
}

PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
	PixelShaderOutput output = (PixelShaderOutput)0;

	float2 ProjectedTexCoords;
	float2 ProjectedRefrTexCoords;
	float3 BumpColor1 = BumpMap1.Sample(MapSampler, input.BumpMapSamplingPos).rgb;
	float3 BumpColor2 = BumpMap1.Sample(MapSampler, input.BumpMapSamplingPos2).rgb;
	//float3 BumpColor = float3(BumpColor1.xy + BumpColor2.xy, BumpColor1.z * BumpColor2.z);
	float3 BumpColor = normalize(2 * (BumpColor1 + BumpColor2) - 2);

	ProjectedTexCoords.x = input.ReflectionMapSamplingPos.x / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f;
	ProjectedTexCoords.y = -input.ReflectionMapSamplingPos.y / input.ReflectionMapSamplingPos.w / 2.0f + 0.5f;

	ProjectedRefrTexCoords.x = input.RefractionMapSamplingPos.x / input.RefractionMapSamplingPos.w / 2.0f + 0.5f;
	ProjectedRefrTexCoords.y = -input.RefractionMapSamplingPos.y / input.RefractionMapSamplingPos.w / 2.0f + 0.5f;

	float2 perturbation = WaveHeight * (BumpColor);
	float2 perturbatedTexCoords = ProjectedTexCoords + perturbation;
	float2 perturbatedRefrTexCoords = ProjectedRefrTexCoords + perturbation;

	float4 ReflectiveColor = ReflectionMap.Sample(RTSampler, perturbatedTexCoords);
	float4 RefractiveColor = RefractionMap.Sample(RTSampler, perturbatedRefrTexCoords);

	//output.Color = RefractiveColor;
	//return output;
	//clip(input.Depth.x / input.Depth.y - Depth);

	float3 eyeVector = normalize(CamPos - input.Position3D);
	float3 normalVector = (BumpColor.rbg);
	float fresnelTerm = 0.02f+0.97f*pow((1-dot(eyeVector, normalVector)),5);
	//float fresnelTerm = dot(eyeVector, normalVector);
	//fresnelTerm = 1 - fresnelTerm * 1.3f;
	
	float3 reflectionVector = -reflect(LightDirection, normalVector);
	//float specular = dot(normalize(reflectionVector), normalize(eyeVector));

	//specular = pow(specular, 256);


	float4 specColor;
	float3 lightSourceDir = normalize(-LightDirection);
	//float3 lightSourceDir = normalize(float3(0.8f, 0.1f, 0.0f));
	float3 halfvec = normalize(eyeVector + lightSourceDir + float3(perturbation.xy * SpecPerturb, 0));
	float3 temp = 0;

	temp.x = pow(dot(halfvec, normalVector), SpecPower);

	specColor = float4(1, 1, 1, 1);
	specColor *= temp.x;
	specColor = float4(specColor.xyz * specColor.w, 0);


	fresnelTerm = clamp(fresnelTerm, 0, 1);
	//float4 combinedColor = lerp(ReflectiveColor, RefractiveColor, fresnelTerm);
	float4 combinedColor = RefractiveColor * (1 - fresnelTerm) + ReflectiveColor * fresnelTerm;

	output.Color = lerp(combinedColor, float4(WaterColor.rgb, 1), WaterColor.w) + specColor;
	//output.Color = WaterColor;

	return output;
	//return float4(1,1,1,0.0);
}

technique11 Water
{
	pass Pass1
	{
		SetVertexShader(CompileShader(vs_4_0, VertexShaderFunction()));
		SetPixelShader(CompileShader(ps_4_0, PixelShaderFunction()));
	}
}

Attached Thumbnails

  • RuinValor 2012-06-30 03-14-49-33.png

Edited by Telanor, 30 June 2012 - 01:17 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS