Created
February 21, 2014 11:47
-
-
Save HilariousCow/9132977 to your computer and use it in GitHub Desktop.
Ribbon Shader (expands an infinitely thin ribbon using direction to camera, and direction to next/prev ribbon node)
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 "BezzyLines/VertexTextureAlpha" { | |
Properties { | |
_MainTex ("Base (RGB)", 2D) = "white" {} | |
} | |
SubShader { | |
Tags | |
{ | |
"Queue"="Transparent" | |
"IgnoreProjector"="False" | |
"RenderType"="Opaque" | |
} | |
Pass{ | |
Cull off | |
ZWrite On | |
ZTest LEqual | |
Blend SrcAlpha OneMinusSrcAlpha | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
#pragma glsl_no_auto_normalization | |
sampler2D _MainTex; | |
struct appdata { | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 color : COLOR; | |
float4 texcoord: TEXCOORD0; | |
}; | |
struct v2f { | |
float4 pos : SV_POSITION;//This gets "eaten up" when sent to frag, and thus is not actually available directly | |
float4 color : COLOR; | |
float2 uv : TEXCOORD0; | |
}; | |
//the line's width is proportional to its depth, right? | |
//so offset after view pos is done. | |
v2f vert(appdata v) | |
{ | |
v2f o; | |
//World space pos and normal (which is actually tangential to the central line) | |
float4 worldPos = mul(_Object2World, v.vertex); | |
float3 normal = mul((float3x3)_Object2World,v.normal); | |
float3 width = length(normal); | |
float3 delta =normalize(worldPos.xyz - _WorldSpaceCameraPos); | |
float3 crossProd = normalize(cross( delta, normal));//work out new normal in worlds space | |
worldPos.xyz += crossProd * width; | |
//view and projection now that vertex offset is done. | |
o.pos = mul(UNITY_MATRIX_VP, worldPos); | |
//Standard texture stuff. | |
o.uv = MultiplyUV (UNITY_MATRIX_TEXTURE0, v.texcoord); | |
o.color = v.color; | |
return o; | |
} | |
float4 frag(v2f p) : COLOR | |
{ | |
return tex2D(_MainTex, p.uv) * p.color; | |
} | |
ENDCG | |
} | |
} | |
FallBack "Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment