- Home /
How can I have the camera forward in a vertex shader?
I want to create a Rim Shader like this: http://spong.com/screen-shot/b/a/batmanarkh334306l/_-Batman-Arkham-City-Enhanced-Detective-Mode-Detailed-_.jpg
I know that is pretty simple in surface, but I need it in a vertex shader. I tried using what it says here http://answers.unity3d.com/questions/170589/shader-actual-view-directionnormal.html but it doesn't work.
Here is my code:
Shader "Custom/Rim"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
}
SubShader
{
Pass{
Blend One OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
struct input{
float4 vertex:POSITION;
float3 normal:NORMAL;
};
struct output{
float4 vertex:SV_POSITION;
float3 normal;
float3 viewDir: TEXCOORD0;
};
output vert (input i){
output o;
o.vertex = mul(UNITY_MATRIX_MVP, i.vertex);
o.normal = i.normal;
//Also tried this:
//o.viewDir = mul((float3x3)UNITY_MATRIX_IT_MV, i.normal);
o.viewDir = normalize(WorldSpaceViewDir(o.vertex));
return o;
}
float4 frag (output o):COLOR{
half rim = 1 - dot(normalize(o.viewDir), o.normal);
float4 c;
c = _Color;
c.a = rim;
return c;
}
ENDCG
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How can I make rim lighting appear in front of everything? 1 Answer
Fade shader based on heading angle to camera not working 1 Answer
Semi transparent Object behind walls? 1 Answer
Camera with shader? 2 Answers
Shader to a Camera 1 Answer