Skip to content

Instantly share code, notes, and snippets.

@smkplus
Forked from sugi-cho/ImageEffectBase.shader
Created December 12, 2017 08:47
Show Gist options
  • Save smkplus/eac847627627227def18da77a8b920bb to your computer and use it in GitHub Desktop.
Save smkplus/eac847627627227def18da77a8b920bb to your computer and use it in GitHub Desktop.
use vertex shader in surface shader
Shader "Custom/ImageEffectBase" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _MainTex_TexelSize;
half4 frag(v2f_img i) : COLOR{
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
i.uv.y = 1-i.uv.y;
#endif
return tex2D(_MainTex, i.uv);
}
ENDCG
SubShader {
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
pass{
CGPROGRAM
#pragma fragmentoption ARB_precision_hint_fastest
#pragma vertex vert_img
#pragma fragment frag
ENDCG
}
}
}
Shader "Custom/SurfVertexBase" {
Properties {
_MainTex("texture", 2D) = "white" {}
}
CGINCLUDE
sampler2D _MainTex;
struct Input {
half4 vColor;
half2 tex;
};
void vert (inout appdata_full v, out Input o){
UNITY_INITIALIZE_OUTPUT(Input,o);
o.vColor = v.color;
o.tex = v.texcoord.xy;
}
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_MainTex, IN.tex);
o.Emission = IN.vColor;
}
ENDCG
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert noforwardadd
ENDCG
}
FallBack "Diffuse"
}
Shader "Custom/v2fBase" {
Properties {
_Color ("color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("texture", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
fixed4 _Color;
struct v2f {
float4 pos : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float3 wPos : TEXCOORD1;
float4 sPos : TEXCOORD2;
float3 cPos : TEXCOORD3;
};
v2f vert (appdata_full v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.wPos = mul(_Object2World, v.vertex).xyz;
o.sPos = ComputeScreenPos(o.pos);
o.cPos = mul(_Object2World, half4(0,0,0,1));
o.color = v.color;
o.texcoord = v.texcoord;
return o;
}
half4 frag (v2f i) : COLOR
{
return i.color * _Color * tex2D(_MainTex, i.texcoord);
}
ENDCG
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest Greater .01
Cull Off Lighting Off ZWrite Off
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest
ENDCG
}
}
}
//コピピペしたら、増やしていく。
Tags { "RenderType"="Opaque" }
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Blend SrcAlpha One
v.vertex.xyz += tex3Dlod(_Tex3D, float4(v.vertex.xyz,0));
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.screenPos = ComputeScreenPos(o.pos);
half4 pos = mul(UNITY_MATRIX_MVP, v.vertex);
half2 sUV = pos.xy/pos.w/2+0.5;
float3 worldPosition = mul( _Object2World, float4( v.vertex.xyz, 1.0 ) ).xyz;
float3 worldNormal = mul( _Object2World, float4( v.normal, 0.0 ) ).xyz;
//カメラから見た法線方向
half3 vNormal = mul(UNITY_MATRIX_MVP, half4(v.normal,0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment