GL performance issue

hi,

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 :frowning:

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).

if i set the types the performance is great :slight_smile: thanks…

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 :frowning: if i use a diffuse shader or bump all is perfect. what is the problem ?

45518--1648--$bild_1_204.png
45518--1649--$bild_2_749.png

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.

any chance to get a unity class to draw circle, lines in unity 2 ?

Well, you just made helper code to draw a circle yourself… :slight_smile:

here a class to generate a circle … is a little bit quick and dirty ^^ any suggestion to do it better ?

45624–1655–$primitives_308.cs (3.84 KB)

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…

45633–1656–$particle_addshader_430.zip (915 Bytes)
45633--1657--$picture_1_379.png

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. :wink:

–Eric

Targos: you need pro to use GL commands, so if you don’t have pro maybe that’s why you are not seeing them.

-Jeremy

Oh well now it makes sense…Thanks for the heads up…
AC

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 :smile:

but for testing here is a version that can be drag and drop on a gameobject.

45696–1660–$primitives_966.zip (1.23 KB)

heh, cool.

Im pleased to see the shader works
AC :smile:

45697--1661--$picture_1_105.png