Created
November 27, 2015 17:11
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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