*
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
Shader "Unlit/Corner"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata v){
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
return o;
|
||||
}
|
||||
|
||||
static const float3x3 sobelX = float3x3(
|
||||
float3(-1, 0, 1),
|
||||
float3(-2, 0, 2),
|
||||
float3(-1, 0, 1)
|
||||
);
|
||||
|
||||
static const float3x3 sobelY = float3x3(
|
||||
float3(-1, -2, -1),
|
||||
float3(0, 0, 0),
|
||||
float3(1, 2, 1)
|
||||
);
|
||||
|
||||
float sobelFilter(sampler2D image, float2 uv, float3x3 kernel) {
|
||||
float2 textureSize = float2(512, 512);
|
||||
|
||||
float sum = 0.0f;
|
||||
for (int y = -1; y <= 1; ++y) {
|
||||
for (int x = -1; x <= 1; ++x) {
|
||||
sum += tex2D(image, uv + float2((float)x / textureSize.x, (float)y / textureSize.y)).r * kernel[y + 1][x + 1];
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float4 frag (v2f i) : SV_Target{
|
||||
float2 textureSize = float2(512,512);
|
||||
float2 texelSize = 1.0f / textureSize;
|
||||
|
||||
float Ix = tex2D(_MainTex, i.uv + float2(texelSize.x, 0.0f)).r - tex2D(_MainTex, i.uv).r;
|
||||
float Iy = tex2D(_MainTex, i.uv + float2(0.0f, texelSize.y)).r - tex2D(_MainTex, i.uv).r;
|
||||
|
||||
float2x2 jacobi;
|
||||
jacobi[0][0] = Ix * Ix;
|
||||
jacobi[0][1] = Ix * Iy;
|
||||
jacobi[1][0] = Ix * Iy;
|
||||
jacobi[1][1] = Iy * Iy;
|
||||
|
||||
float jacobian = (Ix * Ix) * (Iy * Iy) - (Ix * Iy) * (Ix * Iy);
|
||||
|
||||
//return tex2D(_MainTex, i.uv).r;
|
||||
float sX = sobelFilter(_MainTex, i.uv, sobelX);
|
||||
float sY = sobelFilter(_MainTex, i.uv, sobelY);
|
||||
|
||||
//return sX;
|
||||
return sY;
|
||||
return sX*sX + sY*sY;
|
||||
//return jacobian == 0;
|
||||
//return abs(float4(Ix, Iy, 0, 1));
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user