N3zix
February 1, 2017, 2:14pm
1
I am working on a raycasted sphere shader in Unity, that used to work fine on Unity 5.4 and before in DX11 but behaves differently on Unity 5.5 DX11.
In Unity 5.4:
The same scene in Unity 5.5:
When changing the far plane to a small value, the sphere goes back to normal.
This bug is not observed with OpenGL or in DX9.
My guess is that Unity 5.5 changed something in the projection matrix for DirectX 11 but I cannot see any related change in the Unity 5.5 changelog.
Am I missing something obvious ?
It would help to see your shader code if possible. Are you doing any MATRIX_MVP mul()'ing?
N3zix
February 1, 2017, 3:18pm
3
Yeah, I do : o.p = UnityObjectToClipPos(spaceposition);//mul(UNITY_MATRIX_MVP, spaceposition);
In the vertex shader :
// vertex input: position
struct appdata {
float4 vertex : POSITION;
};
struct v2p {
float4 p : POSITION;
float4 i_near : TEXCOORD1;
float4 i_far : TEXCOORD2;
float4 colonne1 : TEXCOORD3;
float4 colonne2 : TEXCOORD4;
float4 colonne3 : TEXCOORD5;
float4 colonne4 : TEXCOORD6;
};
struct fragment_out
{
float4 color : SV_Target;
float depth : SV_Depth;
};
// VERTEX SHADER IMPLEMENTATION =============================
v2p ballimproved_v (appdata v) {
float4x4 ModelViewProjI = mat_inverse(UNITY_MATRIX_MVP);
v2p o; // Shader output
float4 spaceposition;
spaceposition.xyz = _TexPos.xyz;
spaceposition.w =1.0;
spaceposition.xyz += v.vertex.xyz * (2.0 * _Rayon);
o.p = UnityObjectToClipPos(spaceposition);//mul(UNITY_MATRIX_MVP, spaceposition);
v.vertex = o.p;
float4 near = o.p ;
near.z = 0.0 ;
near = mul(ModelViewProjI, near) ;
float4 far = o.p ;
far.z = far.w ;
o.i_far = mul(ModelViewProjI,far) ;
o.i_near = near;
...
return o;
}
You’re using the UnityObjectToClipPos, so that’s fine. Uhh, I notice you’re using depth as well, are you using UNITY_REVERSED_Z shader define macro to check if your depth value should be inverted?
N3zix
February 1, 2017, 3:59pm
5
I just tried and it does not fix the issue. Still, I think I have to do it.
N3zix
February 20, 2017, 9:36am
6
As expected, there was a problem with the calculation of the near and the far plane used to throw rays in the fragment shader.