First Commit
This commit is contained in:
95
Assets/Shaders/Blur.shader
Normal file
95
Assets/Shaders/Blur.shader
Normal file
@@ -0,0 +1,95 @@
|
||||
Shader "Outline/Blur"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
//https://github.com/mattdesl/lwjgl-basics/blob/master/test/mdesl/test/shadertut/ShaderLesson5.java
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
// Combined
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
half4 _MainTex_ST;
|
||||
|
||||
uniform float _BlurResolution;
|
||||
uniform float _BlurRadius;
|
||||
uniform float _BlurDirectionX;
|
||||
uniform float _BlurDirectionY;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
//_BlurRadius = 2.5f;
|
||||
//our original texcoord for this fragment
|
||||
fixed2 tc = UnityStereoScreenSpaceUVAdjust(i.uv, _MainTex_ST);
|
||||
|
||||
//float r = lerp(_BlurResolution.y, _BlurResolution.x, step(_BlurDirection.x, 1.0f));
|
||||
|
||||
//the amount to blur, i.e. how far off center to sample from
|
||||
//1.0 -> blur by one pixel
|
||||
//2.0 -> blur by two pixels, etc.
|
||||
float blur = _BlurRadius/_BlurResolution;
|
||||
|
||||
//the _BlurDirectionection of our blur
|
||||
//(1.0, 0.0) -> x-axis blur
|
||||
//(0.0, 1.0) -> y-axis blur
|
||||
float hstep = _BlurDirectionX;
|
||||
float vstep = _BlurDirectionY;
|
||||
|
||||
//apply blurring, using a 9-tap filter with predefined gaussian weights
|
||||
|
||||
fixed4 sum = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946;
|
||||
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x, tc.y)) * 0.2270270270;
|
||||
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541;
|
||||
sum += UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, fixed2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Shaders/Blur.shader.meta
Normal file
10
Assets/Shaders/Blur.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aeeae5fc85f4ab48a63ba7be7ec7608
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
106
Assets/Shaders/Compose.shader
Normal file
106
Assets/Shaders/Compose.shader
Normal file
@@ -0,0 +1,106 @@
|
||||
Shader "Outline/Compose"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", any) = "white" {}
|
||||
_EdgeTex ("Edge Texture", 2D) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Cull Off ZWrite Off ZTest Always
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
};
|
||||
|
||||
float2 _MainTex_TexelSize;
|
||||
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_DefaultDrawObjects);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_BlurTex);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_TempTex);
|
||||
UNITY_DECLARE_SCREENSPACE_TEXTURE(_EdgeTex);
|
||||
|
||||
uniform float EdgeValue;
|
||||
|
||||
uniform float OffsetRedX;
|
||||
uniform float OffsetGreenX;
|
||||
uniform float OffsetBlueX;
|
||||
uniform float OffsetRedY;
|
||||
uniform float OffsetGreenY;
|
||||
uniform float OffsetBlueY;
|
||||
|
||||
uniform float Brightness;
|
||||
uniform float Contrast;
|
||||
|
||||
uniform float GlobalAlpha;
|
||||
|
||||
half4 _MainTex_ST;
|
||||
half4 _EdgeTex_ST;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
UNITY_SETUP_INSTANCE_ID(v);
|
||||
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
||||
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv0 = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.uv1 = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
|
||||
#if UNITY_UV_STARTS_AT_TOP
|
||||
if (_MainTex_TexelSize.y < 0)
|
||||
o.uv1.y = 1 - o.uv1.y;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
EdgeValue = 1.0f;
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
|
||||
//
|
||||
// Sample the world RT (render so far without our outline objects)
|
||||
//
|
||||
fixed4 world = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex,
|
||||
UnityStereoScreenSpaceUVAdjust(i.uv0, _MainTex_ST));
|
||||
//
|
||||
// Sample our outline texture
|
||||
//
|
||||
fixed4 outline = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_BlurTex,
|
||||
UnityStereoScreenSpaceUVAdjust(i.uv1, _MainTex_ST));
|
||||
//
|
||||
// Sample the solid render of the game object to be outlined
|
||||
//
|
||||
fixed4 gameObject = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_DefaultDrawObjects,
|
||||
UnityStereoScreenSpaceUVAdjust(i.uv1, _MainTex_ST));
|
||||
|
||||
world.xyz = world + EdgeValue * (outline * (1.0 - gameObject.a));
|
||||
return world;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Shaders/Compose.shader.meta
Normal file
10
Assets/Shaders/Compose.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f0ea674bfa1ff042b2829daa5815e90
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
41
Assets/Shaders/DepthOnly.shader
Normal file
41
Assets/Shaders/DepthOnly.shader
Normal file
@@ -0,0 +1,41 @@
|
||||
Shader "Outline/DepthOnly"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
ColorMask 0
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
return fixed4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Shaders/DepthOnly.shader.meta
Normal file
10
Assets/Shaders/DepthOnly.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59ed4cb0e31a72c469f09fcf8614de92
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/Shaders/SolidUnlit.shader
Normal file
74
Assets/Shaders/SolidUnlit.shader
Normal file
@@ -0,0 +1,74 @@
|
||||
Shader "Outline/SolidUnlit"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType" = "TransparentCutout" }
|
||||
ZWrite Off
|
||||
ZTest LEqual
|
||||
Lighting Off
|
||||
// Set up alpha blending
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float4 projPos : TEXCOORD0;
|
||||
float2 convertedNormal : TEXCOORD1;
|
||||
};
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
|
||||
o.projPos = ComputeScreenPos(o.vertex);
|
||||
COMPUTE_EYEDEPTH(o.projPos.z);
|
||||
|
||||
//o.viewNormal = COMPUTE_VIEW_NORMAL;
|
||||
|
||||
// work out camera position to vert position
|
||||
float3 normalDir = UnityObjectToWorldNormal(v.normal);
|
||||
float3 viewDir = normalize(WorldSpaceViewDir(v.vertex));
|
||||
|
||||
float3 upDir = float3(0.0, 1.0, 0.0);
|
||||
float3 rightDir = normalize(cross(viewDir, upDir));
|
||||
upDir = cross(rightDir, viewDir);
|
||||
|
||||
o.convertedNormal.x = dot(rightDir, normalDir);
|
||||
o.convertedNormal.y = dot(upDir, normalDir);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 _Color;
|
||||
float _Alpha;
|
||||
|
||||
fixed4 frag(v2f i) : COLOR0
|
||||
{
|
||||
fixed4 output = _Color;
|
||||
|
||||
output.a = output.a * _Alpha;
|
||||
|
||||
clip((output.a - 0));
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Assets/Shaders/SolidUnlit.shader.meta
Normal file
10
Assets/Shaders/SolidUnlit.shader.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e249b16da4133f84e91d3718a2719884
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user