line rendering and normals?

hi guys!

I’m rendering lots of lines (thousands, and the more the merrier!) using opengl approach (seems to be the fastest, instead of creating a mesh). So I have 2 questions:

  1. can I do it faster??

  2. how can i have normals in the shader? I want to put some illumination on them, specular, or something else, but I don’t know how to pass the normals. Or how to calculate them in the shader, how can I get the current line segment?

Any ideas?!

Thanks!

It’s not necessarily fastest to use GL, since that’s immediate mode and has to be done every frame. Also meshes in Unity 4 can use MeshTopology.Lines.

–Eric

with GL.LINES you should be able to draw even a million of lines, although they would need to be unshaded. If you want them shaded (behave like pipes?), I fear you have to render them with screen aligned quads. The normals could then be computed from the uv coordinates you’ll assign.

so, keeping with GL.LINES, and just rendering lines, no tubes or pipes. how can I have specular light, shininess depending on the camera view?

Use Vectrosity (it’s going to just work) or use MeshTopology.Lines. You can’t with GL.LINES unless you render them to a texture first then blend that texture back over on the screen as a quad, which is just silly.

What do you expect the normals to look like then?

Wanted to have some specularity on them.
And how can I change the vertex color, in the shader, not using a texture, with something like Unity - Manual: Surface Shader examples

Let me show the shader I’ve put together. I want to change the color of the vertex in the shader, like using the normal. And although I have the colors in the preview material/shader, in the render all is shades of white…

Shader “Lines/ShinyShader” {

Properties {
_MainTex (“Base (RGB)”, 2D) = “green” {}
_Shininess (“Shininess”, Range (0.01, 1)) = 1
}

SubShader {
Tags { “Queue” = “Transparent” }
LOD 300

ZWrite Off
Alphatest Greater 0

Blend SrcAlpha OneMinusSrcAlpha
ColorMask RGB
Lighting On
SeparateSpecular On

CGPROGRAM
#pragma surface surf Lambert finalcolor:mycolor vertex:myvert

sampler2D _MainTex;
fixed4 _Color;
half _Shininess;

half4 LightingSimpleSpecular (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
float lt = dot(lightDir, s.Normal);
float vt = dot(viewDir, s.Normal);
float ln = sqrt(1.0 - pow(lt,2.0));
float vr = ln * sqrt( 1 - pow(vt, 2.0) ) - (lt*vt);

//I = ka + kd(l.n) + ks(v.r)^n
half3 h = normalize (lightDir + viewDir);

//half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));

float spec = pow (vr, 48.0);
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * ln) + (_LightColor0.rgb * spec) * (atten * 2);
c.a = s.Alpha;

return c;
}

struct Input {
float2 uv_MainTex;
float3 customColor;
};

void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);

o.Albedo = c.rgb;
o.Albedo = IN.customColor;
//o.Gloss = c.rgb;
o.Alpha = c.a;
//o.Specular = _Shininess;
//o.Albedo = IN.customColor.rgb; // vertex RGB
//o.Alpha = IN.customColor.a; // vertex Alpha
}

void myvert(inout appdata_full v, out Input data)
{
UNITY_INITIALIZE_OUTPUT(Input,data);
data.customColor = normalize(v.normal);// * 0.5 + 0.5;
}

void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
{
color.rgb = IN.customColor;
o.Albedo = IN.customColor;
}
ENDCG
}

Fallback “VertexLit”
}

Are you using mat.SetPass(0) to tell it to use this shader? Also I’m not clear on what your plans for normals are with GL.LINES.

Doesn’t seem to help the .SetPass(0)
Trying to have some specularity, to give a bit of 3d perception to a bunch of lines.

Have you read the GL.LINES docs?