Render Problem with GL
When I use GL to render some line in OnRenderObject(),get some unexpected screen as below.
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.
The Shader:
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.
Code: Select all
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();
}
}
Code: Select all
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
}
}
}
}
Re: Render Problem with GL
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):
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.
Code: Select all
private void OnPostRender()
{
RenderOnscreen();
}
Re: Render Problem with GL
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:
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:
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:
There is no absolute order when two functions are called.OnRenderObject: Called after all regular scene rendering is done.
OnPostRender: Called after a camera finishes rendering the scene.
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:
Code: Select all
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();
}
}
Re: Render Problem with GL
Great! Thanks for the feedback!
Who is online
Users browsing this forum: No registered users and 27 guests