Last active
May 19, 2020 19:29
-
-
Save lowteq/c23ab77276a281428afea42b68ec78ae to your computer and use it in GitHub Desktop.
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 "Unlit/scaner" | |
{ | |
Properties | |
{ | |
_DepthTexture ("Depth", 2D) = "white" {} | |
_ColorTexture ("Color", 2D) = "white" {} | |
depthlength ("Depth Length",Float) = 5 | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Cull Off | |
ZWrite On | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma geometry geom | |
#pragma fragment frag | |
// make fog work | |
#pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
struct particleData{ | |
float3 pos; // Particle Position | |
float3 col; | |
}; | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _DepthTexture; | |
sampler2D _ColorTexture; | |
float3 _ParticleMul; | |
float4 _ParticleOffset; | |
float _height; | |
float depthlength; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = v.vertex; | |
o.uv = v.uv; | |
return o; | |
} | |
[maxvertexcount(3)] | |
void geom(triangle v2f i[3], inout TriangleStream<v2f> outStream) | |
{ | |
v2f o; | |
[unroll] | |
for (int j = 0; j < 3; j++) | |
{ | |
float2 uv = i[j].uv; | |
float y = tex2Dlod(_DepthTexture,float4(uv,0,0)).x; | |
// 頂点シェーダからもらった3頂点それぞれを射影変換して通常のレンダリングと同様にポリゴン位置を決める | |
v2f v = i[j]; | |
v.vertex += float4(0,0,y*depthlength,0); | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = uv; | |
outStream.Append(o); | |
} | |
outStream.RestartStrip(); | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
// sample the texture | |
fixed4 col = tex2D(_ColorTexture, i.uv); | |
fixed d = tex2D(_DepthTexture,i.uv); | |
if (d < 0.01){ | |
discard; | |
} | |
col = tex2D(_ColorTexture,i.uv); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Author
lowteq
commented
May 19, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment