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;
}