i’am drawing a circle with the gl class.
but i have a performance issue with it.
if i draw a circle on a scene the fps drops from 90 to 30 on a powerbook
anyone have a idea how i can do it better ?
function OnPostRender() {
DrawCirlce(3,Vector3(0,0,0), Color.black);
}
function DrawCirlce(radius, pos, color) {
DEG2RAD = 3.14159/180;
GL.PushMatrix();
GL.Begin(GL.LINES);
GL.Color(color);
degInRad = DEG2RAD;
for (i=0; i <= 360; i++) {
GL.Vertex3(pos.x+(Mathf.Cos(degInRad)*radius),pos.y,pos.z+Mathf.Sin(degInRad)*radius);
degInRad = i*DEG2RAD;
GL.Vertex3(pos.x+(Mathf.Cos(degInRad)*radius),pos.y,pos.z+Mathf.Sin(degInRad)*radius);
}
GL.End();
GL.PopMatrix ();
}
First thing to try is check where you’re using non-static types in your script. Add #pragma strict at the top of your script and the compiler will tell you that.
In your case, at least the parameters to DrawCirlce function are untyped, so each time you access them, their types are looked up, checked, and so on. Changing the function to
function DrawCirlce(radius : float, pos : Vector3, color : Color)
will make it use static typing.
…the other thing is, of course: don’t measure the performance in the editor. The editor has all sorts of overhead and timing issues, so a 50% drop in FPS while in the editor might mean a 5% performance drop in the actual game (well, that’s an extreme example, but still).
i have a problem with gl again.
if i use the code above and put a particlesystem in the middle of the cirlce i can see the complet circle if i use a diffuse shader or bump all is perfect. what is the problem ?
This is because particle shaders don’t write into depth buffer. So particles don’t affect visibility of any other objects.
The solution to this, I think, would be not using GL class to draw a circle; instead make a mesh that looks like a circle (a thin torus), and draw that like any other mesh. It will be hard to make it one-pixel-wide though.
Yep. Dont save scripts as attachments when posting. The forum changes the name when you download them(mine downloaded as Primitives_380.cs or similar) and as you know, that wont work. i saved it as primitives, and the p should ve been P. then unity was a bitch and refused to let me change it from p to P (why is that?) so after fiddleassing around, I renamed it in finder, But theres no circle here…
So please archive your scripts first-it will save us some time fixing them on arrival.
try this shader anyway. I cant test it because I cant get a circle.
AC
All I did was change an “off” line to “on” like Aras said in another post, I have no idea if it will work…
Because Unity assumes they are the same. So you have to change it to something else first, like “Primitives” → “primitivesx” → “primitives”. This is actually kind of annoying since Unity is case-sensitive everywhere else, so it would make sense for that to apply everywhere. Or nowhere.
The Primitives class dont need unity pro.
it create a torus mesh. It is a utility class so its not drevin from MonoBehaviour class and cant drag and drop of a gameobject. It is used in my view classes that are driven from monobehaviour
but for testing here is a version that can be drag and drop on a gameobject.