Skip to content

Instantly share code, notes, and snippets.

@leegoonz
Created January 8, 2020 19:49
Show Gist options
  • Save leegoonz/c0abda3f78aec254289f2bd52dd9ef70 to your computer and use it in GitHub Desktop.
Save leegoonz/c0abda3f78aec254289f2bd52dd9ef70 to your computer and use it in GitHub Desktop.
Shader "ASE_DualMatcap"
{
Properties
{
_FrontParaboloid ("_FrontParaboloid", 2D) = "white" { }
_RearParaboloid ("_RearParaboloid", 2D) = "white" { }
_Albedo("Albedo", 2D) = "white" {}
_Float0("Float 0", Range( 0 , 2)) = 1
[HideInInspector] _texcoord( "", 2D ) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" "LightMode" = "ForwardBase" }
LOD 100
Cull Off
Pass
{
CGPROGRAM
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 texcoord : TEXCOORD0;
float3 worldNormal : TEXCOORD1;
UNITY_VERTEX_OUTPUT_STEREO
};
uniform fixed4 _Color;
uniform sampler2D _FrontParaboloid;
uniform sampler2D _RearParaboloid;
uniform sampler2D _Albedo;
uniform float4 _Albedo_ST;
uniform float _Float0;
v2f vert ( appdata v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.texcoord.xy = v.texcoord.xy;
o.texcoord.zw = v.texcoord1.xy;
// ase common template code
v.vertex.xyz += float3(0,0,0) ;
o.vertex = UnityObjectToClipPos(v.vertex);
o.worldNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal));
return o;
}
inline fixed4 texParaboloidXFliped(sampler2D front, sampler2D back, float3 refl)
{
if (refl.x > 0)
{
float2 frontUv;
frontUv.x = refl.z / (refl.x + 1);
frontUv.y = refl.y / (refl.x + 1);
frontUv = (frontUv * .5f) + 0.5f;
frontUv.x = 1 - frontUv.x;
return tex2D(front, frontUv);
}
else
{
float2 backUv;
backUv.x = refl.z / (1 - refl.x);
backUv.x *= -1;
backUv.y = refl.y / (1 - refl.x);
backUv = (backUv * .5f) + 0.5f;
backUv.x = backUv.x;
return tex2D(back, backUv);
}
}
fixed4 frag (v2f i ) : SV_Target
{
fixed4 parabolicOut;
// ase common template code
float2 uv_Albedo = i.texcoord.xy * _Albedo_ST.xy + _Albedo_ST.zw;
parabolicOut = ( float4(1,1,1,0) * ( tex2D( _Albedo, uv_Albedo ) * _Float0 ) );
//return myColorVar;
return parabolicOut * texParaboloidXFliped(_FrontParaboloid, _RearParaboloid, i.worldNormal);;
}
ENDCG
}
}
CustomEditor "ASEMaterialInspector"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment