User avatar
hahaljk
Topic Author
Posts: 2
Joined: 03 Dec 2017, 13:15

Render Problem with GL

15 Mar 2021, 16:46

When I use GL to render some line in OnRenderObject(),get some unexpected screen as below.
snipaste20210315_233934.jpg
Grid Overlay
snipaste20210315_234029.jpg
Red Block is cursor render by GL.
In the second pic, the red block is front of NoesisUI, but hidden by door.
And the door is hidden by NoesisUI.

I think the prombe is the ZTest of NoesisUI?
All the girds and red block should be overlay by UI.
 
void OnRenderObject()
{
	if(!_IsEnable)
		return;

	if (!_LineMaterial)
	{
		_LineMaterial = new Material(Shader.Find("Lines/Colored Blended"));
	}

	if (_HitCellPoint_InWorld.HasValue)
	{
		// set the current material
		_LineMaterial.SetPass(0);
		GL.Begin(GL.QUADS);
		GL.Color(new Color(255, 0, 0));

		GL.Vertex3(_HitCellPoint_InWorld.Value.x, _HitCellPoint_InWorld.Value.y, _HitCellPoint_InWorld.Value.z);
		GL.Vertex3(_HitCellPoint_InWorld.Value.x + 1, _HitCellPoint_InWorld.Value.y, _HitCellPoint_InWorld.Value.z);
		GL.Vertex3(_HitCellPoint_InWorld.Value.x + 1, _HitCellPoint_InWorld.Value.y, _HitCellPoint_InWorld.Value.z + 1);
		GL.Vertex3(_HitCellPoint_InWorld.Value.x, _HitCellPoint_InWorld.Value.y, _HitCellPoint_InWorld.Value.z + 1);
		GL.End();
		
		GL.End();
	}
}   
The Shader:
Shader "Lines/Colored Blended"
{
    SubShader
    {
        Pass
        {
            Blend SrcAlpha OneMinusSrcAlpha
            //ZWrite On 
            //ZTest Always
            Cull Off 
            Fog {
                Mode Off
            }
            BindChannels {
                Bind "vertex", vertex Bind "color", color
            }
        }
    }
}

Tags:
 
User avatar
jsantos
Site Admin
Posts: 3059
Joined: 20 Jan 2012, 17:18
Contact:

Re: Render Problem with GL

16 Mar 2021, 12:43

Noesis doesn't use ZTest. We always render our geometry at the end of the camera. The details depends on the kind pipeline you are using but in the fixed pipeline it is happening here (in NoesisView.cs):
private void OnPostRender()
{
    RenderOnscreen();
}
Not sure when that OnRenderObject you mention is happening but you need to make sure it happens after or before our RenderOnscreen depending on the effect you want to achieve.
 
User avatar
hahaljk
Topic Author
Posts: 2
Joined: 03 Dec 2017, 13:15

Re: Render Problem with GL

16 Mar 2021, 15:00

Thank you for your hints.
I solved the promble.

First, NoesisGUI render GUI on Camera's OnPostRender();
GL render lines or other thins on GameObject's OnRenderObject();
Accoring Unity's official document:
OnRenderObject: Called after all regular scene rendering is done.
OnPostRender: Called after a camera finishes rendering the scene.
There is no absolute order when two functions are called.
In my project, OnRenderObject is called after OnPostRender, so the promble appeared.

To solve it, I move NoesisGUI's rendering at the end of Frame();
Changes to NoesisView.cs:
public class NoesisView: MonoBehaviour, ISerializationCallbackReceiver
{
	......
    void OnEnable()
    {
        StartCoroutine(WaitRoutine());
        ......
    }
    void OnDisable()
    {
        StopAllCoroutines();
    }
    IEnumerator WaitRoutine()
    {
        while (true)
        {
            yield return new WaitForEndOfFrame();
            DrawLast();
        }
    }
    private void OnPostRender()
    {
        //RenderOnscreen();
    }

    private void DrawLast()
    {
        RenderOnscreen();
    }
}
3.jpg
 
User avatar
jsantos
Site Admin
Posts: 3059
Joined: 20 Jan 2012, 17:18
Contact:

Re: Render Problem with GL

16 Mar 2021, 16:44

Great! Thanks for the feedback!

Who is online

Users browsing this forum: Bing [Bot] and 1 guest