Skip to content

Instantly share code, notes, and snippets.

@wtekteam
Created November 27, 2015 17:11
Show Gist options
  • Save wtekteam/ee36d99fcd81b6dbbb70 to your computer and use it in GitHub Desktop.
Save wtekteam/ee36d99fcd81b6dbbb70 to your computer and use it in GitHub Desktop.
An easy implementation for a Wireframe render (to use with the specifical shader).
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Wireframe : MonoBehaviour
{
public Color lineColor;
public Material lineMaterial;
private MeshFilter filter;
void Start()
{
filter = GetComponent<MeshFilter>();
}
void OnRenderObject()
{
if(lineMaterial== null)
{
Debug.Log("no line material");
return;
}
lineMaterial.SetPass(0);
for(int i = 0; i < filter.mesh.triangles.Length; i++)
{
if(i%3 == 0)
{
if(i != 0)
GL.End();
GL.Begin(GL.LINES);
}
GL.Color(lineColor);
GL.Vertex(transform.TransformPoint(filter.mesh.vertices[filter.mesh.triangles[i]]));
}
GL.End ();
}
}
Shader "Custom/Wireframe"
{
SubShader
{
Pass
{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Off
Fog { Mode Off }
BindChannels
{
Bind "vertex", vertex
Bind "color", color
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment