Custom Z-buffer problem on mac and windows

Hello

I am making a shader that uses modified z-buffer. I have modified a vertex shader to:

v2f vert (appdata v) {
		    v2f o;
		    const float C = 0.1;  
		    const float far = 1.0e10;  
		    const float offset = 1.0;
		    o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
		    o.pos.z = ( 2 * log(C*v.vertex.z+offset) / log(C*far+offset) - 0 ) * v.vertex.w;
		    o.uv = float4( v.texcoord.xy, 0, 0 );
		    return o;
		}

Take a look at the result screenshot showing the scene in unity, running under windows and mac.

The problem is that it looks as it should on Mac, and it looks weird on Windows. The code seems to be ok, so what could be the problem then? :face_with_spiral_eyes: Buld&Run shows the exact same results.

Windows runs on direct x, mac on opengl.
Just a thought.
Try -force-opengl commandline on windows to see if that changes anything

According to that blog post you do indeed need different expressions for direct x and opengl

Note about that windows uses directx and mac - opengl ancually helped a lot. Yes, as it was stated in the blog, I changed one number and it worked! Also -force-opengl worked nice!

Now I have 1 question:

  1. How do I force it automatically use opengl everywhere withount specifying -force-opengl every time?

You can’t. Windows unity uses direct x by default and that’s it.