Need some assistance with merging 2 water shaders

Hello everybody,

first of all, I’m pretty new to shaders, to be honest I am just about to learn it.

Since I need some edge blend and shore foam on the water from scrawkblog.org - which is damn beautiful as it is already - I wanted to implement the code for edge blend and shore foam from the unity pro water shaders into the one I’m using.

FX-Water4.shader (unity pro):

OceanWhiteCaps.shader (scrawkblog.org):
OceanWhiteCaps.shader - Pastebin.com

I started with adding edge blend, as that is I believe it is the less complex one. What I did so far is adding the following to the frag part, as you can see in line 256-263:

half4 edgeBlendFactors = half4(1.0, 0.0, 0.0, 0.0);
                                half depth = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos));
                                depth = LinearEyeDepth(depth);
                                edgeBlendFactors = saturate(_InvFadeParemeter * (depth-IN.screenPos.w));               
                                edgeBlendFactors.y = 1.0-edgeBlendFactors.y;
                                col.rgb += (edgeBlendFactors.y + saturate(i.viewInterpolator.w));

Now I’m stuck at a few points… But first of all, let me list what I’ve got so far:

both shaders are using the frag part differently:

Unity Pro: half4 frag( v2f i ) : SV_Target

Scrawkblog: float4 frag(v2f IN) : COLOR

Half4 fits into float4 easily - that’s only a performance thing, have to see if I can adjust it down to using half4 maybe. But from what I’ve read so far, SV_Target seems to be something from an older unity version, and people use COLOR nowadays… but I’m still unaware of the differences, let alone what happens there at all.

My guess is that I need to use i.screenPos or more specific IN.screenPos, but obviously COLOR has different properties/functions(?) as SV_Target, so I would need to grab that value from somewhere else, but how? It would even help to have a grasp of what screen posion actually holds.

I hope someone had the patience to read through my mess, and can eventually help or guide me into the right direction!

Cheers,
WRZ

Edit: Codetags are working now.

Ok, I’ve found out that SV_Target is some DirectX system variable (hence the name), and I then found out, that I just have to declare screenPos etc. somewhere. I was able to do so and run everything without errors, but also with no different functionaities than before adding all those things.

Updated version: Updated Shader 1 - Pastebin.com

I tried adding ZTest and so on like in the Unity Pro Shader, but that didn’t work out either. Anyone has any idea? As said, I’m completely new to shaders… ;/