Hi, I’m working on a post effect
and for that i need to render set of meshes to texture with ZTest LEqual to create a mask
here is a sphere rendered to separate texture
so i’m creating new RenderTexture and setting it as active color buffer while leaving depth buffer unchanged
rendering what i need and resetting render target
and everything works perfect
but when i’m enabling Direct3D in player settings and enabling anti-aliasing in quality settings
i’m getting an error:
ArgumentException: Graphics.SetRenderTarget called with depth RenderBuffer from screen and color RenderBuffer from RenderTexture
UnityEngine.Graphics.SetRenderTargetImpl (RenderBuffer colorBuffer, RenderBuffer depthBuffer, Int32 mipLevel, CubemapFace face, Int32 depthSlice) (at C:/buildslave/unity/build/Runtime/Export/Graphics.cs:189)
UnityEngine.Graphics.SetRenderTarget (RenderBuffer colorBuffer, RenderBuffer depthBuffer) (at C:/buildslave/unity/build/Runtime/Export/Graphics.cs:225)
here is my code:
void OnRenderImageTest0(RenderTexture source, RenderTexture destination){
// create new render target
RenderTexture rt = RenderTexture.GetTemporary(_camera.pixelWidth, _camera.pixelHeight);
rt.Create();
RenderBuffer tmp = Graphics.activeColorBuffer;
// change render target
Graphics.SetRenderTarget(rt.colorBuffer, Graphics.activeDepthBuffer);
...
// render meshes
...
// reset render target
Graphics.SetRenderTarget(tmp, Graphics.activeDepthBuffer);
rt.Release();
}
is it a bug or i’m doing something wrong?
is there any way to do that on Direct3D with enabled anti-aliasing?
here i’ve found that
But in my case size is equal.
unity documentation says:
When implementing complex Shaders or Image Effects, keep Rendering Differences Between Platforms in mind. In particular, using depth texture in an Image Effect often needs special handling on Direct3D + Anti-Aliasing.
In some cases, the depth texture might come directly from the native Z buffer. If you see artifacts in your depth texture, make sure that the shaders that use it do not write into the Z buffer (use ZWrite Off ).
ok, I have ZWrite Off
more from docs:
Vertical Texture coordinate conventions differ between two types of platforms: Direct3D-like and OpenGL-like.
…
When you use Image Effects and anti-aliasing, the resulting source Texture for an Image Effect is not flipped to match the OpenGL-like platform convention. In this case, Unity renders to the screen to get anti-aliasing and then resolves rendering into a Render Texture for further processing with an Image Effect.
…
…
…
Depth (Z) direction differs on different Shader platforms.
…
If you are fetching the depth (Z) buffer value manually, you might want to check the buffer direction.
this is clear, but what i can do in my case?