Rendering right eye corrupted with Instanced Stereo Rendering and tessellation

Seems to be a known bug UE-30278. On Oculus Rift, stereo, Instanced Stereo enabled, on materials that utilize tessellation, Absolute World Position, CameraVector, and anything derived from them are incorrect for the right eye. On further investigation, the pixel shader was using all the transforms for the left eye, incorrectly, because the PackedEyeIndex was not being propagated all the way to the pixel shader.

I have a fix that seems to do the trick here. I inserted the following code just before the final “return O;” line at the end of VertexFactoryInterpolate function in LocalVertexFactory.usf:

<code>
// be sure to "interpolate" the eye index too, just copy from a
#if INSTANCED_STEREO
	O.InterpolantsVSToPS.PackedEyeIndex = a.InterpolantsVSToPS.PackedEyeIndex;
#endif
</code>

hope it helps! This isn’t really a question, more of a helpful hint for other users or anyone at Epic trying to fix bug UE-30278.

Hi there, really appreciate the fix!

Could you tell us where exactly to place it in the 4.12(.2) version of the LocalVertexFactory.usf file? Or maybe upload a modified one here?

The nearest “return O;” is in a #if USING_TESSELLATION, I tried putting it there but it didn’t help.

Sorry, I didn’t see that it should go in the function. I did this and I still get the glitch on the right eye…

Here is where I put your code in the function (line 29):

	FVertexFactoryInterpolantsVSToDS VertexFactoryInterpolate(FVertexFactoryInterpolantsVSToDS a, float aInterp, FVertexFactoryInterpolantsVSToDS b, float bInterp)
	{
		FVertexFactoryInterpolantsVSToDS O;
	
		// Do we really need to interpolate TangentToWorld2 here? It should be replaced by the
		// interpolated normal from 'whatever' interpolation scheme we're using
	
		TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.TangentToWorld0.xyz);
		TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.TangentToWorld2);
	#if INTERPOLATE_VERTEX_COLOR
		TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.Color);
	#endif
	#if USE_INSTANCING
		TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.PerInstanceParams);
	#endif

	#if NEEDS_LIGHTMAP_COORDINATE
		TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.LightMapCoordinate);
	#endif

	#if NUM_MATERIAL_TEXCOORDS
		UNROLL
		for(int tc = 0; tc < (NUM_MATERIAL_TEXCOORDS+1)/2; ++tc)
		{
			TESSELLATION_INTERPOLATE_MEMBER(InterpolantsVSToPS.TexCoords[tc]);
		}
	#endif
	// FIX COPIED FROM UE4 FORUMS
	#if INSTANCED_STEREO
		O.InterpolantsVSToPS.PackedEyeIndex = a.InterpolantsVSToPS.PackedEyeIndex;
	#endif
		return O;
	}

I tried this fix as well, no improvement. Tried a poking around with the code, but I don’t know enough about shader code to figure this out.

I did find it odd though that the only other reference in this file to PackedEyeIndex was on line 631:

#if INSTANCED_STEREO
    Interpolants.PackedEyeIndex = 0;
#endif

maybe it has something to do with this value being hard-coded here?