# Water effects

## Recommended Posts

xlope01    215

Hey,

Any suggestion on how to make the water area that do not have specular to look like the spot that i have mark with the red circle(to create small white specs)


SamplerState SampleType;
Texture2D normalTexture : register(t0);

cbuffer WaterBuffer
{
float4 refractionTint;
float3 lightDirection;
float waterTranslation;
float reflectRefractScale;
float specularShininess;
};

struct PixelInputType
{
float4 position : SV_POSITION;
float4 reflectionPosition : TEXCOORD0;
float4 refractionPosition : TEXCOORD1;
float3 viewDirection : TEXCOORD2;
float2 tex1 : TEXCOORD3;
float2 tex2 : TEXCOORD4;
};

float4 WaterPixelShader(PixelInputType input) : SV_TARGET
{
float4 normalMap1;
float4 normalMap2;
float3 normal1;
float3 normal2;
float3 normal;
float4 color;
float3 reflection;
float specular;

// Move the position the water normal is sampled from to simulate moving water.
input.tex1.y += waterTranslation;
input.tex2.y += waterTranslation;

// Sample the normal from the normal map texture using the two different tiled and translated coordinates.
normalMap1 = normalTexture.Sample(SampleType, input.tex1);
normalMap2 = normalTexture.Sample(SampleType, input.tex2);

// Expand the range of the normal from (0,1) to (-1,+1).
normal1 = (normalMap1.rgb * 2.0f) - 1.0f;
normal2 = (normalMap2.rgb * 2.0f) - 1.0f;
normal = normalize(normal1 + normal2);

color = float4(0,0,1,0);

// Calculate the reflection vector using the normal and the direction of the light.
reflection = -reflect(normalize(lightDirection), normal);

// Calculate the specular light based on the reflection and the camera position.
specular = dot(normalize(reflection), normalize(input.viewDirection));

// Check to make sure the specular was positive so we aren't adding black spots to the water.
if(specular > 0.0f)
{
specular = pow(specular, specularShininess);

color = saturate(color + specular);
}

reflection = -reflect(normalize(float3(-1.0f, -2.0f, 3.2f)), normal);

color = saturate(color + normalize(float4(reflection.x,reflection.y,reflection.z, 0)));

return color;
}



#### Share this post

##### Share on other sites
Seabolt    781

I'm not sure I understand the question, the area you've circled has specular highlights. You could try to fake some specular lighting on the crests of your waves, but that'll be very fake looking.

#### Share this post

##### Share on other sites
xlope01    215

I'm not sure I understand the question, the area you've circled has specular highlights. You could try to fake some specular lighting on the crests of your waves, but that'll be very fake looking.

yeap, this is what I am trying to do.

This is what I have manage to do, looks better than before but still doesn't look that good.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now