Weird problem with fresnel and specular in custom shader

So im trying to do a water shader, where i have fresnel reflections and standard phong specular, but for some reason specular and fresnel parts almost never intersect, which causes those both to look like they are on separate independent layers. Heres what i mean (im outputting float4(fresnel, specular, 0, 1) here):


As you can see there are almost no yellow colors (this is what intersection of green and red would be) in here, except in the distance. It breaks the illusion super quickly, especially in motion, its looks just like i overlayed 2 textures on top of another. Heres my code for fresnel and specular, nothing special really, all the basics:

Fresnel:

float3 viewVec = i.wpos - _WorldSpaceCameraPos;
float3 viewDir = normalize(viewVec);
float reflFresn = pow(1-saturate(dot(wnorm, -viewDir)), _ReflPower);

Specular:

float3 lightDir = normalize(_WorldSpaceLightPos0.xyz);
float3 reflv = reflect(lightDir, wnorm);
float spec = pow(abs(dot (reflv, -viewDir)), _SpecShine) *_SpecMult;

Also tried it with halfway vector now, the results are pretty much the same

Hi, could you provide more details? How do you get world normal?
Or maybe you can check if lightDir is (0,0,0).

Hello. The world normal is basic, since the geometry is always in the xz plane:

float3 texNorm = UnpackNormal(tex2D(_NormalTex, i.wpos.xz)).rbg;

The problem occurs even with one stationary normal map, so the culprit is not the way i combine normals or move them.

The lightDir is never (0,0,0) but there is something weird happenning with it, if theres no shadow casters in the view - it gets reversed, for some reason. I think its engine’s deferred-specific thing and not a shader problem. Im gonna test that more today.

Sounds like what happens if you don’t have a LightMode tag assigned on a forward lit object.
https://docs.unity3d.com/Manual/SL-PassTags.html

You probably need to add Tags { “LightMode”=“ForwardBase” }

As for the issue you’re actually posting about, I don’t see anything wrong in the above image. It looks exactly how I would expect an image to look with fresnel and a specular light coming from different directions using blinn phong and normal maps. The overlap is going to be quite small. Any blend between the two would only occur when using super sampling or some form of specular AA.

Ah, yup, i didnt have any lightmode tags at all. Will try that, thanks.
UPD: ive added the ForwardBase tag, and now light direction is consistant, but reversed. Strange. Or is it normal? I thought that it should be the direction of the forward vector of the light, but its the backward vector now.

But they are not coming from different directions, the screenshot doesnt show that, my bad, but light is located right above the frame (about 30 degrees on x rotation), its not behind the camera. Even if i put the light directly at horizon (0 degrees) the specular still barely intersects with fresnel. It only starts to properly intersect if the light goes below the ground (negative rotation i mean)

Fresnel is ndotv, or the dot product of the surface normal and the view direction. If the camera is looking down the fresnel is similar to a directional light facing upward (using a negative rotation as you put it) for most of the screen. So, yeah, if you want them to intersect that’s what you would have to do.

Again, nothing here is wrong mathematically. This is "how it works"™.

Hm, maybe its not wrong mathematically, but its definetly not how it should be in real life. Ive drawn a crude schematic how it should be actually.
3204207--245052--Fresnel.png
Since fresnel reflects the sky, there should be a possible situation where it reflects the part of the sky where the sun is, and specular is just a reflection of the light source. I dont understand how is that accurate representation.
(http://creativity103.com/collections/AbstractLight/sunset_glow4221100.JPG) This is another example, you can see that specular is happening where the fresnel is.

You are correct here, but real life has built in super-sampling. Each pixel on screen has a single normal, and the reflected angle is either going to be pointing towards a light, or towards the view angle. In a photo each pixel in the image is going to be the reflected light from many different surfaces, basically every surface within the bounds of that pixel’s “window” into the world. Some of those are reflecting the sun, some are reflecting the horizon, and they get blended together.

There’s also the difference between fresnel and reflection. The basic ndotv Fresnel is an approximation of the real world behavior. In the real world Fresnel affects the amount of reflection a surface has, but isn’t the reflection itself. In the real world you’re seeing the reflection of the sky. There’s also some fun stuff like normal maps can point the calculated surface direction to be pointing away from the camera, which isn’t possible in the real world since anything pointed away from the viewer wouldn’t be visible, but ends up mimicking some of that reflection look we expect. It’s wrong though, and messes with the directional light specular further.