I’m currently exploring ZTesting and was wondering if there was a way to make the order of rendering right again? What I mean by that is when I use less, the order of rendering remains the same but when I use greater, the order of rendering reverses itself and places the furthest object in front the closer object when behind a desired mesh. I will add a picture below as well and the shader I’m using on the two cubes. The other objects are using the default diffuse material. And if the order cannot be put back to normal, is there any recommendations on another method?
Shader "Custom/Test"
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
}
Subshader
{
Tags {"Queue" = "Geometry+1"}
Pass
{
ZTest Greater
SetTexture [_MainTex]
}
}
}
[1462-Screen+shot+2012-07-01+at+2.01.20+AM.png|1462]
Why are you trying to change the ZTest condition? The ZTest was created exactly to make sure things are rendered in the right spatial order: each pixel in the screen has its depth (distance from the camera) saved in the corresponding position in the Z-buffer; when a new pixel is about to be rendered, the graphics card compares its calculated distance from the camera to the distance of the pixel already rendered at that screen position: if it’s lower, the new pixel overwrites the older one and its depth is saved in the Z-buffer. When you reverse the condition, farther objects are rendered over the closer ones, creating a weird and disturbing image.
Before Z-test was available in the GPU hardware, the game engines had to order the objects by distance, rendering the farther ones first. This slowed things down, and could produce wrong images when the objects intersected each other.
NOTE: This approach is still used for the transparent shaders (except the cutout ones), because they can’t write to the Z-buffer (this would destroy the pixels behind them).